Paul Eggert wrote: > > If you compile and run the attached > > program on a file that you don't own (e.g., './a.out /'), does it > > incorrectly issue "Permission denied" instead of "Operation not > > permitted" diagnostics?
and I replied: > In this case, the diagnostic is "Operation not permitted" (from EPERM): > > $ ./a.out / > lchown: Operation not permitted > fchownat: Operation not permitted > chown: Operation not permitted > fchown: Operation not permitted Oops, I mistakenly compiled and ran the wrong test program. Here are the results for the test program you meant: $ ./a.out / lchmod: Operation not permitted fchmodat: Operation not permitted chmod: Operation not permitted fchmod: Operation not permitted $ strace ./a.out / ... chmod("/proc/self/fd/3", 0755) = -1 EPERM (Operation not permitted) close(3) = 0 dup(2) = 3 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) getrandom("\xd5\xae\x46\x10\x0d\x5a\x98\x9a", 8, GRND_NONBLOCK) = 8 brk(NULL) = 0x5575761c2000 brk(0x5575761e3000) = 0x5575761e3000 newfstatat(3, "", {st_mode=S_IFCHR|0600, st_rdev=makedev(0x88, 0xd), ...}, AT_EMPTY_PATH) = 0 write(3, "lchmod: Operation not permitted\n", 32lchmod: Operation not permitted ) = 32 close(3) = 0 openat(AT_FDCWD, "/", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 3 newfstatat(3, "", {st_mode=S_IFDIR|0755, st_size=4096, ...}, AT_EMPTY_PATH) = 0 chmod("/proc/self/fd/3", 0755) = -1 EPERM (Operation not permitted) close(3) = 0 dup(2) = 3 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) newfstatat(3, "", {st_mode=S_IFCHR|0600, st_rdev=makedev(0x88, 0xd), ...}, AT_EMPTY_PATH) = 0 write(3, "fchmodat: Operation not permitte"..., 34fchmodat: Operation not permitted ) = 34 close(3) = 0 chmod("/", 0755) = -1 EPERM (Operation not permitted) dup(2) = 3 fcntl(3, F_GETFL) = 0x2 (flags O_RDWR) newfstatat(3, "", {st_mode=S_IFCHR|0600, st_rdev=makedev(0x88, 0xd), ...}, AT_EMPTY_PATH) = 0 write(3, "chmod: Operation not permitted\n", 31chmod: Operation not permitted ) = 31 close(3) = 0 openat(AT_FDCWD, "/", O_RDONLY|O_NOFOLLOW) = 3 fchmod(3, 0755) = -1 EPERM (Operation not permitted) dup(2) = 4 fcntl(4, F_GETFL) = 0x2 (flags O_RDWR) newfstatat(4, "", {st_mode=S_IFCHR|0600, st_rdev=makedev(0x88, 0xd), ...}, AT_EMPTY_PATH) = 0 write(4, "fchmod: Operation not permitted\n", 32fchmod: Operation not permitted ) = 32 close(4) = 0 exit_group(1) = ? +++ exited with 1 +++