* Re: changing permission()/vfs_permission... to work on dentry @ 2003-05-29 0:55 viro 2003-05-29 4:20 ` Shaya Potter 0 siblings, 1 reply; 19+ messages in thread From: viro @ 2003-05-29 0:55 UTC (permalink / raw) To: linux-fsdevel On Wed, May 28, 2003 at 08:29:13PM -0400, Shaya Potter wrote: > > Define "real". There can be a lot of them and none are more real than > > other - same situation as with dentries, actually (all links have the > > same status; there is no "primary" one). > > well real depends on what you want. Take for instance the example I > gave w/ the context, the context can contain a vfsmount, which you then > use. touch /tmp/zero && mount --bind /dev/zero /tmp/zero After that we have a vfsmount mounted on /tmp/zero and pointing to superblock of root filesystem and dentry of dev/zero from it. Both /tmp/zero and /dev/zero will resolve to the same inode (and same dentry, for that matter). vfsmounts are different and both are obviously visible to your process. Which one is "real"? What's more, I can e.g. mount ramfs on /mnt, then bind it on /tmp/foo and /tmp/bar and umount /mnt. After that we have the same tree mounted twice and original vfsmount already gone. Which one is real - one for /tmp/foo or one for /tmp/bar? > > You'll need to propagate pointers to vfsmounts and it won't be pretty - > > e.g. hpfs_unlink() calls permission() and passing vfsmount to ->unlink() > > is just plain *wrong*. > > one doesn't have to. permission() figures out calling process > (current->uid), figures out calling processes context. See above. > yes. The issue we are trying to solve (much like SubDomain > http://www.immunix.org/subdomain.html) is that you have a single fs, but > not every application needs access to that entire namespace, but from an > administrative point of view, its easier to deal w/ a single namespace. > For instance, sendmail doesn't need /bin/sh, it be fairly hard to > administrate a sendmail box that didn't have it though. If there's no > /bin/sh in the processes "namespace" (used loosely, as in mode 000 to it So give it a _REAL_ namespace. And bind /dev/null over /bin/sh in it. And revoke the capability to call mount(2) and umount(2). End of story. > and even uid 0 processes) the ability to get a root shell is limited. And why would I need a /bin/sh binary if I'd already acquired control over a process that runs with UID 0? Anyway, judging by the description on immunix.org, it looks fairly useless these days. We can trivially do the same without any kernel extensions: | * A SubDomain is easier to construct than a chroot environment. | Instead of copying everything required for the program to run into | the chroot jail, SubDomain only requires that the files be | specified in the /etc/subdomain entry. Yes, and...? clone() with CLONE_NEWNS, bind whatever you want wherever you feel like and you are done. | * SubDomain can share files with the rest of the system. Files in a | chroot jail are effectively isolated from the rest of the system. | They should not be hard- or sym-linked to files outside the chroot | jail, because they may provide an escape route. In contrast, | SubDomain allows flexible sharing with the rest of the system; | each file accessed also specifies the access modes (read, write, | and execute) that may be used. <shrug> aside of the last bit, everything still applies. Per-mountpoint read_only is wort doing (and would cover the rest), but it can get tricky. Basically, you need IS_RDONLY() taking vfsmount and looking both into superblock and vfsmount flags. Then the same game with propagating new argument to all callers. | * SubDomain descriptions can be distributed. To distribute a | program along with its SubDomain jail, one need only package the | SubDomain specification along with the program. In contrast, | distributing a chroot jail is problematic; the files to be placed | in the chroot jail must actually be included in the package, and | are not consistent with the files on the system where they are | installed. In other words, SubDomain distributes a jail by | reference, while chroot distributes a jail by value. Ditto for namespaces. Comparison with FPOSIX crapabilities also applies, obviously. ----- End forwarded message ----- ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-29 0:55 changing permission()/vfs_permission... to work on dentry viro @ 2003-05-29 4:20 ` Shaya Potter 2003-05-29 4:38 ` Chris Wright 2003-05-29 8:21 ` [long] per-mountpoint readonly viro 0 siblings, 2 replies; 19+ messages in thread From: Shaya Potter @ 2003-05-29 4:20 UTC (permalink / raw) To: viro; +Cc: linux-fsdevel On Wed, 2003-05-28 at 20:55, viro@parcelfarce.linux.theplanet.co.uk wrote: > So give it a _REAL_ namespace. And bind /dev/null over /bin/sh in it. > And revoke the capability to call mount(2) and umount(2). End of story. The issue w/ the fs namespaces the kernel supports (at least AFAI understand them) is that you can't change the underlying permission model. so for example, an "apache namespace" you might want it to only have read only access to everything besides a few files in /var/log. Can one do that w/ namespaces? ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-29 4:20 ` Shaya Potter @ 2003-05-29 4:38 ` Chris Wright 2003-05-29 8:27 ` viro 2003-05-29 8:21 ` [long] per-mountpoint readonly viro 1 sibling, 1 reply; 19+ messages in thread From: Chris Wright @ 2003-05-29 4:38 UTC (permalink / raw) To: Shaya Potter; +Cc: viro, linux-fsdevel * Shaya Potter (spotter@cs.columbia.edu) wrote: > On Wed, 2003-05-28 at 20:55, viro@parcelfarce.linux.theplanet.co.uk > wrote: > > So give it a _REAL_ namespace. And bind /dev/null over /bin/sh in it. > > And revoke the capability to call mount(2) and umount(2). End of story. > > The issue w/ the fs namespaces the kernel supports (at least AFAI > understand them) is that you can't change the underlying permission > model. yes, you are still stuck with inode mode bits and DAC. you can improve this with some MAC element, like using LSM, but this will not override the existing DAC decision, only further restrict it. and you need to either label the inode with an extended attribute or try and deal with pathnames as you've already mentioned. > so for example, an "apache namespace" you might want it to only have > read only access to everything besides a few files in /var/log. Can one > do that w/ namespaces? true. per-mountpoint read-only would allow you to create a namespace to do this. however, this gets back to changing permission() to taking vfsmount (or likely just nameidata) so that the IS_RDONLY() check could see mountpoint specific flags as well as the super_block flags. as i'm sure you've found, this changes a lot of code ;-) cheers, -chris -- Linux Security Modules http://lsm.immunix.org http://lsm.bkbits.net ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-29 4:38 ` Chris Wright @ 2003-05-29 8:27 ` viro 0 siblings, 0 replies; 19+ messages in thread From: viro @ 2003-05-29 8:27 UTC (permalink / raw) To: Chris Wright; +Cc: Shaya Potter, linux-fsdevel On Wed, May 28, 2003 at 09:38:09PM -0700, Chris Wright wrote: > true. per-mountpoint read-only would allow you to create a namespace > to do this. however, this gets back to changing permission() to taking > vfsmount (or likely just nameidata) so that the IS_RDONLY() check could > see mountpoint specific flags as well as the super_block flags. as i'm > sure you've found, this changes a lot of code ;-) It would, if you had to pass vfsmount into the thing. The Right Way(tm) would be to move that check out to the places where we still have vfsmount instead. And that leads to interesting things around remount semantics - see another posting for details. ^ permalink raw reply [flat|nested] 19+ messages in thread
* [long] per-mountpoint readonly 2003-05-29 4:20 ` Shaya Potter 2003-05-29 4:38 ` Chris Wright @ 2003-05-29 8:21 ` viro 2003-05-29 9:02 ` Trond Myklebust ` (2 more replies) 1 sibling, 3 replies; 19+ messages in thread From: viro @ 2003-05-29 8:21 UTC (permalink / raw) To: Shaya Potter; +Cc: linux-fsdevel On Thu, May 29, 2003 at 12:20:23AM -0400, Shaya Potter wrote: > On Wed, 2003-05-28 at 20:55, viro@parcelfarce.linux.theplanet.co.uk > wrote: > > So give it a _REAL_ namespace. And bind /dev/null over /bin/sh in it. > > And revoke the capability to call mount(2) and umount(2). End of story. > > The issue w/ the fs namespaces the kernel supports (at least AFAI > understand them) is that you can't change the underlying permission > model. > > so for example, an "apache namespace" you might want it to only have > read only access to everything besides a few files in /var/log. Can one > do that w/ namespaces? Now, _that_ would be a good thing to implement. To do it the right way we need to make readonly status per-mountpoint. Note that we already have that for e.g. nosuid and friends. If we get that done for readonly you can * in your namespace remount everything readonly * mount --recbind /var/log /var/log mount -o remount,rw /var/log and enjoy. The first question is obviously "could it be done at all?" Situation with IS_RDONLY() is interesting. First of all, there are uses of that beast in ->permission() instances. We definitely can (and should) take them upstream. No matter how hard somebody might wish to allow write access to e.g. regular file, if fs is readonly, it's readonly. Period. No ACLs can override it. IOW, that check (IS_RDONLY and (regular|directory|symlink) ==> EROFS) should be moved into fs/namei.c::permission(). Ditto for checks in xattr methods - they also go upstream. ioctls (ext2, ext3, reiserfs) have struct file * and thus are not a problem. fs/open.c callers also have struct file * or struct nameidata. Not a problem. fat_truncate() - actually, both checks there are bogus; callers do check for that stuff. Should be removed. ncpfs uses should be replaced with update_atime() (and that will be a huge can of worms). We have struct file * in them, anyway. ntfs uses. These are actually about the state of filesystem itself - they attempt to fill the missing permission bits. arch/sparc64/solaris/fs.c: there we have vfsmount. fs/namei.c::may_open(). After we make sure that permission() _always_ honors IS_RDONLY() (i.e. move the checks into beginning of the thing), that particular check is not needed anymore. vfs_permission() - check moves to permission(). NB: we need to verify that it's only called by permission() and instances of ->permission(). nfsd_permission() - there we have the export, ergo the vfsmount. presto_settime() - the check is bogus, we only call it from ->create(), ->unlink(), etc. and the upper layer logics takes care of these checks. presto_do_setattr() - fsck knows, ask Peter. I suspect that callers should do the check, if they are not doing it already. ext3_change_inode_journal_flag() - called only from ioctl. And that leaves us with two big ones. Namely, permission() and update_atime(). The above will take quite a few accurate steps, but it's doable and would make sense regardless of the following. And yes, there's a lot of work on accurate verification of correctness that I'd skipped - it has to be done and there might be nasty surprises. However, assuming that it's done, we are at the interesting point. The thing is, we have no hope in hell to propagate vfsmount into all calls of permission(). _HOWEVER_, we might not need to do that. Note that part potentially interested in vfsmount is very small and specific. Again, we are talking about want write and is readonly and (file or directory or symlink). Right now it needs only inode, but we want to make "is readonly" a function of vfsmount. Let's start with taking that check out of permission() and into its callers. Note that callers in floppy_open() (the worst from the "where do we get vfsmount/dentry" POV) do not give a damn - there the check is always false, since we are talking about block device. So they are not a problem. Places where we got the inode from struct file * or struct nameidata are also not a problem - there we have everything we might possibly ask for. That kills a lot of permission() instances. We also do not care for cases when we don't ask for write access (obviously - there the check can be dropped). Call in nfsd_permission() is not a problem, for the same reasons as with explicit IS_RDONLY() there. We have export, ergo we have a vfsmount. Call in presto_permission() is an utter bullshit - it's a hack of rather bad taste and should have been replaced with call of vfs_permission() (I mean, just look at it - Peter, please, LART whoever had done that). Checks that come out of calls in ext2 and ext3 xattr stuff can be dropped - after the changes above we would have them already done in callers. Now we are down to 8 functions may_create(), may_delete(), vfs_rename_dir() their intermezzo copies hpfs_unlink() and update_atime(). Let's take a look at update_atime(). We want to propagate struct vfsmount and struct dentry into that guy. It's worth the effort for a lot of reasons, not the least of them being that we will get per-mountpoint noatime and nodiratime out that - immediately. All callers that have inode obtained by struct file * are trivial. We have what we need there. Now, a large group actually comes from the same kind of place - it's ->readdir() in the majority of filesystems. We might be better off just taking that to caller of ->readdir() - provided that NFS folks are OK with that (nfs does _not_ update atime on client after readdir()). In any case, we have struct file * there anyway. nfsd_readlink() doesn't have struct file *, but it has export. Same as above. sys_readlink() has nameidata. open_namei() and do_follow_link() have pointers to relevant vfsmount (should be done accurately - it's easy to get confused there). autofs4 use - AFAICS there we want atime updated unconditionally, so calling update_atime() (update atime after checking noatime/nodiratime/readonly flags) is wrong. That's it with update_atime() and by that time we get visible result - ability to turn noatime and nodiratime on and off on a subtree basis. Now, what's left is hpfs_unlink(), may_create()/may_delete()/vfs_rename_dir() and intermezzo analogs of these 3. Let's see. Check in hpfs_unlink() can be dropped. It should call permission(), all right, but check for filesystem being writable for us is already done, so we can skip it. Situation with may_create()/may_delete() is more interesting. They are called from vfs_{create,link,unlink,....} and there we do not have a vfsmount. Let's start with taking the check ("fs is writable for us") from may_...() into these functions. They are _always_ done on a single fs, so even if we get several checks, they'll combine nicely. Moreover, in all cases except vfs_rename() that check can be done as the very first operation - if it fails we shoudl return -EROFS and do nothing. vfs_rename() is almost OK - there we have a POSIX-mandated idiocy: if (old_dentry->d_inode == new_dentry->d_inode) return 0; in the very beginning. The check can go immediately after that, but we can't move it in the very beginning. IOW, there is a case when rename() on a read-only filesystem is required to succeed - when source and target are links to the same inode. In that case POSIX requires to return 0 and do nothing. Check that had migrated into vfs_rename_dir() can be dropped - we do the same check in its caller earlier (it's called from vfs_rename()). BTW, why the fsck vfs_rename_dir() is not static? We don't use it anywhere else in the tree and it's not exported, so... Now, we are left with that merry bunch - vfs_<operation>. Let's take the POSIX idiocy to the callers of vfs_rename() and let's move the check for fs being writable to us into callers of all these guys. _NOW_ we are done. Indeed, there are two groups of callers (syscalls and nfsd) and both know what we are dealing with. The former have vfsmount, the latter have export. Note that passing vfsmount into vfs_...() would be a Wrong Thing(tm) - they are deliberately fs-local. I.e. they don't care where (and if) fs is mounted - they operate below the mount tree level. Intermezzo analogs are analogous ;-) We can deal with them in the same manner. OK, so far we have shown that per-mountpoint ro/noatime/nodiratime are doable. However, the solution as described above is *NOT* going to be accepted - it sprinkles a lot of crap all over the tree for no visible reason. Let's take a look at the resulting picture and see how it can be cleaned up. What had actually changed? We used to have checks for "fs is writable" on a fairly low level. The end result has their analogs on earlier stages - at the point where we have decided that operation will happen on *this* part of mount tree. That has an obvious functionality problem - what happens if we decide that fs is writable and remount it read-only between the check and actual work? *However*, this is not a new issue. Current code has exact same problem. We need to deal with it anyway. Basically, what's wrong with both current and modified trees is that we ask "can I write to that sucker now?" and consider the positive answer as go-ahead. Theoretically, it could even work - if remount would block until the transient operation is done or say just say "busy" in all cases when something is going on. We even do some checks of that sort. However, they deal only with long-term stuff - files being opened for write or unlinked files kept alive by being open. Transient stuff is ignored, so we can very well get fs remounted r/o right after e.g. mkdir() does all checks and decides to go ahead. How to fix that? Well, the obvious way would be to bracket transient stuff with WILL WRITE/WONT WRITE. With filesystem being able to say DO WRITE/DONT WRITE, obviously ;-) But look, we have already done half of that - we have the opening brackets. And that's exactly what our shifted checks are - we are asking for write access to filesystem, we call a function that assumes such access and once it returns we are done with the thing. IOW, adding the closing brackets is easy now. And that's what we were missing in the above. Now we can get sane semantics for all that stuff. Why would filesystem be read-only or read-write? Well, (1) it can be read-only because it refuses to be read-write, period. E.g. no matter what you do, filesystem on a CD will *not* be writable. Ever. Ditto for remote filesystem that is not exported read-write. Ditto for a filesystem that doesn't know how to be writable. (2) it can be read-only because nobody asked it to be read-write. (3) it can be read-only because sysadmin *told* it to stop being writable. What happens to these cases if we want per-mountpoint writability? (1) doesn't change at all (2) becomes "none of the instances are asked to be writable" (3) becomes independent from (2) IOW, we need to distinguish between "make that instance read-only, stop allowing writes to come via it" and "make fs readonly if it's not busy writing stuff; do _not_ consider lusers wanting it to be writable an obstacle, they are welcome to go forth and procreate". And with that distinction we get a very nice semantics, indeed. Namely, * vfsmounts have a "Don't write through me" flag. * superblock has a counter for transient write accesses (->s_writes). * superblock has a "Sod off, I'm readonly" flag (->s_baldrick). Requesting a write access checks both flags and bumps ->s_writes. Saying that write is over decrements ->s_writes. Requesting a global readonly remount does current checks (for non-transient writes), checks ->s_writes and if it's 0 - sets ->s_baldrick and initiates syncing. Asking to remount read-write asks filesystem if it would agree to reset aforementioned flag and resets the vfsmount flag if fs does agree. That's it. Now, we might actually go further and try to eliminate the current mess in check for non-transient write access. It's not even that hard - there are only two kinds of non-transients. 1) file can be opened for write. We have asked for write access in may_open(); so let's not relinquish it until the final fput(). 2) file can be unlinked but kept open. Let the filesystem bump the ->s_writes when the ->i_nlink reaches 0 and have the ->delete_inode() decrement it when it's done. That will make the current mess unnecessary - we can just check ->s_writes and it will tell us if the thing is busy. Moreover, with that scheme we could even play with "if hadn't been asked for write access in a while, tell it to go readonly but to be ready to become read-write as soon as the next request for write access will be issued" - the policy would be in userland and kernel-side part wouldn't be hard. One such scheme would keep a flag that could be reset by userland if ->s_writes was currently 0 and set whenever we grant write access; attempt to reset it when it's already reset would do a "soft" remount - it would tell the fs driver to do usual steps of r/o remount, but switch back to r/w when write access is requested again. Userland process would simply try to reset the flag periodically. There's a lot of possible variations - basically, with that stuff done we get remount logics into sane shape and that allows a lot of interesting things. *Besides* the immediate results (per-subtree read-only). So there... It certainly appears to be doable, it doesn't require too nasty surgery of in-kernel APIs and it's splittable into reasonably small steps that make sense on their own. If somebody would start doing that they'd have to do (accurately) verification of correctness on each step - thing that is missing in the above and can require dealing with problems I'd overlooked. FWIW, my gut feeling from looking at that stuff is that there won't be anything too nasty, but that needs to be checked if somebody will start that work - the stuff above is a quick and dirty attempt of a roadmap, but there might be pits with something unpleasant. I would estimate that as 3-4 months' work / 4-6 months on gradual merge (started in parallel) / several months of playing with the results after the semantics of remount will be sanitized. YMMV. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [long] per-mountpoint readonly 2003-05-29 8:21 ` [long] per-mountpoint readonly viro @ 2003-05-29 9:02 ` Trond Myklebust 2003-05-29 9:31 ` viro 2003-05-29 9:42 ` Christoph Hellwig 2003-05-29 16:24 ` Bryan Henderson 2 siblings, 1 reply; 19+ messages in thread From: Trond Myklebust @ 2003-05-29 9:02 UTC (permalink / raw) To: viro; +Cc: Shaya Potter, linux-fsdevel >>>>> " " == viro <viro@parcelfarce.linux.theplanet.co.uk> writes: > All callers that have inode obtained by struct file * are > trivial. We have what we need there. Now, a large group > actually comes from the same kind of place - it's ->readdir() > in the majority of filesystems. We might be better off just > taking that to caller of ->readdir() - provided that NFS folks > are OK with that (nfs does _not_ update atime on client after > readdir()). In any case, we have struct file * there anyway. Provided that you are not planning on overriding the S_NOATIME flag, NFS should be fine. We just want to suppress update_atime() for *all* cases since we have no control over how the server updates this value. Cheers, Trond ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [long] per-mountpoint readonly 2003-05-29 9:02 ` Trond Myklebust @ 2003-05-29 9:31 ` viro 0 siblings, 0 replies; 19+ messages in thread From: viro @ 2003-05-29 9:31 UTC (permalink / raw) To: Trond Myklebust; +Cc: Shaya Potter, linux-fsdevel On Thu, May 29, 2003 at 11:02:01AM +0200, Trond Myklebust wrote: > >>>>> " " == viro <viro@parcelfarce.linux.theplanet.co.uk> writes: > > > All callers that have inode obtained by struct file * are > > trivial. We have what we need there. Now, a large group > > actually comes from the same kind of place - it's ->readdir() > > in the majority of filesystems. We might be better off just > > taking that to caller of ->readdir() - provided that NFS folks > > are OK with that (nfs does _not_ update atime on client after > > readdir()). In any case, we have struct file * there anyway. > > Provided that you are not planning on overriding the S_NOATIME flag, > NFS should be fine. We just want to suppress update_atime() for *all* > cases since we have no control over how the server updates this value. Umm... Actually, I thought about per-mountpoint noatime, but we can do (mnt->mnt_flags & MNT_NOATIME) | (s->s_flags & S_NOATIME) just fine, so NFS can still disable it just fine. Is there any network filesystem that would * want atime updated by client for *some* directory accesses and * want it left alone for readdir()? If not, we can clean the things up nicely. NFS is OK, what about the rest? ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [long] per-mountpoint readonly 2003-05-29 8:21 ` [long] per-mountpoint readonly viro 2003-05-29 9:02 ` Trond Myklebust @ 2003-05-29 9:42 ` Christoph Hellwig 2003-05-29 16:24 ` Bryan Henderson 2 siblings, 0 replies; 19+ messages in thread From: Christoph Hellwig @ 2003-05-29 9:42 UTC (permalink / raw) To: viro; +Cc: Shaya Potter, linux-fsdevel On Thu, May 29, 2003 at 09:21:27AM +0100, viro@parcelfarce.linux.theplanet.co.uk wrote: > Let's take a look at update_atime(). We want to propagate struct vfsmount > and struct dentry into that guy. It's worth the effort for a lot of reasons, > not the least of them being that we will get per-mountpoint noatime and > nodiratime out that - immediately. I wonder whether it's worth to have a variant that gets a struct file *, XFS currently has a rather hackish implementation of a privilegued noatime open that I'd like to move into VFS instead of the current horrible hack i. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [long] per-mountpoint readonly 2003-05-29 8:21 ` [long] per-mountpoint readonly viro 2003-05-29 9:02 ` Trond Myklebust 2003-05-29 9:42 ` Christoph Hellwig @ 2003-05-29 16:24 ` Bryan Henderson 2003-05-29 19:22 ` viro 2 siblings, 1 reply; 19+ messages in thread From: Bryan Henderson @ 2003-05-29 16:24 UTC (permalink / raw) To: viro; +Cc: linux-fsdevel, Shaya Potter >OW, that check (IS_RDONLY and (regular|directory|symlink) ==> EROFS) >should be moved into fs/namei.c::permission(). permission() is the wrong place for that. I'm not saying it wouldn't work there, but it's conceptually wrong and would make for mistakes in the future. The EROFS failure has nothing to do with permission; it has to do with basic capabilities of the filesystem image (or in this proposal, of the mount). If it were a question of permission, then the identity and authority of the user would be involved. I've already seen a case of strange programming results because some but not all the programmers in a certain area believed that rejecting writes to a r/o filesystem image was a question of permission. I did a create/open of a file via a r/o mount and the open failed with EROFS, but the file got created anyway! I believe there is a fundamental difference between saying, "one who accesses this file via this name can't write to it" and "one can't write to this filesystem via this filesystem image (struct superblock). The latter may have implications for locking in shared filesystems and for caching. It may even be implemented in some component downstream of Linux. Both kinds of r/o are good, though. I'd like to see both. -- Bryan Henderson IBM Almaden Research Center San Jose CA Filesystems ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [long] per-mountpoint readonly 2003-05-29 16:24 ` Bryan Henderson @ 2003-05-29 19:22 ` viro 2003-05-29 21:30 ` Bryan Henderson 0 siblings, 1 reply; 19+ messages in thread From: viro @ 2003-05-29 19:22 UTC (permalink / raw) To: Bryan Henderson; +Cc: linux-fsdevel, Shaya Potter On Thu, May 29, 2003 at 09:24:00AM -0700, Bryan Henderson wrote: > > > > > >OW, that check (IS_RDONLY and (regular|directory|symlink) ==> EROFS) > >should be moved into fs/namei.c::permission(). > > permission() is the wrong place for that. I'm not saying it wouldn't work > there, but it's conceptually wrong and would make for mistakes in the > future. The EROFS failure has nothing to do with permission; it has to do > with basic capabilities of the filesystem image (or in this proposal, of > the mount). If it were a question of permission, then the identity and > authority of the user would be involved. Have you actually read past that point? It does _not_ stay in permission() - as described below. > I've already seen a case of strange programming results because some but > not all the programmers in a certain area believed that rejecting writes to > a r/o filesystem image was a question of permission. I did a create/open > of a file via a r/o mount and the open failed with EROFS, but the file got > created anyway! IOW, you have not... > I believe there is a fundamental difference between saying, "one who > accesses this file via this name can't write to it" and "one can't write to > this filesystem via this filesystem image (struct superblock). The latter > may have implications for locking in shared filesystems and for caching. > It may even be implemented in some component downstream of Linux. Both > kinds of r/o are good, though. I'd like to see both. Yes, and? In the final variant filesystem is free to reject the request for write access. And instead of having it done as a check at one point in the operation (which is vulnerable to remount races, for obvious reasons) we end with request write access / do the job / give up write access. Write access to fs - not to any given object on it; permissions checks do stay where they currently are. And yes, it doesn't belong to permission(9). Or to ->permission() (as it's currently done). It belongs in places where VFS decides that it will need to modify objects on the filesystem - before asking if it's allowed to do something to specific objects. Mixing it with permission checks for objects is, indeed, bogus. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: per-mountpoint readonly 2003-05-29 19:22 ` viro @ 2003-05-29 21:30 ` Bryan Henderson 0 siblings, 0 replies; 19+ messages in thread From: Bryan Henderson @ 2003-05-29 21:30 UTC (permalink / raw) To: viro; +Cc: linux-fsdevel, Shaya Potter, viro >> >OW, that check (IS_RDONLY and (regular|directory|symlink) ==> EROFS) >> >should be moved into fs/namei.c::permission(). >> >> permission() is the wrong place for that. > >Have you actually read past that point? No. As you might have expected, I did not read your hundreds of lines of explanation of the excruciating details of implementation. It would not have been productive for me to do so, anyway, since I don't have the details of the current implementation memorized as you have. Instead I chose just to address the one statement that appeared to be part of an overview of the strategy and made it look like you were overlooking an important design issue. I'll assume my concern was just a matter of the organization of your email rather than an actual belief on your part that readonliness should be handled by permission(). -- Bryan Henderson IBM Almaden Research Center San Jose Filesystems ^ permalink raw reply [flat|nested] 19+ messages in thread
* changing permission()/vfs_permission... to work on dentry
@ 2003-05-28 20:43 Shaya Potter
2003-05-28 21:48 ` viro
0 siblings, 1 reply; 19+ messages in thread
From: Shaya Potter @ 2003-05-28 20:43 UTC (permalink / raw)
To: linux-fsdevel
I've gone through the entire fs/* vfs layer picking out every use of
permission to see if it can easily use the dentry instead, and it can
(list below showing that the dentry is readily available in every vfs
case)
The idea for converting it over would be to at first add 2 temporary
functions, entry_permission() and dentry_vfs_permission(), so that one
can proceed incrementally, and then to do a total change over by getting
rid of the old permission() and vfs_permission() and renaming the
temporary functions to the regular.
I'm making an assumption (perhaps dangerous) that the fs permission()
functions directly mirrors vfs_permission() (based only on experience w/
nfs filesystem) and therefore since fs permission() function is only
called from permission() (as vfs_permission() can also be) and therefore
would all be easy to switch over.
anyways, just want to make sure that I'm not missing anything.
thanks,
shaya
-------------------------
exec.c
------
sys_use_lib()
error = permission(nd.dentry->d_inode, MAY_READ | MAY_EXEC);
open_exec()
inode = nd.dentry->d_inode;
int err = permission(inode, MAY_EXEC);
flush_old_exec()
permission(bprm->file->f_dentry->d_inode,MAY_READ)
prepare_binprm()
doesn't work off of permission directly - why?
namei.c
-------
vfs_permission()
change option to take a dentry and get inode from that,
instead of taking inode directly.
permission()
same as vfs_permission()
path_walk()
inode = nd->dentry->d_inode;
err = permission(inode, MAY_EXEC);
lookup_hash(struct dentry * base)
inode = base->d_inode;
err = permission(inode, MAY_EXEC);
static inline int may_delete(struct inode *dir,struct dentry *victim,
int isdir)
error = permission(dir,MAY_WRITE | MAY_EXEC);
since
if (!victim->d_inode || victim->d_parent->d_inode != dir)
return -ENOENT;
shouldn't be an issue.
static inline int may_create(struct inode *dir, struct dentry *child)
return permission(dir,MAY_WRITE | MAY_EXEC);
seems to be the same as above
open_namei()
inode = dentry->d_inode;
error = permission(inode,acc_mode);
vfs_rename_dir()
error = permission(old_dentry->d_inode, MAY_WRITE);
namespace.c
-----------
mount_is_safe()
if (permission(nd->dentry->d_inode, MAY_WRITE))
open.c
------
do_sys_truncate()
inode = nd.dentry->d_inode;
error = permission(inode,MAY_WRITE);
sys_utime()
inode = nd.dentry->d_inode;
error = permission(inode,MAY_WRITE)
sys_utimes()
inode = nd.dentry->d_inode;
error = permission(inode,MAY_WRITE)
sys_access()
res = permission(nd.dentry->d_inode, mode);
sys_chdir()
error = permission(nd.dentry->d_inode,MAY_EXEC);
sys_fchdir()
inode = dentry->d_inode;
error = permission(inode, MAY_EXEC);
sys_chroot()
error = permission(nd.dentry->d_inode,MAY_EXEC);
^ permalink raw reply [flat|nested] 19+ messages in thread* Re: changing permission()/vfs_permission... to work on dentry 2003-05-28 20:43 changing permission()/vfs_permission... to work on dentry Shaya Potter @ 2003-05-28 21:48 ` viro 2003-05-28 22:34 ` Shaya Potter 0 siblings, 1 reply; 19+ messages in thread From: viro @ 2003-05-28 21:48 UTC (permalink / raw) To: Shaya Potter; +Cc: linux-fsdevel On Wed, May 28, 2003 at 04:43:08PM -0400, Shaya Potter wrote: > I've gone through the entire fs/* vfs layer picking out every use of > permission to see if it can easily use the dentry instead, and it can > (list below showing that the dentry is readily available in every vfs > case) Why not grep over the entire tree? That would've immediately show at least 6 cases when we do _not_ have a dentry; 2 of them rather nasty (floppy_open() in floppy.c/floppy98.c). The real question is what the hell would you _do_ with dentry? 1) It's worthless without vfsmount - alone it does *NOT* determine the pathname. 2) assuming that you've somehow got both vfsmount and dentry (and thus enough information to find the pathnam), what will you do with it? Anything that requires ->i_sem on ancestors is not an option - quite often they will be already locked. Moreover, there is no warranty that pathname won't change right under you - starting with the parent of your dentry. IOW, what's the real goal? ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-28 21:48 ` viro @ 2003-05-28 22:34 ` Shaya Potter 2003-05-28 22:53 ` viro 0 siblings, 1 reply; 19+ messages in thread From: Shaya Potter @ 2003-05-28 22:34 UTC (permalink / raw) To: viro; +Cc: linux-fsdevel On Wed, 2003-05-28 at 17:48, viro@parcelfarce.linux.theplanet.co.uk wrote: > On Wed, May 28, 2003 at 04:43:08PM -0400, Shaya Potter wrote: > > I've gone through the entire fs/* vfs layer picking out every use of > > permission to see if it can easily use the dentry instead, and it can > > (list below showing that the dentry is readily available in every vfs > > case) > > Why not grep over the entire tree? That would've immediately show > at least 6 cases when we do _not_ have a dentry; 2 of them rather > nasty (floppy_open() in floppy.c/floppy98.c). well, floppy's aren't so much what I'm interested in, but that's a good point. either the vfs would have to be changed or the permission/inode interface would have to stay around. floppy_open (I believe) is just called from the filp, which has access to the dentry, so it could be passed in, but I'm not sure if restructering all that would be worthwhile. > The real question is what the hell would you _do_ with dentry? > > 1) It's worthless without vfsmount - alone it does *NOT* determine the > pathname. the kernel can always know the real vfsmount. if you care about within a specific context, can use that too. > 2) assuming that you've somehow got both vfsmount and dentry (and thus > enough information to find the pathnam), what will you do with it? > Anything that requires ->i_sem on ancestors is not an option - quite > often they will be already locked. Moreover, there is no warranty that > pathname won't change right under you - starting with the parent of > your dentry. need to think more about the issues you just brought up, the path changing is what I'm mostly concerned about. > > IOW, what's the real goal? Well, I want to be able to create a SubDomain like system that allows one to run a process within a context that lets you specify an extra layer of permissions on top of the underlying fs. so my permission() would be something like if ( (context = find_context(current->pid)) != NULL ) { d_path(some denty, some vfsmount, scratch, size); to get full path and_mode = get_mode(context, full_path); real mode = inode mode & and_mode; } else just do normal code. I don't actually want this within the kernel, but be able to do it via fs (aka module) support. Basically the argument is that one has more information from the dentry than just from the inode, and therefore it would make sense to expose that information, as then things like modules could make use of it. anyways, if there's a better way to do this, I'm all ears. I'm also willing to do the restructuring myself, if you think there's some benefit in it. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-28 22:34 ` Shaya Potter @ 2003-05-28 22:53 ` viro 2003-05-29 0:33 ` Shaya Potter 0 siblings, 1 reply; 19+ messages in thread From: viro @ 2003-05-28 22:53 UTC (permalink / raw) To: Shaya Potter; +Cc: linux-fsdevel On Wed, May 28, 2003 at 06:34:32PM -0400, Shaya Potter wrote: > well, floppy's aren't so much what I'm interested in, but that's a good > point. either the vfs would have to be changed or the permission/inode > interface would have to stay around. floppy_open (I believe) is just > called from the filp, which has access to the dentry, so it could be > passed in, but I'm not sure if restructering all that would be > worthwhile. No, it doesn't. As the matter of fact it's always NULL. What's more, you do not have _any_ pathname in a bunch of cases (open_by_devnum()). > > The real question is what the hell would you _do_ with dentry? > > > > 1) It's worthless without vfsmount - alone it does *NOT* determine the > > pathname. > > the kernel can always know the real vfsmount. Define "real". There can be a lot of them and none are more real than other - same situation as with dentries, actually (all links have the same status; there is no "primary" one). You'll need to propagate pointers to vfsmounts and it won't be pretty - e.g. hpfs_unlink() calls permission() and passing vfsmount to ->unlink() is just plain *wrong*. > if you care about within a specific context, can use that too. > > > 2) assuming that you've somehow got both vfsmount and dentry (and thus > > enough information to find the pathnam), what will you do with it? > > Anything that requires ->i_sem on ancestors is not an option - quite > > often they will be already locked. Moreover, there is no warranty that > > pathname won't change right under you - starting with the parent of > > your dentry. > > need to think more about the issues you just brought up, the path > changing is what I'm mostly concerned about. > > > > > IOW, what's the real goal? > > Well, I want to be able to create a SubDomain like system that allows > one to run a process within a context that lets you specify an extra > layer of permissions on top of the underlying fs. > > so my permission() would be something like > > if ( (context = find_context(current->pid)) != NULL ) > { > d_path(some denty, some vfsmount, scratch, size); to get full path > and_mode = get_mode(context, full_path); > > real mode = inode mode & and_mode; Erm. Based on a _pathname_? I.e. just on a string? ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-28 22:53 ` viro @ 2003-05-29 0:33 ` Shaya Potter 2003-05-29 12:25 ` Jan Hudec 2003-05-29 12:40 ` Lucas Correia Villa Real 0 siblings, 2 replies; 19+ messages in thread From: Shaya Potter @ 2003-05-29 0:33 UTC (permalink / raw) To: viro; +Cc: linux-fsdevel On Wed, 2003-05-28 at 18:53, viro@parcelfarce.linux.theplanet.co.uk wrote: > On Wed, May 28, 2003 at 06:34:32PM -0400, Shaya Potter wrote: > > > well, floppy's aren't so much what I'm interested in, but that's a good > > point. either the vfs would have to be changed or the permission/inode > > interface would have to stay around. floppy_open (I believe) is just > > called from the filp, which has access to the dentry, so it could be > > passed in, but I'm not sure if restructering all that would be > > worthwhile. > > No, it doesn't. As the matter of fact it's always NULL. What's more, > you do not have _any_ pathname in a bunch of cases (open_by_devnum()). ok, this is a learning experience. > > > The real question is what the hell would you _do_ with dentry? > > > > > > 1) It's worthless without vfsmount - alone it does *NOT* determine the > > > pathname. > > > > the kernel can always know the real vfsmount. > > Define "real". There can be a lot of them and none are more real than > other - same situation as with dentries, actually (all links have the > same status; there is no "primary" one). well real depends on what you want. Take for instance the example I gave w/ the context, the context can contain a vfsmount, which you then use. > > You'll need to propagate pointers to vfsmounts and it won't be pretty - > e.g. hpfs_unlink() calls permission() and passing vfsmount to ->unlink() > is just plain *wrong*. one doesn't have to. permission() figures out calling process (current->uid), figures out calling processes context. > > > if you care about within a specific context, can use that too. > > > > > 2) assuming that you've somehow got both vfsmount and dentry (and thus > > > enough information to find the pathnam), what will you do with it? > > > Anything that requires ->i_sem on ancestors is not an option - quite > > > often they will be already locked. Moreover, there is no warranty that > > > pathname won't change right under you - starting with the parent of > > > your dentry. > > > > need to think more about the issues you just brought up, the path > > changing is what I'm mostly concerned about. > > > > > > > > IOW, what's the real goal? > > > > Well, I want to be able to create a SubDomain like system that allows > > one to run a process within a context that lets you specify an extra > > layer of permissions on top of the underlying fs. > > > > so my permission() would be something like > > > > if ( (context = find_context(current->pid)) != NULL ) > > { > > d_path(some denty, some vfsmount, scratch, size); to get full path > > and_mode = get_mode(context, full_path); > > > > real mode = inode mode & and_mode; > > Erm. Based on a _pathname_? I.e. just on a string? yes. The issue we are trying to solve (much like SubDomain http://www.immunix.org/subdomain.html) is that you have a single fs, but not every application needs access to that entire namespace, but from an administrative point of view, its easier to deal w/ a single namespace. For instance, sendmail doesn't need /bin/sh, it be fairly hard to administrate a sendmail box that didn't have it though. If there's no /bin/sh in the processes "namespace" (used loosely, as in mode 000 to it and even uid 0 processes) the ability to get a root shell is limited. The problem is, one would have a problem storing all this attribute data for every file in a system as there can be many contexts. If one can store the rules instead and use "string compares" (well, not really string compares as that could be too slow) one can partition off the applications. So why not chroot? well, it doesn't work so well for uid 0 apps, as they can chroot themselves again. and even if that wasn't an issue, one isn't operating under a single namespace anymore so it makes administration harder. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-29 0:33 ` Shaya Potter @ 2003-05-29 12:25 ` Jan Hudec 2003-05-29 12:41 ` viro 2003-05-29 12:40 ` Lucas Correia Villa Real 1 sibling, 1 reply; 19+ messages in thread From: Jan Hudec @ 2003-05-29 12:25 UTC (permalink / raw) To: Shaya Potter; +Cc: viro, linux-fsdevel On Wed, May 28, 2003 at 08:33:27PM -0400, Shaya Potter wrote: > On Wed, 2003-05-28 at 18:53, viro@parcelfarce.linux.theplanet.co.uk > wrote: > > Erm. Based on a _pathname_? I.e. just on a string? > > yes. The issue we are trying to solve (much like SubDomain > http://www.immunix.org/subdomain.html) is that you have a single fs, but > not every application needs access to that entire namespace, but from an > administrative point of view, its easier to deal w/ a single namespace. > For instance, sendmail doesn't need /bin/sh, it be fairly hard to > administrate a sendmail box that didn't have it though. If there's no > /bin/sh in the processes "namespace" (used loosely, as in mode 000 to it > and even uid 0 processes) the ability to get a root shell is limited. > > The problem is, one would have a problem storing all this attribute data > for every file in a system as there can be many contexts. If one can > store the rules instead and use "string compares" (well, not really > string compares as that could be too slow) one can partition off the > applications. > > So why not chroot? well, it doesn't work so well for uid 0 apps, as > they can chroot themselves again. and even if that wasn't an issue, one > isn't operating under a single namespace anymore so it makes > administration harder. Perhaps it's a stupid idea, but couldn't you resolve the names to inode numbers first (though it would require checking when something happens to those inodes)? I would expect you need to make the file (eg. shell) unaccessible and not just one of it's dentries (eg. /bin/sh). Perhaps this would be solved by the intent patches anyway. Since the intent should be passed to all the methods, it should make it to permission too. And since it will probably be boud to nameidata, it would include everything (even the vfsmount). ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb@ucw.cz> ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-29 12:25 ` Jan Hudec @ 2003-05-29 12:41 ` viro 0 siblings, 0 replies; 19+ messages in thread From: viro @ 2003-05-29 12:41 UTC (permalink / raw) To: Jan Hudec, Shaya Potter, linux-fsdevel On Thu, May 29, 2003 at 02:25:48PM +0200, Jan Hudec wrote: > Perhaps it's a stupid idea, but couldn't you resolve the names to inode > numbers first (though it would require checking when something happens > to those inodes)? I would expect you need to make the file (eg. shell) > unaccessible and not just one of it's dentries (eg. /bin/sh). If you have bogus links sitting around, you might very well have bogus copies too. > Perhaps this would be solved by the intent patches anyway. Since the > intent should be passed to all the methods, it should make it to > permission too. And since it will probably be boud to nameidata, it > would include everything (even the vfsmount). Filesystem methods should _not_ depend on the instance they are working on. IOW, control over namespace does not belong to fs - it doesn't get to decide where it's mounted and it certainly doesn't get to work in different ways depending on where it's mounted. All such stuff belongs to VFS and nowhere else. ^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: changing permission()/vfs_permission... to work on dentry 2003-05-29 0:33 ` Shaya Potter 2003-05-29 12:25 ` Jan Hudec @ 2003-05-29 12:40 ` Lucas Correia Villa Real 1 sibling, 0 replies; 19+ messages in thread From: Lucas Correia Villa Real @ 2003-05-29 12:40 UTC (permalink / raw) To: linux-fsdevel On Wednesday 28 May 2003 21:33, Shaya Potter wrote: > yes. The issue we are trying to solve (much like SubDomain > http://www.immunix.org/subdomain.html) is that you have a single fs, but > not every application needs access to that entire namespace, but from an > administrative point of view, its easier to deal w/ a single namespace. > For instance, sendmail doesn't need /bin/sh, it be fairly hard to > administrate a sendmail box that didn't have it though. If there's no > /bin/sh in the processes "namespace" (used loosely, as in mode 000 to it > and even uid 0 processes) the ability to get a root shell is limited. > > The problem is, one would have a problem storing all this attribute data > for every file in a system as there can be many contexts. If one can > store the rules instead and use "string compares" (well, not really > string compares as that could be too slow) one can partition off the > applications. > > So why not chroot? well, it doesn't work so well for uid 0 apps, as > they can chroot themselves again. and even if that wasn't an issue, one > isn't operating under a single namespace anymore so it makes > administration harder. Hi, Can't this be implemented as a stackable filesystem instead? I guess this stuff can be handled on VFS. Lucas ^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2003-05-29 21:17 UTC | newest] Thread overview: 19+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2003-05-29 0:55 changing permission()/vfs_permission... to work on dentry viro 2003-05-29 4:20 ` Shaya Potter 2003-05-29 4:38 ` Chris Wright 2003-05-29 8:27 ` viro 2003-05-29 8:21 ` [long] per-mountpoint readonly viro 2003-05-29 9:02 ` Trond Myklebust 2003-05-29 9:31 ` viro 2003-05-29 9:42 ` Christoph Hellwig 2003-05-29 16:24 ` Bryan Henderson 2003-05-29 19:22 ` viro 2003-05-29 21:30 ` Bryan Henderson -- strict thread matches above, loose matches on Subject: below -- 2003-05-28 20:43 changing permission()/vfs_permission... to work on dentry Shaya Potter 2003-05-28 21:48 ` viro 2003-05-28 22:34 ` Shaya Potter 2003-05-28 22:53 ` viro 2003-05-29 0:33 ` Shaya Potter 2003-05-29 12:25 ` Jan Hudec 2003-05-29 12:41 ` viro 2003-05-29 12:40 ` Lucas Correia Villa Real
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox