changing permission()/vfs_permission... to work on dentry
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);
Quoted 4 lines · Shaya Potter
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?
Quoted 9 lines · On Wed, 2003-05-28 at 17:48, [email protected] wrote:
Quoted 4 lines · Shaya Potter
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()infloppy.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.
Quoted 4 lines
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.
Quoted 6 lines
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.
Quoted 2 lines
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.
Quoted 6 lines · Shaya Potter
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()).
Quoted 6 lines
Quoted 4 lines
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*.
Quoted 19 lines
if you care about within a specific context, can use that too.
Quoted 6 lines
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.
Quoted 2 lines
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.
Quoted 8 lines
so my
permission()would be something likeif ( (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?
Quoted 11 lines · On Wed, 2003-05-28 at 18:53, [email protected] wrote:
Quoted 6 lines · Shaya Potter
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.
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
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.
Quoted 4 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.
Quoted 22 lines
Quoted 22 lines
if you care about within a specific context, can use that too.
Quoted 6 lines
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.
Quoted 2 lines
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
Quoted 8 lines
Quoted 6 lines
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.
Quoted 19 lines · Shaya Potter
Quoted 1 line · On Wed, 2003-05-28 at 18:53, [email protected] 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/shin 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.
Quoted 4 lines
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 <[email protected]>
Quoted 4 lines · Jan Hudec
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.
Quoted 4 lines
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.
Quoted 15 lines · Shaya Potter
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 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.
Quoted 4 lines
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