changing permission()/vfs_permission... to work on dentry
Quoted 7 lines · Shaya Potter
Quoted 3 lines
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?
Quoted 6 lines
Quoted 3 lines
You'll need to propagate pointers to vfsmounts and it won't be pretty - e.g.
hpfs_unlink()callspermission()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.
Quoted 7 lines
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/shin 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.
Quoted 1 line
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 -----
Quoted 2 lines · On Wed, 2003-05-28 at 20:55, [email protected] wrote:
So give it a _REAL_ namespace. And bind
/dev/nullover/bin/shin 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?
Quoted 8 lines · * Shaya Potter ([email protected]) wrote:
Quoted 2 lines · On Wed, 2003-05-28 at 20:55, [email protected] wrote:
So give it a _REAL_ namespace. And bind
/dev/nullover/bin/shin 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.
Quoted 3 lines
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
Signature · 1 line
Linux Security Modules http://lsm.immunix.org http://lsm.bkbits.net
Quoted 5 lines · Chris Wright
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 theIS_RDONLY()check could see mountpoint specific flags as well as thesuper_blockflags. 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.
[long] per-mountpoint readonly
In reply to Shaya PotterQuoted 5 lines · Shaya Potter
Quoted 2 lines · On Wed, 2003-05-28 at 20:55, [email protected] wrote:
So give it a _REAL_ namespace. And bind
/dev/nullover/bin/shin it. And revoke the capability to call mount(2) and umount(2). End of story.
Quoted 7 lines
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 functionsmay_create(), may_delete(), vfs_rename_dir()
their intermezzo copieshpfs_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.
Re: [long] per-mountpoint readonly
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
" " == viro <[email protected]> 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
Re: [long] per-mountpoint readonly
Quoted 10 lines · Trond Myklebust
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
" " == viro <[email protected]> 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.
Quoted 3 lines
Provided that you are not planning on overriding the
S_NOATIMEflag, NFS should be fine. We just want to suppressupdate_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?
Re: [long] per-mountpoint readonly
In reply to [email protected]Quoted 4 lines · On Thu, May 29, 2003 at 09:21:27AM +0100…
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.
Re: [long] per-mountpoint readonly
In reply to [email protected]Quoted 6 lines
OW, that check (
IS_RDONLYand (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
Re: [long] per-mountpoint readonly
Quoted 7 lines · Bryan Henderson
Quoted 6 lines
OW, that check (
IS_RDONLYand (regular|directory|symlink) ==> EROFS) should be moved into fs/namei.c::permission().
Quoted 6 lines
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.
Quoted 5 lines
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...
Quoted 6 lines
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.
Re: per-mountpoint readonly
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
OW, that check (
IS_RDONLYand (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