Root Can't Delete Folder It Owns

3

0

Platform: CentOS 6.2 Shell: tcsh


EDIT
Brian Swift has pointed out a workable solution. He points out that if the home directory is served via NFS, root on a client may not have the same permissions. Logging in as root on the NFS server, the folder delete without complaint. That still leaves me with some unanswered questions, though.

Background:

  1. I created this file as root appr. 2 years ago on the same client I tried the below commands on.
  2. All other root folders created on that same client from that same time period (mid-2010) deleted without complaint.

Questions:

  1. What makes that folder a special snowflake versus the other client root created folders in my home dir?
  2. Is there any way to check for deviant NFS permissions?

Again I owe Brian a big thanks for getting to the bottom of this, he is truly a super user!


ORIGINAL Question:

I'm lost as to what in the world is going on here... root owns this locked directory (from a manual gcc-4.4.3 install) in my home directory. I change to root (su root, also tried su) and try to delete it and get permissions errors. I try to change the permissions, the operation is denied. I try to lsattr/chattr it and get ioctl errors in the terminal.


To be clear, I'm doing general cleanup on my home directory, and I've been able to remove any other files I've wanted just fine with some help from root to hack through permissions barriers, etc. It's just this one folder that's giving grief.

Here's what I've tried....

COMMAND:

whoami


OUTPUT

root

COMMAND:

 rm -rf gcc-4.4.3_objdir


OUTPUT

> gcc-4.4.3_objdir rm: cannot remove
    > `gcc-4.4.3_objdir/config.status': Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/x86_64-unknown-linux-gnu': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/intl/config.status': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/intl/config.intl': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/intl/config.cache':
    > Permission denied rm: cannot remove `gcc-4.4.3_objdir/intl/Makefile':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/intl/config.log': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/intl/config.h': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/libdecnumber/decNumber.o': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/libdecnumber/gstdint.h':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/libdecnumber/config.status': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/libdecnumber/decimal128.o': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/libdecnumber/decimal32.o':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/libdecnumber/decContext.o': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/libdecnumber/bid2dpd_dpd2bid.o':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/libdecnumber/host-ieee64.o': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/libdecnumber/decimal64.o': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/libdecnumber/config.cache':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/libdecnumber/host-ieee32.o': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/libdecnumber/host-ieee128.o':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/libdecnumber/Makefile': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/libdecnumber/libdecnumber.a': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/libdecnumber/config.log':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/libdecnumber/stamp-h1': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/libdecnumber/config.h': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/gcc/build/errors.o': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/gcc/cstamp-h': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/gcc/objc': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/gcc/config.status': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/gcc/gthr-default.h': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/gcc/options.h': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/gcc/gccbug': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/gcc/ada/Makefile':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/ada/gcc-interface/Makefile': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/gcc/cs-bconfig.h': Permission
    > denied rm: cannot remove `gcc-4.4.3_objdir/gcc/tmp-modes.h':
    > Permission denied rm: cannot remove `gcc-4.4.3_objdir/gcc/java':
    > Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/auto-host.h': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/gcc/doc': Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/bconfig.h': Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/.gdbinit': Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/tm.h': Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/objcp': Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/as': Permission denied rm: cannot remove
    > `gcc-4.4.3_objdir/gcc/config.cache': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/gcc/optionlist': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/gcc/configargs.h': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/gcc/s-options': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/gcc/Make-hooks': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/gcc/s-options-h': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/gcc/Makefile': Permission denied
    > rm: cannot remove `gcc-4.4.3_objdir/gcc/cp': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/gcc/collect-ld': Permission denied rm:
    > cannot remove `gcc-4.4.3_objdir/gcc/nm': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/gcc/config.log': Permission denied rm: cannot
    > remove `gcc-4.4.3_objdir/gcc/config.h': Permission denied rm: cannot
    ...

COMMAND:

ls -laFd gcc-4.4.3_objdir

OUTPUT

drwxr-xr-x. 10 root root 4096 Mar 19  2010 gcc-4.4.3_objdir/

COMMAND:

id

OUTPUT

uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:###########

COMMAND:

chown -R root:root gcc-4.4.3_objdir

OUTPUT

chown: changing ownership of `gcc-4.4.3_objdir/gcc/build': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/cstamp-h': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/objc': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/config.status': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/gthr-default.h': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/options.h': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/gccbug': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/ada/Makefile': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/ada/gcc-interface/Makefile': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/gcc/ada/gcc-interface': Operation not permitted
...
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/libiberty': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/fixopts.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/config.status': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/fixinc.sh': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/fixincl.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/mkheaders.almost': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/mkheaders': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/fixincl': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/server.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/fixlib.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/fixtests.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/procopen.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/full-stamp': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/Makefile': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/config.log': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/stamp-h': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/config.h': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes/fixfixes.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/fixincludes': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu/config.cache': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/stage_final': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/stage_current': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/Makefile': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/config.status': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/line-map.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/lex.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/identifiers.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/symtab.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/mkdeps.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/makedepend': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/pch.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/localedir.h': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/directives.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/config.cache': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/makedepend.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/localedir.hs': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/traditional.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/init.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/charset.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/Makefile': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/libcpp.a': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/directives-only.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/errors.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/makedepend.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/pch.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/charset.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/line-map.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/mkdeps.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/symtab.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/files.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/directives-only.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/directives.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/expr.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/init.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/identifiers.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/lex.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/traditional.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps/macro.Po': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/.deps': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/macro.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/config.log': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/expr.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/stamp-h1': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/files.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/config.h': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp/errors.o': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/libcpp': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/stage_last': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir/config.log': Operation not permitted
chown: changing ownership of `gcc-4.4.3_objdir': Operation not permitted

COMMAND:

stat gcc-4.4.3_objdir

OUTPUT

  File: `gcc-4.4.3_objdir'
  Size: 4096        Blocks: 8          IO Block: 8192   directory
Device: 1ch/28d Inode: 36835590    Links: 10
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-04-24 04:04:17.251456720 -0400
Modify: 2010-03-19 18:23:51.000000000 -0400
Change: 2012-04-20 12:02:38.334456000 -0400

COMMAND:

chattr -i gcc-4.4.3_objdir

OUTPUT

chattr: Inappropriate ioctl for device while reading flags on gcc-4.4.3_objdir

COMMAND:

lsattr gcc-4.4.3_objdir

OUTPUT

lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/config.status
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/x86_64-unknown-linux-gnu
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/intl
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/libdecnumber
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/gcc
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/serdep.tmp
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/libiberty
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/zlib
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/build-x86_64-unknown-linux-gnu
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/stage_final
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/stage_current
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/Makefile
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/libcpp
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/stage_last
lsattr: Inappropriate ioctl for device While reading flags on gcc-4.4.3_objdir/config.log

Jason R. Mick

Posted 2012-04-24T18:57:49.180

Reputation: 245

Just a random guess: this is a readonly filesystem because of some leaf mount or so. Check the output of "mount". – Gregory MOUSSAT – 2012-04-24T19:49:03.907

@GregoryMOUSSAT Results of mount gcc-4.4.3_objdir: mount: can't find gcc-4.4.3_objdir in /etc/fstab or /etc/mtab; Results of mount /dev/mapper/vg_<MACH_NAME>-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0") /dev/sda1 on /boot type ext4 (rw) /dev/mapper/vg_<MACH_NAME>-lv_home on /home type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) <CENSORED HOME> – Jason R. Mick – 2012-04-24T21:22:41.020

@GregoryMOUSSAT The dir does not appear to be in the list of mounted directories, and attempting to mount it (not sure why you would do that, but I wasn't sure if you meant to do that or just get the mount listing) does not work either. – Jason R. Mick – 2012-04-24T21:28:22.280

Might make sense if directory was coming from a NFS server or some other form of NAS. Depending on server config, root on client might not be able to delete files, and server might not support file attributes. – Brian Swift – 2012-04-25T07:02:55.600

@BrianSwift Interesting hypothesis... Home is on an NFS server... I'm gonna try to delete it on there. Typically though, root can delete anything in my home directory on a client, so this is an odd exception. Any idea why there'd be a special exception for a specific folder on a client and/or how to check that? – Jason R. Mick – 2012-04-25T19:19:25.750

HA what do you know, that worked! Can you make that an answer? I'll upvote you and check you. Also, if you have any insight into how one lone folder can be disallowed for deletion on clients, vs. every other folder, that would be much appreciated. To clear up one possibility I thought up, the folder was NOT created on the NFS server machine. It was created by root on the same (client) machine I'm currently on. (Anything else created by root on my NFS client machine has proved perfectly delete-able by root.) – Jason R. Mick – 2012-04-25T19:25:25.133

Answers

3

Might make sense if directory was coming from a NFS server or some other form of NAS. Depending on server config, root on client might not be able to delete files, and server might not support file attributes.

As to why only this directory had problems, I'll just speculate that the NFS configuration (or NFS client or server software) changed in some relevant manner sometime after the directory was created. I would have been curious if ls -l showed on the server ownership was root, your username, or nobody.

One additional speculation, if this directory was created by un-taring a gcc distribution as root, maybe the directory picked up some funky ownership/permissions from the tar archive, rather than directories and files you created directly.

Brian Swift

Posted 2012-04-24T18:57:49.180

Reputation: 486

Thanks again! (the ownership on the server was root, the same as on the client... fwiw) – Jason R. Mick – 2012-04-26T14:46:06.610

0

Have you tried removing the directory with your own account?

When deleting a file or directory you are in fact modifying the parent directory fo that file (everything is a file in linux even a directory). And you have the permissions to modify your home directory.

Another thing to check is SELinux, run /usr/sbin/getenforce, if it says "Enforcing" you can either try to disable SELinux temporarily /usr/sbin/setenforce 0 or check the SElinux settings ls -lZ gcc-4.4.3_objdir and use /sbin/restorecon -R /home/<username>/ to correct them.

Bram

Posted 2012-04-24T18:57:49.180

Reputation: 582

Interesting theory... sadly switching to permissive via echo 0 >/selinux/enforce (I verified permissive was in effect.) did nothing ... still got the same Permission denied errors. – Jason R. Mick – 2012-04-25T19:22:14.157

0

This should delete that file or folder:

chmod -Rf 777 your_folder_or_file_name

rm -rf your_folder_or_file_name

AlexB

Posted 2012-04-24T18:57:49.180

Reputation: 1