Confirmation of methods for calculating requested pathname.
Subsystems (7)
The current Linux kernel is not designed to pass vfsmount parameter that is crucial for pathname-based security including AppArmor and TOMOYO Linux, to LSM. Though both projects have been proposing patches to calculate pathname, none of them have been accepted as you know.
To find the reason for NACK, we examined past proposals and the threads. And we came to understand that you oppose accessing vfsmount inside vfs helper functions. Is our understanding correct?
If our understanding is correct, we would like to propose a new method that does not require modifications to vfs helper functions. Attached patch is a trial of this method.
vfs helper functions are surrounded by mnt_want_write() and mnt_drop_write() pairs which receive "struct vfsmount" parameter since 2.6.26. So, by remembering the absolute pathname of "struct vfsmount" of the moment, LSM module can calculate an absolute pathname of the given "struct dentry" parameter inside vfs_* functions, without passing "struct vfsmount" parameter to vfs_* functions.
This approach doesn't access vfsmount inside vfs helper functions, and modification of existing kernel is only in task_struct and mnt_want/drop_write().
We would like to hear your comments as fs maintainer.
Regards,
---
Subject: Remembering previously referenced vfsmount's pathname.
--- fs/Kconfig | 18 ++++++++++++++++++ fs/namespace.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/init_task.h | 7 +++++++ include/linux/sched.h | 3 +++ kernel/fork.c | 8 ++++++++ 5 files changed, 82 insertions(+)
fs/Kconfig +18 -0
@@ -2094,4 +2094,22 @@ endif source "fs/nls/Kconfig" source "fs/dlm/Kconfig" +config REMEMBER_VFSMOUNT_PATH + bool "Remember previously referenced vfsmount's pathname." + help + The vfs_* functions (e.g. vfs_mkdir) don't receive "struct vfsmount" + parameter, making it impossible to calculate an absolute pathname of + the given "struct dentry" parameter inside vfs_* functions. + + If someone wants to get an absolute pathname of the given + "struct dentry" parameter, he/she must calculate it outside + vfs_* functions. + + However, vfs_* functions are surrounded by mnt_want_write() and + mnt_drop_write() pairs which receive "struct vfsmount" parameter. + So, by remembering the absolute pathname of "struct vfsmount" of + the moment, he/she can calculate an absolute pathname of the given + "struct dentry" parameter inside vfs_* functions, without passing + "struct vfsmount" parameter to vfs_* functions. + endmenu
fs/namespace.c +46 -0
70 lines not on this page · raw message
include/linux/init_task.h +7 -0
@@ -113,6 +113,12 @@ extern struct group_info init_groups;# define CAP_INIT_BSET CAP_INIT_EFF_SET#endif +#ifdef CONFIG_REMEMBER_VFSMOUNT_PATH +#define INIT_VFSMOUNT_PATH .current_vfsmount_path = NULL, +#else +#define INIT_VFSMOUNT_PATH +#endif +/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -179,6 +185,7 @@ extern struct group_info init_groups;INIT_IDS \ INIT_TRACE_IRQFLAGS \INIT_LOCKDEP \ + INIT_VFSMOUNT_PATH \ }
include/linux/sched.h +3 -0
@@ -1300,6 +1300,9 @@ struct task_struct {int latency_record_count;struct latency_record latency_record[LT_SAVECOUNT ];#endif +#ifdef CONFIG_REMEMBER_VFSMOUNT_PATH +const char *current_vfsmount_path; +#endif };/*
kernel/fork.c +8 -0
@@ -1051,6 +1051,14 @@ static struct task_struct *copy_process( p->blocked_on =NULL ;/* not blocked yet */ #endif +#ifdef CONFIG_REMEMBER_VFSMOUNT_PATH +/* +* It seems to me that this function is called between mnt_want_write() +* and mnt_drop_write(). I don't know why. +*/ + p->current_vfsmount_path =NULL ; +#endif +/* Perform scheduler related setup. Assign this task to a CPU. */ sched_fork (p, clone_flags);
(repost) Confirmation of methods for calculating requested pathname.
Al, could you answer the following question?
The current Linux kernel is not designed to pass vfsmount parameter that is crucial for pathname-based security including AppArmor and TOMOYO Linux, to LSM. Though both projects have been proposing patches to calculate pathname, none of them have been accepted as you know.
To find the reason for NACK, we examined past proposals and the threads. And we came to understand that you oppose accessing vfsmount inside vfs helper functions. Is our understanding correct?
If our understanding is correct, we would like to propose a new method that does not require modifications to vfs helper functions. Attached patch is a trial of this method.
vfs helper functions are surrounded by mnt_want_write() and mnt_drop_write() pairs which receive "struct vfsmount" parameter since 2.6.26. So, by remembering the absolute pathname of "struct vfsmount" of the moment, LSM module can calculate an absolute pathname of the given "struct dentry" parameter inside vfs_* functions, without passing "struct vfsmount" parameter to vfs_* functions.
This approach doesn't access vfsmount inside vfs helper functions, and modification of existing kernel is only in task_struct and mnt_want/drop_write().
We would like to hear your comments as fs maintainer.
Regards,
---
Subject: Remembering previously referenced vfsmount's pathname.
--- fs/Kconfig | 18 ++++++++++++++++++ fs/namespace.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/init_task.h | 7 +++++++ include/linux/sched.h | 3 +++ kernel/fork.c | 8 ++++++++ 5 files changed, 82 insertions(+)
fs/Kconfig +18 -0
@@ -2093,4 +2093,22 @@ endif source "fs/nls/Kconfig" source "fs/dlm/Kconfig" +config REMEMBER_VFSMOUNT_PATH + bool "Remember previously referenced vfsmount's pathname." + help + The vfs_* functions (e.g. vfs_mkdir) don't receive "struct vfsmount" + parameter, making it impossible to calculate an absolute pathname of + the given "struct dentry" parameter inside vfs_* functions. + + If someone wants to get an absolute pathname of the given + "struct dentry" parameter, he/she must calculate it outside + vfs_* functions. + + However, vfs_* functions are surrounded by mnt_want_write() and + mnt_drop_write() pairs which receive "struct vfsmount" parameter. + So, by remembering the absolute pathname of "struct vfsmount" of + the moment, he/she can calculate an absolute pathname of the given + "struct dentry" parameter inside vfs_* functions, without passing + "struct vfsmount" parameter to vfs_* functions. + endmenu
fs/namespace.c +46 -0
70 lines not on this page · raw message
include/linux/init_task.h +7 -0
@@ -113,6 +113,12 @@ extern struct group_info init_groups;# define CAP_INIT_BSET CAP_INIT_EFF_SET#endif +#ifdef CONFIG_REMEMBER_VFSMOUNT_PATH +#define INIT_VFSMOUNT_PATH .current_vfsmount_path = NULL, +#else +#define INIT_VFSMOUNT_PATH +#endif +/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -179,6 +185,7 @@ extern struct group_info init_groups;INIT_IDS \ INIT_TRACE_IRQFLAGS \INIT_LOCKDEP \ + INIT_VFSMOUNT_PATH \ }
include/linux/sched.h +3 -0
@@ -1301,6 +1301,9 @@ struct task_struct {int latency_record_count;struct latency_record latency_record[LT_SAVECOUNT ];#endif +#ifdef CONFIG_REMEMBER_VFSMOUNT_PATH +const char *current_vfsmount_path; +#endif };/*
kernel/fork.c +8 -0
@@ -1051,6 +1051,14 @@ static struct task_struct *copy_process( p->blocked_on =NULL ;/* not blocked yet */ #endif +#ifdef CONFIG_REMEMBER_VFSMOUNT_PATH +/* +* It seems to me that this function is called between mnt_want_write() +* and mnt_drop_write(). I don't know why. +*/ + p->current_vfsmount_path =NULL ; +#endif +/* Perform scheduler related setup. Assign this task to a CPU. */ sched_fork (p, clone_flags);
Re: (repost) Confirmation of methods for calculating requested pathname.
Quoted 25 lines · Kentaro Takeda
Al, could you answer the following question?
The current Linux kernel is not designed to pass vfsmount parameter that is crucial for pathname-based security including AppArmor and TOMOYO Linux, to LSM. Though both projects have been proposing patches to calculate pathname, none of them have been accepted as you know.
To find the reason for NACK, we examined past proposals and the threads. And we came to understand that you oppose accessing vfsmount inside vfs helper functions. Is our understanding correct?
If our understanding is correct, we would like to propose a new method that does not require modifications to vfs helper functions. Attached patch is a trial of this method.
vfs helper functions are surrounded by
mnt_want_write()andmnt_drop_write()pairs which receive "struct vfsmount" parameter since 2.6.26. So, by remembering the absolute pathname of "struct vfsmount" of the moment, LSM module can calculate an absolute pathname of the given "struct dentry" parameter inside vfs_* functions, without passing "struct vfsmount" parameter to vfs_* functions.
Quoted 3 lines
This approach doesn't access vfsmount inside vfs helper functions, and modification of existing kernel is only in
task_structand mnt_want/drop_write().
I don't know what Al Viro will say, but this is incredibly ugly. Even more ugly than previous patches.
Re: (repost) Confirmation of methods for calculating requested pathname.
In reply to Kentaro TakedaQuoted 12 lines · Kentaro Takeda
If our understanding is correct, we would like to propose a new method that does not require modifications to vfs helper functions. Attached patch is a trial of this method.
vfs helper functions are surrounded by
mnt_want_write()andmnt_drop_write()pairs which receive "struct vfsmount" parameter since 2.6.26. So, by remembering the absolute pathname of "struct vfsmount" of the moment, LSM module can calculate an absolute pathname of the given "struct dentry" parameter inside vfs_* functions, without passing "struct vfsmount" parameter to vfs_* functions.
Quoted 3 lines
This approach doesn't access vfsmount inside vfs helper functions, and modification of existing kernel is only in
task_structand mnt_want/drop_write().
This is exactly the same as passing vfsmount through vfs helper functions, except the parameter is "hidden" inside struct task.
Although this seems to violate the idea that the vfs helper call chains (including functions they call) aren't affected by the mount point, to be frank they are affected by the mount point _already_ - by virtue of mnt_get_write()/mnt_drop_write() existing.
Ironically, the _current_ way that vfs helper call chains are affected by mount point is for security: read-only mount points are basic security.
So I don't understand the objection to using path mount point in security decisions, given that it already is to some extent.
This patch seems ugly at first because of hidden parameters in struct task. On the other hand, mnt_get_write() already does a similar thing (and the implementation is uglier imho, though clever), and it is accepted.
-- Jamie
Re: (repost) Confirmation of methods for calculating requested pathname.
In reply to Alexey DobriyanQuoted 2 lines
I don't know what Al Viro will say, but this is incredibly ugly. Even more ugly than previous patches.
Which approach did you mean by the "previous patches"?
* introduce security_path_* (new LSM hooks)
http://marc.info/?l=linux-security-module&m=120962139014606&w=2
* pass struct path * to vfs helper functions and existing LSM hooks
http://lkml.org/lkml/2008/5/29/217
Regards,
Serge E. Hallyn
maintainerRe: (repost) Confirmation of methods for calculating requested pathname.
In reply to Kentaro TakedaQuoted 13 lines · Kentaro Takeda
Al, could you answer the following question?
The current Linux kernel is not designed to pass vfsmount parameter that is crucial for pathname-based security including AppArmor and TOMOYO Linux, to LSM. Though both projects have been proposing patches to calculate pathname, none of them have been accepted as you know.
To find the reason for NACK, we examined past proposals and the threads. And we came to understand that you oppose accessing vfsmount inside vfs helper functions. Is our understanding correct?
Quoted 6 lines
If our understanding is correct, we would like to propose a new method that does not require modifications to vfs helper functions. Attached patch is a trial of this method.
vfs helper functions are surrounded by
mnt_want_write()andmnt_drop_write()pairs which receive "struct vfsmount" parameter
I thought Al and others (Stephen?) had made it clear that the thing to do was add new lsm hooks there. So whereas inode_permission takes only an inode and ends up calling security_inode_permission, you would add a security_path_permission() or somesuch before or after the call to inode_permission(), where as you've noted the path is available. You're *close* to doing the right thing by having a helper who is called at the right place catch the vfsmount, but you refuse to send a patch doing exactly what has been suggested.
-serge
Re: (repost) Confirmation of methods for calculating requested pathname.
Hello.
Quoted 2 lines · Serge E. Hallyn
I thought Al and others (Stephen?) had made it clear that the thing to do was add new lsm hooks there.
Thank you for a hint.
I have a question to Al Viro: Is it acceptable for you to introduce new LSM hooks (i.e. security_path_*()) where struct vfsmount is available? If it is acceptable, I'd like to start from the following patch.
Regards.
-----
Subject: Introduce new LSM hooks.
This patch allows LSM to check permission using "struct vfsmount" without passing "struct vfsmount" to VFS helper functions.
--- fs/namei.c | 37 ++++++++++++ fs/open.c | 5 + include/linux/security.h | 135 +++++++++++++++++++++++++++++++++++++++++++++++ net/unix/af_unix.c | 4 + security/capability.c | 53 ++++++++++++++++++ security/security.c | 63 +++++++++++++++++++++ 6 files changed, 297 insertions(+)
fs/namei.c +37 -0
@@ -1585,6 +1585,10 @@ int may_open(struct nameidata *nd, int a* Refuse to truncate files with mandatory locks held on them. */ error =locks_verify_locked (inode); +if (!error) + error =security_path_truncate (&nd->path,0 , +ATTR_MTIME |ATTR_CTIME |ATTR_OPEN , +NULL );if (!error) {DQUOT_INIT (inode);
@@ -1615,7 +1619,11 @@ static int __open_namei_create(struct naif (!IS_POSIXACL (dir->d_inode)) mode &= ~current->fs->umask; + error =security_path_mknod (&nd->path, path->dentry, mode,0 ); +if (error) + goto out_unlock; error =vfs_create (dir->d_inode, path->dentry, mode, nd); +out_unlock:mutex_unlock (&dir->d_inode->i_mutex);dput (nd->path.dentry); nd->path.dentry = path->dentry;
@@ -2018,6 +2026,9 @@ asmlinkage long sys_mknodat(int dfd, con error =mnt_want_write (nd.path.mnt);if (error) goto out_dput; + error =security_path_mknod (&nd.path, dentry, mode, dev); +if (error) + goto out_drop_write;switch (mode &S_IFMT ) {case 0 :case S_IFREG : error =vfs_create (nd.path.dentry->d_inode,dentry,mode,&nd);
@@ -2030,6 +2041,7 @@ asmlinkage long sys_mknodat(int dfd, con error =vfs_mknod (nd.path.dentry->d_inode,dentry,mode,0 );break ; } +out_drop_write:mnt_drop_write (nd.path.mnt); out_dput:dput (dentry);
@@ -2089,7 +2101,11 @@ asmlinkage long sys_mkdirat(int dfd, con error =mnt_want_write (nd.path.mnt);if (error) goto out_dput; + error =security_path_mkdir (&nd.path, dentry, mode); +if (error) + goto out_drop_write; error =vfs_mkdir (nd.path.dentry->d_inode, dentry, mode); +out_drop_write:mnt_drop_write (nd.path.mnt); out_dput:dput (dentry);
@@ -2196,7 +2212,11 @@ static long do_rmdir(int dfd, const char error =mnt_want_write (nd.path.mnt);if (error) goto exit3; + error =security_path_rmdir (&nd.path, dentry); +if (error) + goto exit4; error =vfs_rmdir (nd.path.dentry->d_inode, dentry); +exit4:mnt_drop_write (nd.path.mnt); exit3:dput (dentry);
@@ -2278,7 +2298,11 @@ static long do_unlinkat(int dfd, const c error =mnt_want_write (nd.path.mnt);if (error) goto exit2; + error =security_path_unlink (&nd.path, dentry); +if (error) + goto exit3; error =vfs_unlink (nd.path.dentry->d_inode, dentry); +exit3:mnt_drop_write (nd.path.mnt); exit2:dput (dentry);
@@ -2359,7 +2383,11 @@ asmlinkage long sys_symlinkat(const char error =mnt_want_write (nd.path.mnt);if (error) goto out_dput; + error =security_path_symlink (&nd.path, dentry, from); +if (error) + goto out_drop_write; error =vfs_symlink (nd.path.dentry->d_inode, dentry, from); +out_drop_write:mnt_drop_write (nd.path.mnt); out_dput:dput (dentry);
@@ -2456,7 +2484,11 @@ asmlinkage long sys_linkat(int olddfd, c error =mnt_want_write (nd.path.mnt);if (error) goto out_dput; + error =security_path_link (old_path.dentry, &nd.path, new_dentry); +if (error) + goto out_drop_write; error =vfs_link (old_path.dentry, nd.path.dentry->d_inode, new_dentry); +out_drop_write:mnt_drop_write (nd.path.mnt); out_dput:dput (new_dentry);
@@ -2688,8 +2720,13 @@ asmlinkage long sys_renameat(int olddfd, error =mnt_want_write (oldnd.path.mnt);if (error) goto exit5; + error =security_path_rename (&oldnd.path, old_dentry, + &newnd.path, new_dentry); +if (error) + goto exit6; error =vfs_rename (old_dir->d_inode, old_dentry, new_dir->d_inode, new_dentry); +exit6:mnt_drop_write (oldnd.path.mnt); exit5:dput (new_dentry);
fs/open.c +5 -0
@@ -272,6 +272,8 @@ static long do_sys_truncate(const char _ goto put_write_and_out; error =locks_verify_truncate (inode,NULL , length); +if (!error) + error =security_path_truncate (&path, length,0 ,NULL );if (!error) {DQUOT_INIT (inode); error =do_truncate (path.dentry, length,0 ,NULL );
@@ -329,6 +331,9 @@ static long do_sys_ftruncate(unsigned in error =locks_verify_truncate (inode, file, length);if (!error) + error =security_path_truncate (&file->f_path, length, +ATTR_MTIME |ATTR_CTIME , file); +if (!error) error =do_truncate (dentry, length,ATTR_MTIME |ATTR_CTIME , file); out_putf:fput (file);
include/linux/security.h +135 -0
199 lines not on this page · raw message
net/unix/af_unix.c +4 -0
@@ -827,7 +827,11 @@ static int unix_bind(struct socket *sock err =mnt_want_write (nd.path.mnt);if (err) goto out_mknod_dput; + err =security_path_mknod (&nd.path, dentry, mode,0 ); +if (err) + goto out_mknod_drop_write; err =vfs_mknod (nd.path.dentry->d_inode, dentry, mode,0 ); +out_mknod_drop_write:mnt_drop_write (nd.path.mnt);if (err) goto out_mknod_dput;
security/capability.c +53 -0
65 lines not on this page · raw message
security/security.c +63 -0
69 lines not on this page · raw message
Re: (repost) Confirmation of methods for calculating requested pathname.
In reply to Serge E. HallynQuoted 21 lines · Serge E. Hallyn
Quoted 13 lines · Kentaro Takeda
Al, could you answer the following question?
The current Linux kernel is not designed to pass vfsmount parameter that is crucial for pathname-based security including AppArmor and TOMOYO Linux, to LSM. Though both projects have been proposing patches to calculate pathname, none of them have been accepted as you know.
To find the reason for NACK, we examined past proposals and the threads. And we came to understand that you oppose accessing vfsmount inside vfs helper functions. Is our understanding correct?
Quoted 6 lines
If our understanding is correct, we would like to propose a new method that does not require modifications to vfs helper functions. Attached patch is a trial of this method.
vfs helper functions are surrounded by
mnt_want_write()andmnt_drop_write()pairs which receive "struct vfsmount" parameter
Quoted 8 lines
I thought Al and others (Stephen?) had made it clear that the thing to do was add new lsm hooks there. So whereas
inode_permissiontakes only an inode and ends up callingsecurity_inode_permission, you would add asecurity_path_permission()or somesuch before or after the call toinode_permission(), where as you've noted the path is available. You're *close* to doing the right thing by having a helper who is called at the right place catch the vfsmount, but you refuse to send a patch doing exactly what has been suggested.
No, that idea seemingly died because both Al and Miklos thought it was wrong to add new security hooks to the same code path (vs. moving the existing ones to the callers), but I was opposed to moving the existing hooks as they are presently exactly where SELinux needs them, and moving them to the callers raises concerns both with ensuring invocation on all code paths (possible, but an ongoing maintenance concern) and with performing DAC checks first where possible (which I think is also a concern for TOMOYO et al). Miklos' vfs path API showed more promise but was rejected.
Signature · 2 lines
Stephen Smalley National Security Agency
Re: (repost) Confirmation of methods for calculating requested pathname.
Quoted 3 lines · Stephen Smalley
No, that idea seemingly died because both Al and Miklos thought it was wrong to add new security hooks to the same code path (vs. moving the existing ones to the callers),
I do think that duplicating hooks is the wrong approach, but it does have the minimal impact of all the solutions, and the duplication can be consolidated later. So in the end this might be the easiest way forward.
What Al is violently opposed to is removing the vfs_foo() API which separates the "VFS core", which doesn't know anything abount mounts, from the rest of the VFS.
But as Jamie pointed out, we've already sneaked in vfsmounts via the r/o bind mounts patches. I don't see why we would need to strictly separate the mount namespace handling from the VFS core.
Miklos