Re: Thinking outside the box on file systems

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Kyle Moffett
Date: Wednesday, August 15, 2007 - 9:44 pm

Mmm, slow-as-dirt hotel wireless.  What fun...

On Aug 15, 2007, at 18:14:44, Phillip Susi wrote:

Let me repeat myself here:  Algorithmically you fundamentally CANNOT  
implement inheritance-based ACLs without one of the following  
(although if you have some other algorithm in mind, I'm listening):
   (A) Some kind of recursive operation *every* time you change an  
inheritable permission
   (B) A unified "starting point" from which you begin *every* access- 
control lookup (or one "starting point" per useful semantic grouping,  
like a namespace).

The "(A)" is presently done in userspace and that's what you want to  
avoid.  As to (B), I will attempt to prove below that you cannot  
implement "(B)" without breaking existing assumptions and restricting  
a very nice VFS model.


What ACL would "task->cwd" use?

Options:
(1.a) Use the one calculated during the original chdir() call.
(1.b) Navigate "up" task->cwd building an ACL backwards.
(1.c) $CAN_YOU_THINK_OF_SOMETHING_ELSE_HERE

Unsolvable problems with each option:

(1.a.I)
You just broke all sorts of chrooted daemons.  When I start bind in  
its chroot jail, it does the following:
   chdir("/private/bind9");
   chroot(".");
   setgid(...);
   setuid(...);
The "/private" directory is readable only by root, since root is the  
only one who will be navigating you into these chroots for any  
reason.  You only switch UID/GID after the chroot() call, at which  
point you are inside of a sub-context and your cwd is fully  
accessible.  If you stick an inheritable ACL on "/private", then the  
"cwd" ACL will not allow access by anybody but root and my bind won't  
be able to read any config files.

You also break relative paths and directory-moving.  Say a process  
does chdir("/foo/bar").  Now the ACL data in "cwd" is appropriate  
for /foo/bar.  If you later chdir("../quux"), how do you unapply the  
changes made when you switched into that directory?  For inheritable  
ACLs, you can't "unapply" such an ACL state change unless you save  
state for all the parent directories, except...  What happens when  
you are in "/foo/bar" and another process does "mv /foo/bar /foobar/ 
quux"?  Suddenly any "cwd" ACL data you have is completely invalid  
and you have to rebuild your ACLs from scratch.  Moreover, if the  
directory you are in was moved to a portion of the filesystem not  
accessible from your current namespace then how do you deal with it?

For example:
NS1 has the / root dir of /dev/sdb1 mounted on /mnt
NS2 has the /bar subdir of /dev/sdb1 mounted on /mnt

Your process is in NS2 and does chdir("/mnt/quux").  A user in NS1  
does: "mv /mnt/bar/quux /mnt/quux".  Now your "cwd" is in a directory  
on a filesystem you have mounted, but it does not correspond *AT ALL*  
to any path available from your namespace.

Another example:
Your process has done dirfd=open("/media/cdrom/somestuff") when the  
admin does "umount -l /media/cdrom".  You still have the CD-ROM open  
and accessible but IT HAS NO PATH.  It isn't even mounted in *any*  
namespace, it's just kind of dangling waiting for its last users to  
go away.  You can still do fchdir(dirfd), openat(dirfd, "foo/ 
bar", ...), open("./foo"), etc.

In Linux the ONLY distinction between "relative" and "absolute" paths  
is that the "absolute" path begins with a magic slash which implies  
that you start at the hidden "root" fd the kernel manages.

More detail on problems with the "building the ACL from scratch" part:

No, this is correct because in the root directory "/", the ".." entry  
is just another link to the root directory.  So the absolute path  
"/../../../../../.." is just a fancy name for the root directory.   
The above jail-escape-as-root exploit is possible because it is  
impossible to determine whether a directory is or is not a subentry  
of another directory without an exhaustive search.  So when your  
"cwd" points to a path outside of the chroot, the one special case in  
the code for the "root" directory does not ever match and you can  
"chdir" all the way up to the real root.  You can even do an fstat()  
after every iteration to figure out whether you're there or not!

And yes, this has been exploited before, although not often as chroot 
()-ed uid=0 daemons aren't all that common.

So, pray tell, when this code runs and you do the "chroot" call, what  
ACL do you think should get stuck on "cwd"?  It doesn't reference  
anything available relative to the chroot.



With this you just got into the big-ugly-nasty-recursive-behavior  
again.  Say I untar 20 kernel source trees and then have my program  
open all 1000 available FDs to various directories in the kernel  
source tree.  Now I run 20 copies of this program, one for each tree,  
still well within my ulimits even on a conservative box.  Now run "mv  
dir_full_of_kernel_sources some/new/dir".  The only thing you can do  
to find all of the FDs is to iterate down the entire subdirectory  
tree looking for open files and updating their contexts one-by-one.   
Except you have 20,000 directory FDs to update.  Ouch.

To sum up, when doing access control the only values you can safely  
and efficiently get at are:
(A)  The dentry/inode
(B)  The superblock
(C)  *Maybe* the vfsmount if those patches get accepted

Any access control model which tries to poke other values is just  
going to have a shitload of corner cases where it just falls over.

Cheers,
Kyle Moffett

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Thinking outside the box on file systems, Marc Perkel, (Tue Aug 14, 3:45 pm)
Re: Thinking outside the box on file systems, Michael Tharp, (Wed Aug 15, 6:02 am)
Re: Thinking outside the box on file systems, Lennart Sorensen, (Wed Aug 15, 6:30 am)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 6:53 am)
Re: Thinking outside the box on file systems, Michael Tharp, (Wed Aug 15, 8:14 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 9:02 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 9:36 am)
Re: Thinking outside the box on file systems, Valdis.Kletnieks, (Wed Aug 15, 9:57 am)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 9:58 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:02 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:09 am)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 10:17 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:19 am)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 10:22 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:30 am)
Re: Thinking outside the box on file systems, Michael Tharp, (Wed Aug 15, 10:30 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:34 am)
Re: Thinking outside the box on file systems, Phillip Susi, (Wed Aug 15, 10:34 am)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 10:37 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:51 am)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 10:53 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:54 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 10:59 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 11:05 am)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 11:14 am)
Re: Thinking outside the box on file systems, Craig Ruff, (Wed Aug 15, 11:22 am)
Re: Thinking outside the box on file systems, Lennart Sorensen, (Wed Aug 15, 12:20 pm)
Re: Thinking outside the box on file systems, Lennart Sorensen, (Wed Aug 15, 12:26 pm)
Re: Thinking outside the box on file systems, Yakov Lerner, (Wed Aug 15, 1:02 pm)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 1:11 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 1:20 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 1:35 pm)
Re: Thinking outside the box on file systems, Phillip Susi, (Wed Aug 15, 1:38 pm)
Re: Thinking outside the box on file systems, Phillip Susi, (Wed Aug 15, 1:43 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 1:44 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 1:50 pm)
Re: Thinking outside the box on file systems, Lennart Sorensen, (Wed Aug 15, 2:04 pm)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 2:17 pm)
Re: Thinking outside the box on file systems, Valdis.Kletnieks, (Wed Aug 15, 2:20 pm)
Re: Thinking outside the box on file systems, Phillip Susi, (Wed Aug 15, 3:14 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 3:40 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Wed Aug 15, 3:48 pm)
Re: Thinking outside the box on file systems, Valdis.Kletnieks, (Wed Aug 15, 8:42 pm)
Re: Thinking outside the box on file systems, Kyle Moffett, (Wed Aug 15, 9:44 pm)
Re: Thinking outside the box on file systems, Helge Hafting, (Thu Aug 16, 4:27 am)
Re: Thinking outside the box on file systems, Helge Hafting, (Thu Aug 16, 4:42 am)
Re: Thinking outside the box on file systems, linux-os (Dick Johnson), (Thu Aug 16, 5:09 am)
Re: Thinking outside the box on file systems, Phillip Susi, (Thu Aug 16, 8:09 am)
Re: Thinking outside the box on file systems, Valdis.Kletnieks, (Thu Aug 16, 8:29 am)
Re: Thinking outside the box on file systems, Phillip Susi, (Thu Aug 16, 10:28 am)
Re: Thinking outside the box on file systems, Valdis.Kletnieks, (Thu Aug 16, 10:31 am)
Re: Thinking outside the box on file systems, Phillip Susi, (Thu Aug 16, 3:03 pm)
Re: Thinking outside the box on file systems, H. Peter Anvin, (Thu Aug 16, 4:12 pm)
Re: Thinking outside the box on file systems, Kyle Moffett, (Thu Aug 16, 4:17 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Thu Aug 16, 9:24 pm)
Re: Thinking outside the box on file systems, Valdis.Kletnieks, (Thu Aug 16, 9:52 pm)
Re: Thinking outside the box on file systems, Phillip Susi, (Fri Aug 17, 8:19 am)
Re: Thinking outside the box on file systems, Valdis.Kletnieks, (Fri Aug 17, 8:39 am)
Re: Thinking outside the box on file systems, Phillip Susi, (Fri Aug 17, 12:01 pm)
Re: Thinking outside the box on file systems, Kyle Moffett, (Fri Aug 17, 10:48 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Sat Aug 18, 9:45 am)
Re: Thinking outside the box on file systems, Al Viro, (Sat Aug 18, 11:19 am)
Re: Thinking outside the box on file systems, david, (Sat Aug 18, 7:03 pm)
Re: Thinking outside the box on file systems, Al Viro, (Sat Aug 18, 7:57 pm)
Re: Thinking outside the box on file systems, Marc Perkel, (Sat Aug 18, 9:07 pm)
Re: Thinking outside the box on file systems, Brennan Ashton, (Mon Aug 20, 12:47 am)
Re: Thinking outside the box on file systems, Marc Perkel, (Mon Aug 20, 4:18 am)
Re: Thinking outside the box on file systems, linux-os (Dick Johnson), (Mon Aug 20, 6:32 am)
Re: Thinking outside the box on file systems, Phillip Susi, (Mon Aug 20, 7:24 am)
Re: Thinking outside the box on file systems, Phillip Susi, (Mon Aug 20, 7:29 am)
Re: Thinking outside the box on file systems, Lennart Sorensen, (Mon Aug 20, 8:13 am)
Re: Thinking outside the box on file systems, Lennart Sorensen, (Mon Aug 20, 8:25 am)
Re: Thinking outside the box on file systems, Helge Hafting, (Mon Aug 20, 8:26 am)
Re: [OT] Re: Thinking outside the box on file systems, Xavier Bestel, (Mon Aug 20, 9:20 am)
[OT] Re: Thinking outside the box on file systems, Randy Dunlap, (Mon Aug 20, 9:21 am)
Re: Thinking outside the box on file systems, Oleg Verych, (Sat Sep 1, 4:20 pm)