/proc and directory permissions
Posted Oct 29, 2009 4:59 UTC (Thu) by
jimparis (subscriber, #38647)
In reply to:
/proc and directory permissions by jimparis
Parent article:
/proc and directory permissions
Here is an example that shows the non-obvious behavior:
$ sudo su
# mkdir -m 0700 /dir
# echo "safe" > /dir/file.txt
# chmod 0666 /dir/file.txt
# ls -al /dir
total 12
drwx------ 2 root root 4096 2009-10-29 00:28 .
drwxr-xr-x 27 root root 4096 2009-10-29 00:28 ..
-rw-rw-rw- 1 root root 7 2009-10-29 00:43 file.txt
# cat file.txt
safe
Now user "nobody" cannot read or write this file:
# su nobody -c 'cat /dir/file.txt'
sh: /dir/file.txt: Permission denied
# su nobody -c 'echo "hacked" > /dir/file.txt'
sh: /dir/file.txt: Permission denied
If we provide an open read-only file descriptor (as stdin, fd 0), they can read it:
# su nobody -c 'cat <&0' < /dir/file.txt
safe
But they still can't write to this descriptor:
# su nobody -c 'echo "hacked" >&0' < /dir/file.txt
sh: line 0: echo: write error: Bad file descriptor
Unless we re-open the file using the magic link in /proc:
# su nobody -c 'echo "hacked" >/proc/self/fd/0' < /dir/file.txt
# cat /dir/file.txt
hacked
(
Log in to post comments)