Pavel Machek wrote: > On Mon 2009-09-28 18:04:10, Miklos Szeredi wrote: > > a) the current permission model under /proc/PID/fd has a security > > hole (which Jamie is worried about) > > I believe its bugtraq time. Being able to reopen file with additional > permissions looks like a security problem... > > Jamie, do you have some test script? And do you want your 15 minutes > of bugtraq fame? ;-). $ mkdir secret $ exec 3>> secret/appendonly.txt $ chmod 000 secret # This is not changed during do_stuff jamie@amile:~/test$ echo START OF LOG 1>&3 $ do_stuff 1>&3 cat: secret/appendonly.txt: Permission denied # A good sign $ chmod 755 secret $ cat secret/appendonly.txt # Let's see our log nothing to see here # What's that doing there??! You can re-open a deleted file with increased permisssions. That's probably more subversive: $ exec >>appendonlydeleted.txt $ exec 4<appendonlydeleted.txt # I'll read it later. $ echo START OF LOG $ ./do_stuff $ cat 0<&4 >/dev/tty nothing to see here # How did they do that?! How'd it happen? do_stuff: #!/bin/sh echo some text getting logged... echo more text... echo no wait, let\'s subvert the append flag! echo nothing to see here >/proc/self/fd/1 If /proc/self/fd/1 were a _real_ symbolic link, that wouldn't work. The reopen does check the inode permission, but it does not require you have any reachable path to the file. Someone _might_ use that as a traditional unix security mechanism, but if so it's probably quite rare. If converting append-only to writable doesn't sound too bad, you can convert read-only to writable and write-only to readable. Gaining write access to a deleted file which you only received a read-only descriptor for sounds dodgy to me: $ echo secret5948043853048 >secret_readonly_password.txt $ exec 3<secret_readonly_password.txt $ rm secret_readonly_password.txt # Now I'm sure nobody can change it! $ echo all your base ha ha >/proc/self/fd/3 $ cat 0<&3 all your base ha ha # Oh dear, my assumption was broken. Did you really think you had to "chmod 444" before deleting the file? -- Jamie -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html