AppArmor security module overview
Subsystems (20)
cover AppArmor security module overview
This post contains patches to include the AppArmor application security framework, with request for inclusion into -mm for wider testing.
These patches are currently against lkml but we will gladly rebase them against -mm so that they will apply cleanly.
Any comments and feedback to improve implementation are appreciated.
A second post dealing with the issue of passing NULL nameidata, will be posted to lkml for discussion.
Changes since previous post:
- remove custom pathname mangling
- rework apparmor auditing to cleanup message formating and better use audit framework
- change permission consistency checks from runtime to once at policy load
- add change_profile feature and cleanup change_hat to use change_profile
The patch series consists of five areas:
(1) Pass struct vfsmount through to LSM hooks.
(2) Fixes and improvements to __d_path():
(a) make it unambiguous and exclude unreachable paths from /proc/mounts,
(b) make its result consistent in the face of remounts,
(c) introduce d_namespace_path(), a variant of d_path that goes up to the namespace root instead of the chroot.
(d) the behavior of d_path() and getcwd() remain unchanged, and there is no hidding of unreachable paths in /proc/mounts. The patches addressing these have been seperated from the AppArmor submission and will be introduced at a later date.
Part (a) has been in the -mm tree for a while; this series includes an updated copy of the -mm patch. Parts (b) and (c) shouldn't be too controversial.
(3) Be able to distinguish file descriptor access from access by name in LSM hooks.
Applications expect different behavior from file descriptor accesses and accesses by name in some cases. We need to pass this information down the LSM hooks to allow AppArmor to tell which is which.
(4) Convert the selinux sysctl pathname computation code into a standalone function.
(5) The AppArmor LSM itself.
(See below.)
A tarball of the kernel patches, base user-space utilities, example profiles, and technical documentation (including a walk-through) are available at:
http://forgeftp.novell.com//apparmor/LKML_Submission-June-07/
Explaining the AppArmor design in detail would take by far too much space here, so let me refer you to the technical documentation for that. Included is a low-level walk-through of the system and basic tools, and some examples. The manual pages included in the apparmor-parser package are worth a read as well.
PATCH 1/44 Pass struct vfsmount to the inode_create LSM hook
This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 2 +- include/linux/security.h | 9 ++++++--- security/dummy.c | 2 +- security/selinux/hooks.c | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-)
fs/namei.c +1 -1
@@ -1521,7 +1521,7 @@ int vfs_create(struct inode *dir, structreturn -EACCES ;/* shouldn't it be ENOSYS? */ mode &=S_IALLUGO ; mode |=S_IFREG ; - error =security_inode_create (dir, dentry, mode); + error =security_inode_create (dir, dentry, nd ? nd->mnt :NULL , mode);if (error)return error;DQUOT_INIT (dir);
include/linux/security.h +6 -3
@@ -283,6 +283,7 @@ struct request_sock;* Check permission to create a regular file. * @dir contains inode structure of the parent of the new file. * @dentry contains the dentry structure for the file to be created. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * @mode contains the file mode of the file to be created. * Return 0 if permission is granted. * @inode_link:
@@ -1204,8 +1205,8 @@ struct security_operations {void (*inode_free_security) (struct inode *inode);int (*inode_init_security) (struct inode *inode,struct inode *dir,char **name,void **value,size_t *len); -int (*inode_create) (struct inode *dir, -struct dentry *dentry,int mode); +int (*inode_create) (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode);int (*inode_link) (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry);int (*inode_unlink) (struct inode *dir,struct dentry *dentry);
@@ -1611,11 +1612,12 @@ static inline int security_inode_init_sestatic inline int security_inode_create (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode) {if (unlikely (IS_PRIVATE (dir)))return 0 ; -return security_ops->inode_create (dir, dentry, mode); +return security_ops->inode_create (dir, dentry, mnt, mode); } static inline int security_inode_link (struct dentry *old_dentry,
@@ -2338,6 +2340,7 @@ static inline int security_inode_init_sestatic inline int security_inode_create (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode) {return 0 ;
security/dummy.c +1 -1
@@ -265,7 +265,7 @@ static int dummy_inode_init_security (st }static int dummy_inode_create (struct inode *inode,struct dentry *dentry, -int mask) +struct vfsmount *mnt,int mask) {return 0 ; }
security/selinux/hooks.c +2 -1
@@ -2176,7 +2176,8 @@ static int selinux_inode_init_security(sreturn 0 ; } -static int selinux_inode_create (struct inode *dir,struct dentry *dentry,int mask) +static int selinux_inode_create (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mask) {return may_create (dir, dentry,SECCLASS_FILE ); }
Re: [AppArmor 01/44] Pass struct vfsmount to the inode_create LSM hook
Quoted 1 line · On Tue, Jun 26, 2007 at 04:07:57PM -0700, [email protected] wrote:
This is needed for computing pathnames in the AppArmor LSM.
Please see the various per-mountpoint r/o thread that NACKed all the vfsmount additions and have the rationale for it.
Re: [AppArmor 01/44] Pass struct vfsmount to the inode_create LSM hook
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · On Tue, Jun 26, 2007 at 04:07:57PM -0700, [email protected] wrote:
This is needed for computing pathnames in the AppArmor LSM.
Please see the various per-mountpoint r/o thread that NACKed all the vfsmount additions and have the rationale for it.
The per-mountpoint flags can be checked at the vfs level instead of checking down in the filesystems. That's all pretty nice; it avoids a number of problems. (I think the latest patches of Dave Hansen are archived at
http://lwn.net/Articles/239630/.)
The lSM hooks are a rather different story: we cannot move LSM functionality into the vfs without breaking the LSM abstraction. LSMs already are not agnostic of vfsmount anymore right now. They are free to use the additional vfsmounts, or just ignore them.
So what are the specific issues you have with this?
Thanks,
Andreas
PATCH 2/44 Pass struct path down to remove_suid and children
In reply to [email protected]Required by a later patch that adds a struct vfsmount parameter to notify_change().
--- fs/ntfs/file.c | 2 +- fs/reiserfs/file.c | 2 +- fs/splice.c | 4 ++-- fs/xfs/linux-2.6/xfs_lrw.c | 2 +- include/linux/fs.h | 4 ++-- mm/filemap.c | 12 ++++++------ mm/filemap_xip.c | 2 +- mm/shmem.c | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-)
fs/ntfs/file.c +1 -1
@@ -2122,7 +2122,7 @@ static ssize_t ntfs_file_aio_write_noloc goto out;if (!count) goto out; - err =remove_suid (file->f_path.dentry); + err =remove_suid (&file->f_path);if (err) goto out;file_update_time (file);
fs/reiserfs/file.c +1 -1
@@ -1335,7 +1335,7 @@ static ssize_t reiserfs_file_write(strucif (count ==0 ) goto out; - res =remove_suid (file->f_path.dentry); + res =remove_suid (&file->f_path);if (res) goto out;
fs/splice.c +2 -2
@@ -807,7 +807,7 @@ generic_file_splice_write_nolock(structssize_t ret;int err; - err =remove_suid (out->f_path.dentry); + err =remove_suid (&out->f_path);if (unlikely (err))return err;
@@ -860,7 +860,7 @@ generic_file_splice_write(struct pipe_in err =should_remove_suid (out->f_path.dentry);if (unlikely (err)) {mutex_lock (&inode->i_mutex); - err =__remove_suid (out->f_path.dentry, err); + err =__remove_suid (&out->f_path, err);mutex_unlock (&inode->i_mutex);if (err)return err;
fs/xfs/linux-2.6/xfs_lrw.c +1 -1
@@ -798,7 +798,7 @@ start: !capable(CAP_FSETID)) { error =xfs_write_clear_setuid (xip);if (likely (!error)) - error = -remove_suid (file->f_path.dentry); + error = -remove_suid (&file->f_path);if (unlikely (error)) { goto out_unlock_internal; }
include/linux/fs.h +2 -2
@@ -1725,9 +1725,9 @@ extern void __iget(struct inode * inode)extern void clear_inode (struct inode *);extern void destroy_inode (struct inode *);extern struct inode *new_inode (struct super_block *); -extern int __remove_suid (struct dentry *,int ); +extern int __remove_suid (struct path *,int );extern int should_remove_suid (struct dentry *); -extern int remove_suid (struct dentry *); +extern int remove_suid (struct path *);extern void __insert_inode_hash (struct inode *,unsigned long hashval);extern void remove_inode_hash (struct inode *);
mm/filemap.c +6 -6
@@ -1906,20 +1906,20 @@ int should_remove_suid(struct dentry *de }EXPORT_SYMBOL (should_remove_suid); -int __remove_suid (struct dentry *dentry,int kill) +int __remove_suid (struct path *path,int kill) {struct iattr newattrs; newattrs.ia_valid =ATTR_FORCE | kill; -return notify_change (dentry, &newattrs); +return notify_change (path->dentry, &newattrs); } -int remove_suid (struct dentry *dentry) +int remove_suid (struct path *path) { -int kill =should_remove_suid (dentry); +int kill =should_remove_suid (path->dentry);if (unlikely (kill)) -return __remove_suid (dentry, kill); +return __remove_suid (path, kill);return 0 ; }
@@ -2270,7 +2270,7 @@ __generic_file_aio_write_nolock(struct kif (count ==0 ) goto out; - err =remove_suid (file->f_path.dentry); + err =remove_suid (&file->f_path);if (err) goto out;
mm/filemap_xip.c +1 -1
@@ -406,7 +406,7 @@ xip_file_write(struct file *filp, constif (count ==0 ) goto out_backing; - ret =remove_suid (filp->f_path.dentry); + ret =remove_suid (&filp->f_path);if (ret) goto out_backing;
mm/shmem.c +1 -1
@@ -1518,7 +1518,7 @@ shmem_file_write(struct file *file, consif (err || !count) goto out; - err =remove_suid (file->f_path.dentry); + err =remove_suid (&file->f_path);if (err) goto out;
PATCH 3/44 Add a vfsmount parameter to notify_change()
In reply to [email protected]The vfsmount parameter must be set appropriately for files visibile outside the kernel. Files that are only used in a filesystem (e.g., reiserfs xattr files) will have a NULL vfsmount.
--- fs/attr.c | 3 ++- fs/ecryptfs/inode.c | 4 +++- fs/exec.c | 3 ++- fs/fat/file.c | 2 +- fs/hpfs/namei.c | 2 +- fs/namei.c | 3 ++- fs/nfsd/vfs.c | 8 ++++---- fs/open.c | 28 +++++++++++++++------------- fs/reiserfs/xattr.c | 6 +++--- fs/sysfs/file.c | 2 +- fs/utimes.c | 11 ++++++----- include/linux/fs.h | 6 +++--- mm/filemap.c | 2 +- mm/tiny-shmem.c | 2 +- 14 files changed, 45 insertions(+), 37 deletions(-)
fs/attr.c +2 -1
@@ -100,7 +100,8 @@ int inode_setattr(struct inode * inode, }EXPORT_SYMBOL (inode_setattr); -int notify_change (struct dentry * dentry,struct iattr * attr) +int notify_change (struct dentry *dentry,struct vfsmount *mnt, +struct iattr *attr) {struct inode *inode = dentry->d_inode;mode_t mode;
fs/ecryptfs/inode.c +3 -1
@@ -870,12 +870,14 @@ static int ecryptfs_setattr(struct dentr {int rc =0 ;struct dentry *lower_dentry; +struct vfsmount *lower_mnt;struct inode *inode;struct inode *lower_inode;struct ecryptfs_crypt_stat *crypt_stat; crypt_stat = &ecryptfs_inode_to_private (dentry->d_inode)->crypt_stat; lower_dentry =ecryptfs_dentry_to_lower (dentry); + lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry); inode = dentry->d_inode; lower_inode =ecryptfs_inode_to_lower (inode);if (ia->ia_valid &ATTR_SIZE ) {
@@ -890,7 +892,7 @@ static int ecryptfs_setattr(struct dentrif (rc <0 ) goto out; } - rc =notify_change (lower_dentry, ia); + rc =notify_change (lower_dentry, lower_mnt, ia); out:fsstack_copy_attr_all (inode, lower_inode,NULL );return rc;
fs/exec.c +2 -1
@@ -1565,7 +1565,8 @@ int do_coredump(long signr, int exit_cod goto close_fail;if (!file->f_op->write) goto close_fail; -if (!ispipe &&do_truncate (file->f_path.dentry,0 ,0 , file) !=0 ) +if (!ispipe && +do_truncate (file->f_path.dentry, file->f_path.mnt,0 ,0 , file) !=0 ) goto close_fail; retval = binfmt->core_dump (signr, regs, file);
fs/fat/file.c +1 -1
@@ -92,7 +92,7 @@ int fat_generic_ioctl(struct inode *inod }/* This MUST be done before doing anything irreversible... */ - err =notify_change (filp->f_path.dentry, &ia); + err =notify_change (filp->f_path.dentry, filp->f_path.mnt, &ia);if (err) goto up;
fs/hpfs/namei.c +1 -1
@@ -426,7 +426,7 @@ again:/*printk("HPFS: truncating file before delete.\n");*/ newattrs.ia_size =0 ; newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ; - err =notify_change (dentry, &newattrs); + err =notify_change (dentry,NULL , &newattrs);put_write_access (inode);if (!err) goto again;
fs/namei.c +2 -1
@@ -1598,7 +1598,8 @@ int may_open(struct nameidata *nd, int aif (!error) {DQUOT_INIT (inode); - error =do_truncate (dentry,0 ,ATTR_MTIME |ATTR_CTIME ,NULL ); + error =do_truncate (dentry, nd->mnt,0 , +ATTR_MTIME |ATTR_CTIME ,NULL ); }put_write_access (inode);if (error)
fs/nfsd/vfs.c +4 -4
@@ -358,7 +358,7 @@ nfsd_setattr(struct svc_rqst *rqstp, str err = nfserr_notsync;if (!check_guard || guardtime == inode->i_ctime.tv_sec) {fh_lock (fhp); - host_err =notify_change (dentry, iap); + host_err =notify_change (dentry, fhp->fh_export->ex_mnt, iap); err =nfserrno (host_err);fh_unlock (fhp); }
@@ -893,13 +893,13 @@ out:return err; } -static void kill_suid (struct dentry *dentry) +static void kill_suid (struct dentry *dentry,struct vfsmount *mnt) {struct iattr ia; ia.ia_valid =ATTR_KILL_SUID |ATTR_KILL_SGID ;mutex_lock (&dentry->d_inode->i_mutex); -notify_change (dentry, &ia); +notify_change (dentry, mnt, &ia);mutex_unlock (&dentry->d_inode->i_mutex); }
@@ -958,7 +958,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s/* clear setuid/setgid flag after write */ if (host_err >=0 && (inode->i_mode & (S_ISUID |S_ISGID ))) -kill_suid (dentry); +kill_suid (dentry, exp->ex_mnt);if (host_err >=0 && stable) {static ino_t last_ino;
fs/open.c +15 -13
@@ -193,8 +193,8 @@ out:return error; } -int do_truncate (struct dentry *dentry,loff_t length,unsigned int time_attrs, -struct file *filp) +int do_truncate (struct dentry *dentry,struct vfsmount *mnt,loff_t length, +unsigned int time_attrs,struct file *filp) {int err;struct iattr newattrs;
@@ -214,7 +214,7 @@ int do_truncate(struct dentry *dentry, l newattrs.ia_valid |=should_remove_suid (dentry);mutex_lock (&dentry->d_inode->i_mutex); - err =notify_change (dentry, &newattrs); + err =notify_change (dentry, mnt, &newattrs);mutex_unlock (&dentry->d_inode->i_mutex);return err; }
@@ -269,7 +269,7 @@ static long do_sys_truncate(const char _ error =locks_verify_truncate (inode,NULL , length);if (!error) {DQUOT_INIT (inode); - error =do_truncate (nd.dentry, length,0 ,NULL ); + error =do_truncate (nd.dentry, nd.mnt, length,0 ,NULL ); }put_write_access (inode);
@@ -321,7 +321,8 @@ static long do_sys_ftruncate(unsigned in error =locks_verify_truncate (inode, file, length);if (!error) - error =do_truncate (dentry, length,ATTR_MTIME |ATTR_CTIME , file); + error =do_truncate (dentry, file->f_path.mnt, length, +ATTR_MTIME |ATTR_CTIME , file); out_putf:fput (file); out:
@@ -521,7 +522,7 @@ asmlinkage long sys_fchmod(unsigned int mode = inode->i_mode; newattrs.ia_mode = (mode &S_IALLUGO ) | (inode->i_mode & ~S_IALLUGO ); newattrs.ia_valid =ATTR_MODE |ATTR_CTIME ; - err =notify_change (dentry, &newattrs); + err =notify_change (dentry, file->f_path.mnt, &newattrs);mutex_unlock (&inode->i_mutex); out_putf:
@@ -556,7 +557,7 @@ asmlinkage long sys_fchmodat(int dfd, co mode = inode->i_mode; newattrs.ia_mode = (mode &S_IALLUGO ) | (inode->i_mode & ~S_IALLUGO ); newattrs.ia_valid =ATTR_MODE |ATTR_CTIME ; - error =notify_change (nd.dentry, &newattrs); + error =notify_change (nd.dentry, nd.mnt, &newattrs);mutex_unlock (&inode->i_mutex); dput_and_out:
@@ -570,7 +571,8 @@ asmlinkage long sys_chmod(const char __ureturn sys_fchmodat (AT_FDCWD , filename, mode); } -static int chown_common (struct dentry * dentry,uid_t user,gid_t group) +static int chown_common (struct dentry * dentry,struct vfsmount *mnt, +uid_t user,gid_t group) {struct inode * inode;int error;
@@ -599,7 +601,7 @@ static int chown_common(struct dentry *if (!S_ISDIR (inode->i_mode)) newattrs.ia_valid |=ATTR_KILL_SUID |ATTR_KILL_SGID ;mutex_lock (&inode->i_mutex); - error =notify_change (dentry, &newattrs); + error =notify_change (dentry, mnt, &newattrs);mutex_unlock (&inode->i_mutex); out:return error;
@@ -613,7 +615,7 @@ asmlinkage long sys_chown(const char __u error =user_path_walk (filename, &nd);if (error) goto out; - error =chown_common (nd.dentry, user, group); + error =chown_common (nd.dentry, nd.mnt, user, group);path_release (&nd); out:return error;
@@ -633,7 +635,7 @@ asmlinkage long sys_fchownat(int dfd, co error =__user_walk_fd (dfd, filename, follow, &nd);if (error) goto out; - error =chown_common (nd.dentry, user, group); + error =chown_common (nd.dentry, nd.mnt, user, group);path_release (&nd); out:return error;
@@ -647,7 +649,7 @@ asmlinkage long sys_lchown(const char __ error =user_path_walk_link (filename, &nd);if (error) goto out; - error =chown_common (nd.dentry, user, group); + error =chown_common (nd.dentry, nd.mnt, user, group);path_release (&nd); out:return error;
@@ -666,7 +668,7 @@ asmlinkage long sys_fchown(unsigned int dentry = file->f_path.dentry;audit_inode (NULL , dentry->d_inode); - error =chown_common (dentry, user, group); + error =chown_common (dentry, file->f_path.mnt, user, group);fput (file); out:return error;
fs/reiserfs/xattr.c +3 -3
@@ -479,7 +479,7 @@ reiserfs_xattr_set(struct inode *inode, newattrs.ia_size = buffer_size; newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ;mutex_lock (&xinode->i_mutex); - err =notify_change (fp->f_path.dentry, &newattrs); + err =notify_change (fp->f_path.dentry,NULL , &newattrs);if (err) goto out_filp;
@@ -819,7 +819,7 @@ reiserfs_chown_xattrs_filler(void *buf, }if (!S_ISDIR (xafile->d_inode->i_mode)) - err =notify_change (xafile, attrs); + err =notify_change (xafile,NULL , attrs);dput (xafile);return err;
@@ -871,7 +871,7 @@ int reiserfs_chown_xattrs(struct inode * goto out_dir; } - err =notify_change (dir, attrs); + err =notify_change (dir,NULL , attrs);unlock_kernel (); out_dir:
fs/sysfs/file.c +1 -1
@@ -554,7 +554,7 @@ int sysfs_chmod_file(struct kobject *kob newattrs.ia_mode = (mode &S_IALLUGO ) | (inode->i_mode & ~S_IALLUGO ); newattrs.ia_valid =ATTR_MODE |ATTR_CTIME ; - res =notify_change (victim, &newattrs); + res =notify_change (victim,NULL , &newattrs);mutex_unlock (&inode->i_mutex); }dput (victim);
fs/utimes.c +6 -5
@@ -46,7 +46,7 @@ long do_utimes(int dfd, char __user *fil {int error;struct nameidata nd; -struct dentry *dentry; +struct path path;struct inode *inode;struct iattr newattrs;struct file *f =NULL ;
@@ -64,16 +64,17 @@ long do_utimes(int dfd, char __user *fil f =fget (dfd);if (!f) goto out; - dentry = f->f_path.dentry; + path = f->f_path; }else { error =__user_walk_fd (dfd, filename, (flags &AT_SYMLINK_NOFOLLOW ) ?0 :LOOKUP_FOLLOW , &nd);if (error) goto out; - dentry = nd.dentry; + path.dentry = nd.dentry; + path.mnt = nd.mnt; } - inode = dentry->d_inode; + inode = path.dentry->d_inode; error = -EROFS ;if (IS_RDONLY (inode))
@@ -111,7 +112,7 @@ long do_utimes(int dfd, char __user *fil goto dput_and_out; }mutex_lock (&inode->i_mutex); - error =notify_change (dentry, &newattrs); + error =notify_change (path.dentry, path.mnt, &newattrs);mutex_unlock (&inode->i_mutex); dput_and_out:if (f)
include/linux/fs.h +3 -3
@@ -1498,8 +1498,8 @@ static inline int break_lease(struct ino/* fs/open.c */ -extern int do_truncate (struct dentry *,loff_t start,unsigned int time_attrs, -struct file *filp); +extern int do_truncate (struct dentry *,struct vfsmount *,loff_t start, +unsigned int time_attrs,struct file *filp);extern long do_sys_open (int fdf,const char __user *filename,int flags,int mode);extern struct file *filp_open (const char *,int ,int );
@@ -1652,7 +1652,7 @@ extern int do_remount_sb(struct super_bl#ifdef CONFIG_BLOCK extern sector_t bmap (struct inode *,sector_t );#endif -extern int notify_change (struct dentry *,struct iattr *); +extern int notify_change (struct dentry *,struct vfsmount *,struct iattr *);extern int permission (struct inode *,int ,struct nameidata *);extern int generic_permission (struct inode *,int ,int (*check_acl)(struct inode *,int ));
mm/filemap.c +1 -1
@@ -1911,7 +1911,7 @@ int __remove_suid(struct path *path, intstruct iattr newattrs; newattrs.ia_valid =ATTR_FORCE | kill; -return notify_change (path->dentry, &newattrs); +return notify_change (path->dentry, path->mnt, &newattrs); }int remove_suid (struct path *path)
mm/tiny-shmem.c +1 -1
@@ -86,7 +86,7 @@ struct file *shmem_file_setup(char *name file->f_mode =FMODE_WRITE |FMODE_READ ;/* notify everyone as to the change of file size */ - error =do_truncate (dentry, size,0 , file); + error =do_truncate (dentry, file->f_path.mnt, size,0 , file);if (error <0 ) goto close_file;
PATCH 4/44 Pass struct vfsmount to the inode_setattr LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/attr.c | 4 ++-- include/linux/security.h | 8 ++++++-- security/dummy.c | 3 ++- security/selinux/hooks.c | 5 +++-- 4 files changed, 13 insertions(+), 7 deletions(-)
fs/attr.c +2 -2
@@ -144,13 +144,13 @@ int notify_change(struct dentry *dentry,down_write (&dentry->d_inode->i_alloc_sem);if (inode->i_op && inode->i_op->setattr) { - error =security_inode_setattr (dentry, attr); + error =security_inode_setattr (dentry, mnt, attr);if (!error) error = inode->i_op->setattr (dentry, attr); }else { error =inode_change_ok (inode, attr);if (!error) - error =security_inode_setattr (dentry, attr); + error =security_inode_setattr (dentry, mnt, attr);if (!error) {if ((ia_valid &ATTR_UID && attr->ia_uid != inode->i_uid) || (ia_valid &ATTR_GID && attr->ia_gid != inode->i_gid))
include/linux/security.h +6 -2
@@ -358,6 +358,7 @@ struct request_sock;* file attributes change (such as when a file is truncated, chown/chmod * operations, transferring disk quotas, etc). * @dentry contains the dentry structure for the file. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * @attr is the iattr structure containing the new file attributes. * Return 0 if permission is granted. * @inode_getattr:
@@ -1221,7 +1222,8 @@ struct security_operations {int (*inode_readlink) (struct dentry *dentry);int (*inode_follow_link) (struct dentry *dentry,struct nameidata *nd);int (*inode_permission) (struct inode *inode,int mask,struct nameidata *nd); -int (*inode_setattr) (struct dentry *dentry,struct iattr *attr); +int (*inode_setattr) (struct dentry *dentry,struct vfsmount *mnt, +struct iattr *attr);int (*inode_getattr) (struct vfsmount *mnt,struct dentry *dentry);void (*inode_delete) (struct inode *inode); int (*inode_setxattr) (struct dentry *dentry, char *name, void *value,
@@ -1708,11 +1710,12 @@ static inline int security_inode_permiss }static inline int security_inode_setattr (struct dentry *dentry, +struct vfsmount *mnt,struct iattr *attr) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_setattr (dentry, attr); +return security_ops->inode_setattr (dentry, mnt, attr); } static inline int security_inode_getattr (struct vfsmount *mnt,
@@ -2412,6 +2415,7 @@ static inline int security_inode_permiss }static inline int security_inode_setattr (struct dentry *dentry, +struct vfsmount *mnt,struct iattr *attr) {return 0 ;
security/dummy.c +2 -1
@@ -328,7 +328,8 @@ static int dummy_inode_permission (strucreturn 0 ; } -static int dummy_inode_setattr (struct dentry *dentry,struct iattr *iattr) +static int dummy_inode_setattr (struct dentry *dentry,struct vfsmount *mnt, +struct iattr *iattr) {return 0 ; }
security/selinux/hooks.c +3 -2
@@ -2267,11 +2267,12 @@ static int selinux_inode_permission(stru file_mask_to_av(inode->i_mode, mask), NULL); } -static int selinux_inode_setattr (struct dentry *dentry,struct iattr *iattr) +static int selinux_inode_setattr (struct dentry *dentry,struct vfsmount *mnt, +struct iattr *iattr) {int rc; - rc = secondary_ops->inode_setattr (dentry, iattr); + rc = secondary_ops->inode_setattr (dentry, mnt, iattr);if (rc)return rc;
PATCH 5/44 Add struct vfsmount parameter to vfs_mkdir()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/ecryptfs/inode.c | 5 ++++- fs/namei.c | 5 +++-- fs/nfsd/nfs4recover.c | 3 ++- fs/nfsd/vfs.c | 8 +++++--- include/linux/fs.h | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-)
fs/ecryptfs/inode.c +4 -1
@@ -509,11 +509,14 @@ static int ecryptfs_mkdir(struct inode * {int rc;struct dentry *lower_dentry; +struct vfsmount *lower_mnt;struct dentry *lower_dir_dentry; lower_dentry =ecryptfs_dentry_to_lower (dentry); + lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry); lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_mkdir (lower_dir_dentry->d_inode, lower_dentry, mode); + rc =vfs_mkdir (lower_dir_dentry->d_inode, lower_dentry, lower_mnt, + mode);if (rc || !lower_dentry->d_inode) goto out; rc =ecryptfs_interpose (lower_dentry, dentry, dir->i_sb,0 );
fs/namei.c +3 -2
@@ -1934,7 +1934,8 @@ asmlinkage long sys_mknod(const char __ureturn sys_mknodat (AT_FDCWD , filename, mode, dev); } -int vfs_mkdir (struct inode *dir,struct dentry *dentry,int mode) +int vfs_mkdir (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt, +int mode) {int error =may_create (dir, dentry,NULL );
@@ -1978,7 +1979,7 @@ asmlinkage long sys_mkdirat(int dfd, conif (!IS_POSIXACL (nd.dentry->d_inode)) mode &= ~current->fs->umask; - error =vfs_mkdir (nd.dentry->d_inode, dentry, mode); + error =vfs_mkdir (nd.dentry->d_inode, dentry, nd.mnt, mode);dput (dentry); out_unlock:mutex_unlock (&nd.dentry->d_inode->i_mutex);
fs/nfsd/nfs4recover.c +2 -1
@@ -156,7 +156,8 @@ nfsd4_create_clid_dir(struct nfs4_clientdprintk ("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n" ); goto out_put; } - status =vfs_mkdir (rec_dir.dentry->d_inode, dentry,S_IRWXU ); + status =vfs_mkdir (rec_dir.dentry->d_inode, dentry, rec_dir.mnt, +S_IRWXU ); out_put:dput (dentry); out_unlock:
fs/nfsd/vfs.c +5 -3
@@ -1115,6 +1115,7 @@ nfsd_create(struct svc_rqst *rqstp, stru int type, dev_t rdev, struct svc_fh *resfhp) { struct dentry *dentry, *dchild = NULL; +struct svc_export *exp;struct inode *dirp;__be32 err;int host_err;
@@ -1131,6 +1132,7 @@ nfsd_create(struct svc_rqst *rqstp, stru goto out; dentry = fhp->fh_dentry; + exp = fhp->fh_export; dirp = dentry->d_inode; err = nfserr_notdir;
@@ -1147,7 +1149,7 @@ nfsd_create(struct svc_rqst *rqstp, stru host_err =PTR_ERR (dchild);if (IS_ERR (dchild)) goto out_nfserr; - err =fh_compose (resfhp, fhp->fh_export, dchild, fhp); + err =fh_compose (resfhp, exp, dchild, fhp);if (err) goto out; }else {
@@ -1186,7 +1188,7 @@ nfsd_create(struct svc_rqst *rqstp, stru host_err =vfs_create (dirp, dchild, iap->ia_mode,NULL );break ;case S_IFDIR : - host_err =vfs_mkdir (dirp, dchild, iap->ia_mode); + host_err =vfs_mkdir (dirp, dchild, exp->ex_mnt, iap->ia_mode);break ;case S_IFCHR :case S_IFBLK :
@@ -1201,7 +1203,7 @@ nfsd_create(struct svc_rqst *rqstp, struif (host_err <0 ) goto out_nfserr; -if (EX_ISSYNC (fhp->fh_export)) { +if (EX_ISSYNC (exp)) { err =nfserrno (nfsd_sync_dir (dentry));write_inode_now (dchild->d_inode,1 ); }
include/linux/fs.h +1 -1
@@ -993,7 +993,7 @@ extern void unlock_super(struct super_bl*/ extern int vfs_permission (struct nameidata *,int );extern int vfs_create (struct inode *,struct dentry *,int ,struct nameidata *); -extern int vfs_mkdir (struct inode *,struct dentry *,int ); +extern int vfs_mkdir (struct inode *,struct dentry *,struct vfsmount *,int );extern int vfs_mknod (struct inode *,struct dentry *,int ,dev_t );extern int vfs_symlink (struct inode *,struct dentry *,const char *,int );extern int vfs_link (struct dentry *,struct inode *,struct dentry *);
PATCH 6/44 Pass struct vfsmount to the inode_mkdir LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 2 +- include/linux/security.h | 8 ++++++-- security/dummy.c | 2 +- security/selinux/hooks.c | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-)
fs/namei.c +1 -1
@@ -1946,7 +1946,7 @@ int vfs_mkdir(struct inode *dir, structreturn -EPERM ; mode &= (S_IRWXUGO |S_ISVTX ); - error =security_inode_mkdir (dir, dentry, mode); + error =security_inode_mkdir (dir, dentry, mnt, mode);if (error)return error;
include/linux/security.h +6 -2
@@ -308,6 +308,7 @@ struct request_sock;* associated with inode strcture @dir. * @dir containst the inode structure of parent of the directory to be created. * @dentry contains the dentry structure of new directory. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * @mode contains the mode of new directory. * Return 0 if permission is granted. * @inode_rmdir:
@@ -1213,7 +1214,8 @@ struct security_operations {int (*inode_unlink) (struct inode *dir,struct dentry *dentry);int (*inode_symlink) (struct inode *dir,struct dentry *dentry,const char *old_name); -int (*inode_mkdir) (struct inode *dir,struct dentry *dentry,int mode); +int (*inode_mkdir) (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode);int (*inode_rmdir) (struct inode *dir,struct dentry *dentry);int (*inode_mknod) (struct inode *dir,struct dentry *dentry,int mode,dev_t dev);
@@ -1650,11 +1652,12 @@ static inline int security_inode_symlinkstatic inline int security_inode_mkdir (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode) {if (unlikely (IS_PRIVATE (dir)))return 0 ; -return security_ops->inode_mkdir (dir, dentry, mode); +return security_ops->inode_mkdir (dir, dentry, mnt, mode); } static inline int security_inode_rmdir (struct inode *dir,
@@ -2371,6 +2374,7 @@ static inline int security_inode_symlinkstatic inline int security_inode_mkdir (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode) {return 0 ;
security/dummy.c +1 -1
@@ -288,7 +288,7 @@ static int dummy_inode_symlink (struct i }static int dummy_inode_mkdir (struct inode *inode,struct dentry *dentry, -int mask) +struct vfsmount *mnt,int mask) {return 0 ; }
security/selinux/hooks.c +2 -1
@@ -2207,7 +2207,8 @@ static int selinux_inode_symlink(structreturn may_create (dir, dentry,SECCLASS_LNK_FILE ); } -static int selinux_inode_mkdir (struct inode *dir,struct dentry *dentry,int mask) +static int selinux_inode_mkdir (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mask) {return may_create (dir, dentry,SECCLASS_DIR ); }
PATCH 7/44 Add a struct vfsmount parameter to vfs_mknod()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/ecryptfs/inode.c | 5 ++++- fs/namei.c | 10 ++++++---- fs/nfsd/vfs.c | 3 ++- include/linux/fs.h | 2 +- net/unix/af_unix.c | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-)
fs/ecryptfs/inode.c +4 -1
@@ -560,11 +560,14 @@ ecryptfs_mknod(struct inode *dir, struct {int rc;struct dentry *lower_dentry; +struct vfsmount *lower_mnt;struct dentry *lower_dir_dentry; lower_dentry =ecryptfs_dentry_to_lower (dentry); + lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry); lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_mknod (lower_dir_dentry->d_inode, lower_dentry, mode, dev); + rc =vfs_mknod (lower_dir_dentry->d_inode, lower_dentry, lower_mnt, mode, + dev);if (rc || !lower_dentry->d_inode) goto out; rc =ecryptfs_interpose (lower_dentry, dentry, dir->i_sb,0 );
fs/namei.c +6 -4
@@ -1855,7 +1855,8 @@ fail: }EXPORT_SYMBOL_GPL (lookup_create); -int vfs_mknod (struct inode *dir,struct dentry *dentry,int mode,dev_t dev) +int vfs_mknod (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt, +int mode,dev_t dev) {int error =may_create (dir, dentry,NULL );
@@ -1907,11 +1908,12 @@ asmlinkage long sys_mknodat(int dfd, con error =vfs_create (nd.dentry->d_inode,dentry,mode,&nd);break ;case S_IFCHR :case S_IFBLK : - error =vfs_mknod (nd.dentry->d_inode,dentry,mode, -new_decode_dev (dev)); + error =vfs_mknod (nd.dentry->d_inode, dentry, nd.mnt, + mode,new_decode_dev (dev));break ;case S_IFIFO :case S_IFSOCK : - error =vfs_mknod (nd.dentry->d_inode,dentry,mode,0 ); + error =vfs_mknod (nd.dentry->d_inode, dentry, nd.mnt, + mode,0 );break ;case S_IFDIR : error = -EPERM ;
fs/nfsd/vfs.c +2 -1
@@ -1194,7 +1194,8 @@ nfsd_create(struct svc_rqst *rqstp, strucase S_IFBLK :case S_IFIFO :case S_IFSOCK : - host_err =vfs_mknod (dirp, dchild, iap->ia_mode, rdev); + host_err =vfs_mknod (dirp, dchild, exp->ex_mnt, iap->ia_mode, + rdev);break ;default :printk ("nfsd: bad file type %o in nfsd_create\n" , type);
include/linux/fs.h +1 -1
@@ -994,7 +994,7 @@ extern void unlock_super(struct super_blextern int vfs_permission (struct nameidata *,int );extern int vfs_create (struct inode *,struct dentry *,int ,struct nameidata *);extern int vfs_mkdir (struct inode *,struct dentry *,struct vfsmount *,int ); -extern int vfs_mknod (struct inode *,struct dentry *,int ,dev_t ); +extern int vfs_mknod (struct inode *,struct dentry *,struct vfsmount *,int ,dev_t );extern int vfs_symlink (struct inode *,struct dentry *,const char *,int );extern int vfs_link (struct dentry *,struct inode *,struct dentry *);extern int vfs_rmdir (struct inode *,struct dentry *);
net/unix/af_unix.c +1 -1
@@ -807,7 +807,7 @@ static int unix_bind(struct socket *sock*/ mode =S_IFSOCK | (SOCK_INODE (sock)->i_mode & ~current->fs->umask); - err =vfs_mknod (nd.dentry->d_inode, dentry, mode,0 ); + err =vfs_mknod (nd.dentry->d_inode, dentry, nd.mnt, mode,0 );if (err) goto out_mknod_dput;mutex_unlock (&nd.dentry->d_inode->i_mutex);
PATCH 8/44 Pass struct vfsmount to the inode_mknod LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 2 +- include/linux/security.h | 7 +++++-- security/dummy.c | 2 +- security/selinux/hooks.c | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-)
fs/namei.c +1 -1
@@ -1869,7 +1869,7 @@ int vfs_mknod(struct inode *dir, structif (!dir->i_op || !dir->i_op->mknod)return -EPERM ; - error =security_inode_mknod (dir, dentry, mode, dev); + error =security_inode_mknod (dir, dentry, mnt, mode, dev);if (error)return error;
include/linux/security.h +5 -2
@@ -323,6 +323,7 @@ struct request_sock;* and not this hook. * @dir contains the inode structure of parent of the new file. * @dentry contains the dentry structure of the new file. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * @mode contains the mode of the new file. * @dev contains the device number. * Return 0 if permission is granted.
@@ -1218,7 +1219,7 @@ struct security_operations { struct vfsmount *mnt, int mode);int (*inode_rmdir) (struct inode *dir,struct dentry *dentry);int (*inode_mknod) (struct inode *dir,struct dentry *dentry, -int mode,dev_t dev); +struct vfsmount *mnt,int mode,dev_t dev);int (*inode_rename) (struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry);int (*inode_readlink) (struct dentry *dentry);
@@ -1670,11 +1671,12 @@ static inline int security_inode_rmdir (static inline int security_inode_mknod (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode,dev_t dev) {if (unlikely (IS_PRIVATE (dir)))return 0 ; -return security_ops->inode_mknod (dir, dentry, mode, dev); +return security_ops->inode_mknod (dir, dentry, mnt, mode, dev); } static inline int security_inode_rename (struct inode *old_dir,
@@ -2388,6 +2390,7 @@ static inline int security_inode_rmdir (static inline int security_inode_mknod (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode,dev_t dev) {return 0 ;
security/dummy.c +1 -1
@@ -299,7 +299,7 @@ static int dummy_inode_rmdir (struct ino }static int dummy_inode_mknod (struct inode *inode,struct dentry *dentry, -int mode,dev_t dev) +struct vfsmount *mnt,int mode,dev_t dev) {return 0 ; }
security/selinux/hooks.c +3 -2
@@ -2218,11 +2218,12 @@ static int selinux_inode_rmdir(struct inreturn may_link (dir, dentry,MAY_RMDIR ); } -static int selinux_inode_mknod (struct inode *dir,struct dentry *dentry,int mode,dev_t dev) +static int selinux_inode_mknod (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode,dev_t dev) {int rc; - rc = secondary_ops->inode_mknod (dir, dentry, mode, dev); + rc = secondary_ops->inode_mknod (dir, dentry, mnt, mode, dev);if (rc)return rc;
PATCH 9/44 Add a struct vfsmount parameter to vfs_symlink()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/ecryptfs/inode.c | 4 +++- fs/namei.c | 6 ++++-- fs/nfsd/vfs.c | 12 ++++++++---- include/linux/fs.h | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-)
fs/ecryptfs/inode.c +3 -1
@@ -470,6 +470,7 @@ static int ecryptfs_symlink(struct inode {int rc;struct dentry *lower_dentry; +struct vfsmount *lower_mnt;struct dentry *lower_dir_dentry;umode_t mode;char *encoded_symname;
@@ -478,6 +479,7 @@ static int ecryptfs_symlink(struct inode lower_dentry =ecryptfs_dentry_to_lower (dentry);dget (lower_dentry); + lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry); lower_dir_dentry =lock_parent (lower_dentry); mode =S_IALLUGO ; encoded_symlen = ecryptfs_encode_filename(crypt_stat, symname,
@@ -487,7 +489,7 @@ static int ecryptfs_symlink(struct inode rc = encoded_symlen; goto out_lock; } - rc =vfs_symlink (lower_dir_dentry->d_inode, lower_dentry, + rc =vfs_symlink (lower_dir_dentry->d_inode, lower_dentry, lower_mnt, encoded_symname, mode);kfree (encoded_symname);if (rc || !lower_dentry->d_inode)
fs/namei.c +4 -2
@@ -2203,7 +2203,8 @@ asmlinkage long sys_unlink(const char __return do_unlinkat (AT_FDCWD , pathname); } -int vfs_symlink (struct inode *dir,struct dentry *dentry,const char *oldname,int mode) +int vfs_symlink (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt, +const char *oldname,int mode) {int error =may_create (dir, dentry,NULL );
@@ -2249,7 +2250,8 @@ asmlinkage long sys_symlinkat(const charif (IS_ERR (dentry)) goto out_unlock; - error =vfs_symlink (nd.dentry->d_inode, dentry, from,S_IALLUGO ); + error =vfs_symlink (nd.dentry->d_inode, dentry, nd.mnt, from, +S_IALLUGO );dput (dentry); out_unlock:mutex_unlock (&nd.dentry->d_inode->i_mutex);
fs/nfsd/vfs.c +8 -4
@@ -1436,6 +1436,7 @@ nfsd_symlink(struct svc_rqst *rqstp, str struct iattr *iap) {struct dentry *dentry, *dnew; +struct svc_export *exp;__be32 err, cerr;int host_err;umode_t mode;
@@ -1462,6 +1463,7 @@ nfsd_symlink(struct svc_rqst *rqstp, strif (iap && (iap->ia_valid &ATTR_MODE )) mode = iap->ia_mode &S_IALLUGO ; + exp = fhp->fh_export;if (unlikely (path[plen] !=0 )) {char *path_alloced =kmalloc (plen+1 ,GFP_KERNEL );if (path_alloced ==NULL )
@@ -1469,20 +1471,22 @@ nfsd_symlink(struct svc_rqst *rqstp, strelse {strncpy (path_alloced, path, plen); path_alloced[plen] =0 ; - host_err =vfs_symlink (dentry->d_inode, dnew, path_alloced, mode); + host_err =vfs_symlink (dentry->d_inode, dnew, + exp->ex_mnt, path_alloced, mode);kfree (path_alloced); } }else - host_err =vfs_symlink (dentry->d_inode, dnew, path, mode); + host_err =vfs_symlink (dentry->d_inode, dnew, exp->ex_mnt, path, + mode);if (!host_err) { -if (EX_ISSYNC (fhp->fh_export)) +if (EX_ISSYNC (exp)) host_err =nfsd_sync_dir (dentry); } err =nfserrno (host_err);fh_unlock (fhp); - cerr =fh_compose (resfhp, fhp->fh_export, dnew, fhp); + cerr =fh_compose (resfhp, exp, dnew, fhp);dput (dnew);if (err==0 ) err = cerr; out:
include/linux/fs.h +1 -1
@@ -995,7 +995,7 @@ extern int vfs_permission(struct nameidaextern int vfs_create (struct inode *,struct dentry *,int ,struct nameidata *);extern int vfs_mkdir (struct inode *,struct dentry *,struct vfsmount *,int );extern int vfs_mknod (struct inode *,struct dentry *,struct vfsmount *,int ,dev_t ); -extern int vfs_symlink (struct inode *,struct dentry *,const char *,int ); +extern int vfs_symlink (struct inode *,struct dentry *,struct vfsmount *,const char *,int );extern int vfs_link (struct dentry *,struct inode *,struct dentry *);extern int vfs_rmdir (struct inode *,struct dentry *);extern int vfs_unlink (struct inode *,struct dentry *);
PATCH 10/44 Pass struct vfsmount to the inode_symlink LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 2 +- include/linux/security.h | 9 ++++++--- security/dummy.c | 2 +- security/selinux/hooks.c | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-)
fs/namei.c +1 -1
@@ -2214,7 +2214,7 @@ int vfs_symlink(struct inode *dir, strucif (!dir->i_op || !dir->i_op->symlink)return -EPERM ; - error =security_inode_symlink (dir, dentry, oldname); + error =security_inode_symlink (dir, dentry, mnt, oldname);if (error)return error;
include/linux/security.h +6 -3
@@ -301,6 +301,7 @@ struct request_sock;* Check the permission to create a symbolic link to a file. * @dir contains the inode structure of parent directory of the symbolic link. * @dentry contains the dentry structure of the symbolic link. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * @old_name contains the pathname of file. * Return 0 if permission is granted. * @inode_mkdir:
@@ -1213,8 +1214,8 @@ struct security_operations {int (*inode_link) (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry);int (*inode_unlink) (struct inode *dir,struct dentry *dentry); -int (*inode_symlink) (struct inode *dir, -struct dentry *dentry,const char *old_name); +int (*inode_symlink) (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,const char *old_name);int (*inode_mkdir) (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt,int mode);int (*inode_rmdir) (struct inode *dir,struct dentry *dentry);
@@ -1644,11 +1645,12 @@ static inline int security_inode_unlinkstatic inline int security_inode_symlink (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,const char *old_name) {if (unlikely (IS_PRIVATE (dir)))return 0 ; -return security_ops->inode_symlink (dir, dentry, old_name); +return security_ops->inode_symlink (dir, dentry, mnt, old_name); } static inline int security_inode_mkdir (struct inode *dir,
@@ -2369,6 +2371,7 @@ static inline int security_inode_unlinkstatic inline int security_inode_symlink (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,const char *old_name) {return 0 ;
security/dummy.c +1 -1
@@ -282,7 +282,7 @@ static int dummy_inode_unlink (struct in }static int dummy_inode_symlink (struct inode *inode,struct dentry *dentry, -const char *name) +struct vfsmount *mnt,const char *name) {return 0 ; }
security/selinux/hooks.c +2 -1
@@ -2202,7 +2202,8 @@ static int selinux_inode_unlink(struct ireturn may_link (dir, dentry,MAY_UNLINK ); } -static int selinux_inode_symlink (struct inode *dir,struct dentry *dentry,const char *name) +static int selinux_inode_symlink (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,const char *name) {return may_create (dir, dentry,SECCLASS_LNK_FILE ); }
PATCH 11/44 Pass struct vfsmount to the inode_readlink LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/stat.c | 2 +- include/linux/security.h | 11 +++++++---- security/dummy.c | 2 +- security/selinux/hooks.c | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-)
fs/stat.c +1 -1
@@ -306,7 +306,7 @@ asmlinkage long sys_readlinkat(int dfd, error = -EINVAL ;if (inode->i_op && inode->i_op->readlink) { - error =security_inode_readlink (nd.dentry); + error =security_inode_readlink (nd.dentry, nd.mnt);if (!error) {touch_atime (nd.mnt, nd.dentry); error = inode->i_op->readlink (nd.dentry, buf, bufsiz);
include/linux/security.h +7 -4
@@ -338,6 +338,7 @@ struct request_sock;* @inode_readlink: * Check the permission to read the symbolic link. * @dentry contains the dentry structure for the file link. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * Return 0 if permission is granted. * @inode_follow_link: * Check permission to follow a symbolic link when looking up a pathname.
@@ -1223,7 +1224,7 @@ struct security_operations { struct vfsmount *mnt, int mode, dev_t dev);int (*inode_rename) (struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry); -int (*inode_readlink) (struct dentry *dentry); +int (*inode_readlink) (struct dentry *dentry,struct vfsmount *mnt);int (*inode_follow_link) (struct dentry *dentry,struct nameidata *nd);int (*inode_permission) (struct inode *inode,int mask,struct nameidata *nd); int (*inode_setattr) (struct dentry *dentry, struct vfsmount *mnt,
@@ -1693,11 +1694,12 @@ static inline int security_inode_rename new_dir, new_dentry); } -static inline int security_inode_readlink (struct dentry *dentry) +static inline int security_inode_readlink (struct dentry *dentry, +struct vfsmount *mnt) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_readlink (dentry); +return security_ops->inode_readlink (dentry, mnt); } static inline int security_inode_follow_link (struct dentry *dentry,
@@ -2407,7 +2409,8 @@ static inline int security_inode_renamereturn 0 ; } -static inline int security_inode_readlink (struct dentry *dentry) +static inline int security_inode_readlink (struct dentry *dentry, +struct vfsmount *mnt) {return 0 ; }
security/dummy.c +1 -1
@@ -312,7 +312,7 @@ static int dummy_inode_rename (struct inreturn 0 ; } -static int dummy_inode_readlink (struct dentry *dentry) +static int dummy_inode_readlink (struct dentry *dentry,struct vfsmount *mnt) {return 0 ; }
security/selinux/hooks.c +1 -1
@@ -2237,7 +2237,7 @@ static int selinux_inode_rename(struct ireturn may_rename (old_inode, old_dentry, new_inode, new_dentry); } -static int selinux_inode_readlink (struct dentry *dentry) +static int selinux_inode_readlink (struct dentry *dentry,struct vfsmount *mnt) {return dentry_has_perm (current,NULL , dentry,FILE__READ ); }
PATCH 12/44 Add struct vfsmount parameters to vfs_link()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/ecryptfs/inode.c | 9 +++++++-- fs/namei.c | 5 +++-- fs/nfsd/vfs.c | 3 ++- include/linux/fs.h | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-)
fs/ecryptfs/inode.c +7 -2
@@ -411,19 +411,24 @@ static int ecryptfs_link(struct dentry * struct dentry *new_dentry) {struct dentry *lower_old_dentry; +struct vfsmount *lower_old_mnt;struct dentry *lower_new_dentry; +struct vfsmount *lower_new_mnt;struct dentry *lower_dir_dentry;u64 file_size_save;int rc; file_size_save =i_size_read (old_dentry->d_inode); lower_old_dentry =ecryptfs_dentry_to_lower (old_dentry); + lower_old_mnt =ecryptfs_dentry_to_lower_mnt (old_dentry); lower_new_dentry =ecryptfs_dentry_to_lower (new_dentry); + lower_new_mnt =ecryptfs_dentry_to_lower_mnt (new_dentry);dget (lower_old_dentry);dget (lower_new_dentry); lower_dir_dentry =lock_parent (lower_new_dentry); - rc =vfs_link (lower_old_dentry, lower_dir_dentry->d_inode, - lower_new_dentry); + rc =vfs_link (lower_old_dentry, lower_old_mnt, + lower_dir_dentry->d_inode, lower_new_dentry, + lower_new_mnt);if (rc || !lower_new_dentry->d_inode) goto out_lock; rc =ecryptfs_interpose (lower_new_dentry, new_dentry, dir->i_sb,0 );
fs/namei.c +3 -2
@@ -2268,7 +2268,7 @@ asmlinkage long sys_symlink(const char _return sys_symlinkat (oldname,AT_FDCWD , newname); } -int vfs_link (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry) +int vfs_link (struct dentry *old_dentry,struct vfsmount *old_mnt,struct inode *dir,struct dentry *new_dentry,struct vfsmount *new_mnt) {struct inode *inode = old_dentry->d_inode;int error;
@@ -2346,7 +2346,8 @@ asmlinkage long sys_linkat(int olddfd, c error =PTR_ERR (new_dentry);if (IS_ERR (new_dentry)) goto out_unlock; - error =vfs_link (old_nd.dentry, nd.dentry->d_inode, new_dentry); + error =vfs_link (old_nd.dentry, old_nd.mnt, nd.dentry->d_inode, + new_dentry, nd.mnt);dput (new_dentry); out_unlock:mutex_unlock (&nd.dentry->d_inode->i_mutex);
fs/nfsd/vfs.c +2 -1
@@ -1536,7 +1536,8 @@ nfsd_link(struct svc_rqst *rqstp, struct dold = tfhp->fh_dentry; dest = dold->d_inode; - host_err =vfs_link (dold, dirp, dnew); + host_err =vfs_link (dold, tfhp->fh_export->ex_mnt, dirp, + dnew, ffhp->fh_export->ex_mnt);if (!host_err) {if (EX_ISSYNC (ffhp->fh_export)) { err =nfserrno (nfsd_sync_dir (ddir));
include/linux/fs.h +1 -1
@@ -996,7 +996,7 @@ extern int vfs_create(struct inode *, stextern int vfs_mkdir (struct inode *,struct dentry *,struct vfsmount *,int );extern int vfs_mknod (struct inode *,struct dentry *,struct vfsmount *,int ,dev_t );extern int vfs_symlink (struct inode *,struct dentry *,struct vfsmount *,const char *,int ); -extern int vfs_link (struct dentry *,struct inode *,struct dentry *); +extern int vfs_link (struct dentry *,struct vfsmount *,struct inode *,struct dentry *,struct vfsmount *);extern int vfs_rmdir (struct inode *,struct dentry *);extern int vfs_unlink (struct inode *,struct dentry *);extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *);
PATCH 13/44 Pass the struct vfsmounts to the inode_link LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 3 ++- include/linux/security.h | 18 +++++++++++++----- security/dummy.c | 6 ++++-- security/selinux/hooks.c | 9 +++++++-- 4 files changed, 26 insertions(+), 10 deletions(-)
fs/namei.c +2 -1
@@ -2293,7 +2293,8 @@ int vfs_link(struct dentry *old_dentry,if (S_ISDIR (old_dentry->d_inode->i_mode))return -EPERM ; - error =security_inode_link (old_dentry, dir, new_dentry); + error =security_inode_link (old_dentry, old_mnt, dir, new_dentry, + new_mnt);if (error)return error;
include/linux/security.h +13 -5
@@ -289,8 +289,10 @@ struct request_sock;* @inode_link: * Check permission before creating a new hard link to a file. * @old_dentry contains the dentry structure for an existing link to the file. +* @old_mnt is the vfsmount corresponding to @old_dentry (may be NULL). * @dir contains the inode structure of the parent directory of the new link. * @new_dentry contains the dentry structure for the new link. +* @new_mnt is the vfsmount corresponding to @new_dentry (may be NULL). * Return 0 if permission is granted. * @inode_unlink: * Check the permission to remove a hard link to a file.
@@ -1212,8 +1214,9 @@ struct security_operations { char **name, void **value, size_t *len);int (*inode_create) (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt,int mode); -int (*inode_link) (struct dentry *old_dentry, -struct inode *dir,struct dentry *new_dentry); +int (*inode_link) (struct dentry *old_dentry,struct vfsmount *old_mnt, +struct inode *dir,struct dentry *new_dentry, +struct vfsmount *new_mnt);int (*inode_unlink) (struct inode *dir,struct dentry *dentry);int (*inode_symlink) (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt,const char *old_name);
@@ -1628,12 +1631,15 @@ static inline int security_inode_create }static inline int security_inode_link (struct dentry *old_dentry, +struct vfsmount *old_mnt,struct inode *dir, -struct dentry *new_dentry) +struct dentry *new_dentry, +struct vfsmount *new_mnt) {if (unlikely (IS_PRIVATE (old_dentry->d_inode)))return 0 ; -return security_ops->inode_link (old_dentry, dir, new_dentry); +return security_ops->inode_link (old_dentry, old_mnt, dir, + new_dentry, new_mnt); } static inline int security_inode_unlink (struct inode *dir,
@@ -2359,8 +2365,10 @@ static inline int security_inode_create }static inline int security_inode_link (struct dentry *old_dentry, +struct vfsmount *old_mnt,struct inode *dir, -struct dentry *new_dentry) +struct dentry *new_dentry, +struct vfsmount *new_mnt) {return 0 ; }
security/dummy.c +4 -2
@@ -270,8 +270,10 @@ static int dummy_inode_create (struct inreturn 0 ; } -static int dummy_inode_link (struct dentry *old_dentry,struct inode *inode, -struct dentry *new_dentry) +static int dummy_inode_link (struct dentry *old_dentry, +struct vfsmount *old_mnt,struct inode *inode, +struct dentry *new_dentry, +struct vfsmount *new_mnt) {return 0 ; }
security/selinux/hooks.c +7 -2
@@ -2182,11 +2182,16 @@ static int selinux_inode_create(struct ireturn may_create (dir, dentry,SECCLASS_FILE ); } -static int selinux_inode_link (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry) +static int selinux_inode_link (struct dentry *old_dentry, +struct vfsmount *old_mnt, +struct inode *dir, +struct dentry *new_dentry, +struct vfsmount *new_mnt) {int rc; - rc = secondary_ops->inode_link (old_dentry,dir,new_dentry); + rc = secondary_ops->inode_link (old_dentry, old_mnt, dir, new_dentry, + new_mnt);if (rc)return rc;return may_link (dir, old_dentry,MAY_LINK );
PATCH 14/44 Add a struct vfsmount parameter to vfs_rmdir()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/ecryptfs/inode.c | 4 +++- fs/namei.c | 4 ++-- fs/nfsd/nfs4recover.c | 2 +- fs/nfsd/vfs.c | 8 +++++--- fs/reiserfs/xattr.c | 2 +- include/linux/fs.h | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-)
fs/ecryptfs/inode.c +3 -1
@@ -542,14 +542,16 @@ out:static int ecryptfs_rmdir (struct inode *dir,struct dentry *dentry) {struct dentry *lower_dentry; +struct vfsmount *lower_mnt;struct dentry *lower_dir_dentry;int rc; lower_dentry =ecryptfs_dentry_to_lower (dentry); + lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry);dget (dentry); lower_dir_dentry =lock_parent (lower_dentry);dget (lower_dentry); - rc =vfs_rmdir (lower_dir_dentry->d_inode, lower_dentry); + rc =vfs_rmdir (lower_dir_dentry->d_inode, lower_dentry, lower_mnt);dput (lower_dentry);if (!rc)d_delete (lower_dentry);
fs/namei.c +2 -2
@@ -2024,7 +2024,7 @@ void dentry_unhash(struct dentry *dentryspin_unlock (&dcache_lock); } -int vfs_rmdir (struct inode *dir,struct dentry *dentry) +int vfs_rmdir (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt) {int error =may_delete (dir, dentry,1 );
@@ -2088,7 +2088,7 @@ static long do_rmdir(int dfd, const char error =PTR_ERR (dentry);if (IS_ERR (dentry)) goto exit2; - error =vfs_rmdir (nd.dentry->d_inode, dentry); + error =vfs_rmdir (nd.dentry->d_inode, dentry, nd.mnt);dput (dentry); exit2:mutex_unlock (&nd.dentry->d_inode->i_mutex);
fs/nfsd/nfs4recover.c +1 -1
@@ -276,7 +276,7 @@ nfsd4_clear_clid_dir(struct dentry *dir,* a kernel from the future.... */ nfsd4_list_rec_dir (dentry, nfsd4_remove_clid_file);mutex_lock_nested (&dir->d_inode->i_mutex,I_MUTEX_PARENT ); - status =vfs_rmdir (dir->d_inode, dentry); + status =vfs_rmdir (dir->d_inode, dentry, rec_dir.mnt);mutex_unlock (&dir->d_inode->i_mutex);return status; }
fs/nfsd/vfs.c +5 -3
@@ -1666,6 +1666,7 @@ nfsd_unlink(struct svc_rqst *rqstp, stru char *fname, int flen) {struct dentry *dentry, *rdentry; +struct svc_export *exp;struct inode *dirp;__be32 err;int host_err;
@@ -1680,6 +1681,7 @@ nfsd_unlink(struct svc_rqst *rqstp, strufh_lock_nested (fhp,I_MUTEX_PARENT ); dentry = fhp->fh_dentry; dirp = dentry->d_inode; + exp = fhp->fh_export; rdentry =lookup_one_len (fname, dentry, flen); host_err =PTR_ERR (rdentry);
@@ -1697,21 +1699,21 @@ nfsd_unlink(struct svc_rqst *rqstp, struif (type !=S_IFDIR ) {/* It's UNLINK */ #ifdef MSNFS -if ((fhp->fh_export->ex_flags &NFSEXP_MSNFS ) && +if ((exp->ex_flags &NFSEXP_MSNFS ) && (atomic_read (&rdentry->d_count) >1 )) { host_err = -EPERM ; } else#endif host_err =vfs_unlink (dirp, rdentry); }else {/* It's RMDIR */ - host_err =vfs_rmdir (dirp, rdentry); + host_err =vfs_rmdir (dirp, rdentry, exp->ex_mnt); }dput (rdentry);if (host_err) goto out_nfserr; -if (EX_ISSYNC (fhp->fh_export)) +if (EX_ISSYNC (exp)) host_err =nfsd_sync_dir (dentry); out_nfserr:
fs/reiserfs/xattr.c +1 -1
@@ -775,7 +775,7 @@ int reiserfs_delete_xattrs(struct inodeif (dir->d_inode->i_nlink <=2 ) { root =get_xa_root (inode->i_sb,XATTR_REPLACE );reiserfs_write_lock_xattrs (inode->i_sb); - err =vfs_rmdir (root->d_inode, dir); + err =vfs_rmdir (root->d_inode, dir,NULL );reiserfs_write_unlock_xattrs (inode->i_sb);dput (root); }else {
include/linux/fs.h +1 -1
@@ -997,7 +997,7 @@ extern int vfs_mkdir(struct inode *, strextern int vfs_mknod (struct inode *,struct dentry *,struct vfsmount *,int ,dev_t );extern int vfs_symlink (struct inode *,struct dentry *,struct vfsmount *,const char *,int );extern int vfs_link (struct dentry *,struct vfsmount *,struct inode *,struct dentry *,struct vfsmount *); -extern int vfs_rmdir (struct inode *,struct dentry *); +extern int vfs_rmdir (struct inode *,struct dentry *,struct vfsmount *);extern int vfs_unlink (struct inode *,struct dentry *);extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *);
PATCH 15/44 Pass struct vfsmount to the inode_rmdir LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 2 +- include/linux/security.h | 12 ++++++++---- security/dummy.c | 3 ++- security/selinux/hooks.c | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-)
fs/namei.c +1 -1
@@ -2041,7 +2041,7 @@ int vfs_rmdir(struct inode *dir, structif (d_mountpoint (dentry)) error = -EBUSY ;else { - error =security_inode_rmdir (dir, dentry); + error =security_inode_rmdir (dir, dentry, mnt);if (!error) { error = dir->i_op->rmdir (dir, dentry);if (!error)
include/linux/security.h +8 -4
@@ -318,6 +318,7 @@ struct request_sock;* Check the permission to remove a directory. * @dir contains the inode structure of parent of the directory to be removed. * @dentry contains the dentry structure of directory to be removed. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * Return 0 if permission is granted. * @inode_mknod: * Check permissions when creating a special file (or a socket or a fifo
@@ -1222,7 +1223,8 @@ struct security_operations { struct vfsmount *mnt, const char *old_name);int (*inode_mkdir) (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt,int mode); -int (*inode_rmdir) (struct inode *dir,struct dentry *dentry); +int (*inode_rmdir) (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt);int (*inode_mknod) (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt,int mode,dev_t dev); int (*inode_rename) (struct inode *old_dir, struct dentry *old_dentry,
@@ -1671,11 +1673,12 @@ static inline int security_inode_mkdir ( }static inline int security_inode_rmdir (struct inode *dir, -struct dentry *dentry) +struct dentry *dentry, +struct vfsmount *mnt) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_rmdir (dir, dentry); +return security_ops->inode_rmdir (dir, dentry, mnt); } static inline int security_inode_mknod (struct inode *dir,
@@ -2396,7 +2399,8 @@ static inline int security_inode_mkdir ( }static inline int security_inode_rmdir (struct inode *dir, -struct dentry *dentry) +struct dentry *dentry, +struct vfsmount *mnt) {return 0 ; }
security/dummy.c +2 -1
@@ -295,7 +295,8 @@ static int dummy_inode_mkdir (struct inoreturn 0 ; } -static int dummy_inode_rmdir (struct inode *inode,struct dentry *dentry) +static int dummy_inode_rmdir (struct inode *inode,struct dentry *dentry, +struct vfsmount *mnt) {return 0 ; }
security/selinux/hooks.c +2 -1
@@ -2219,7 +2219,8 @@ static int selinux_inode_mkdir(struct inreturn may_create (dir, dentry,SECCLASS_DIR ); } -static int selinux_inode_rmdir (struct inode *dir,struct dentry *dentry) +static int selinux_inode_rmdir (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt) {return may_link (dir, dentry,MAY_RMDIR ); }
PATCH 16/44 Call lsm hook before unhashing dentry in vfs_rmdir()
In reply to [email protected]If we unhash the dentry before calling the security_inode_rmdir hook, we cannot compute the file's pathname in the hook anymore. AppArmor needs to know the filename in order to decide whether a file may be deleted, though.
--- fs/namei.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/namei.c +7 -6
@@ -2034,6 +2034,10 @@ int vfs_rmdir(struct inode *dir, structif (!dir->i_op || !dir->i_op->rmdir)return -EPERM ; + error =security_inode_rmdir (dir, dentry, mnt); +if (error) +return error; +DQUOT_INIT (dir);mutex_lock (&dentry->d_inode->i_mutex);
@@ -2041,12 +2045,9 @@ int vfs_rmdir(struct inode *dir, structif (d_mountpoint (dentry)) error = -EBUSY ;else { - error =security_inode_rmdir (dir, dentry, mnt); -if (!error) { - error = dir->i_op->rmdir (dir, dentry); -if (!error) - dentry->d_inode->i_flags |=S_DEAD ; - } + error = dir->i_op->rmdir (dir, dentry); +if (!error) + dentry->d_inode->i_flags |=S_DEAD ; }mutex_unlock (&dentry->d_inode->i_mutex);if (!error) {
PATCH 17/44 Add a struct vfsmount parameter to vfs_unlink()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/ecryptfs/inode.c | 3 ++- fs/namei.c | 4 ++-- fs/nfsd/nfs4recover.c | 2 +- fs/nfsd/vfs.c | 2 +- include/linux/fs.h | 2 +- ipc/mqueue.c | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-)
fs/ecryptfs/inode.c +2 -1
@@ -453,10 +453,11 @@ static int ecryptfs_unlink(struct inode {int rc =0 ;struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry); +struct vfsmount *lower_mnt =ecryptfs_dentry_to_lower_mnt (dentry);struct inode *lower_dir_inode =ecryptfs_inode_to_lower (dir);lock_parent (lower_dentry); - rc =vfs_unlink (lower_dir_inode, lower_dentry); + rc =vfs_unlink (lower_dir_inode, lower_dentry, lower_mnt);if (rc) {printk (KERN_ERR "Error in vfs_unlink; rc = [%d]\n" , rc); goto out_unlock;
fs/namei.c +2 -2
@@ -2105,7 +2105,7 @@ asmlinkage long sys_rmdir(const char __ureturn do_rmdir (AT_FDCWD , pathname); } -int vfs_unlink (struct inode *dir,struct dentry *dentry) +int vfs_unlink (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt) {int error =may_delete (dir, dentry,0 );
@@ -2169,7 +2169,7 @@ static long do_unlinkat(int dfd, const c inode = dentry->d_inode;if (inode)atomic_inc (&inode->i_count); - error =vfs_unlink (nd.dentry->d_inode, dentry); + error =vfs_unlink (nd.dentry->d_inode, dentry, nd.mnt); exit2:dput (dentry); }
fs/nfsd/nfs4recover.c +1 -1
@@ -261,7 +261,7 @@ nfsd4_remove_clid_file(struct dentry *direturn -EINVAL ; }mutex_lock_nested (&dir->d_inode->i_mutex,I_MUTEX_PARENT ); - status =vfs_unlink (dir->d_inode, dentry); + status =vfs_unlink (dir->d_inode, dentry, rec_dir.mnt);mutex_unlock (&dir->d_inode->i_mutex);return status; }
fs/nfsd/vfs.c +1 -1
@@ -1704,7 +1704,7 @@ nfsd_unlink(struct svc_rqst *rqstp, stru host_err = -EPERM; } else#endif - host_err =vfs_unlink (dirp, rdentry); + host_err =vfs_unlink (dirp, rdentry, exp->ex_mnt); }else {/* It's RMDIR */ host_err =vfs_rmdir (dirp, rdentry, exp->ex_mnt); }
include/linux/fs.h +1 -1
@@ -998,7 +998,7 @@ extern int vfs_mknod(struct inode *, strextern int vfs_symlink (struct inode *,struct dentry *,struct vfsmount *,const char *,int );extern int vfs_link (struct dentry *,struct vfsmount *,struct inode *,struct dentry *,struct vfsmount *);extern int vfs_rmdir (struct inode *,struct dentry *,struct vfsmount *); -extern int vfs_unlink (struct inode *,struct dentry *); +extern int vfs_unlink (struct inode *,struct dentry *,struct vfsmount *);extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *);/*
ipc/mqueue.c +1 -1
@@ -748,7 +748,7 @@ asmlinkage long sys_mq_unlink(const charif (inode)atomic_inc (&inode->i_count); - err =vfs_unlink (dentry->d_parent->d_inode, dentry); + err =vfs_unlink (dentry->d_parent->d_inode, dentry, mqueue_mnt); out_err:dput (dentry);
PATCH 18/44 Pass struct vfsmount to the inode_unlink LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 2 +- include/linux/security.h | 12 ++++++++---- security/dummy.c | 3 ++- security/selinux/hooks.c | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-)
fs/namei.c +1 -1
@@ -2121,7 +2121,7 @@ int vfs_unlink(struct inode *dir, structif (d_mountpoint (dentry)) error = -EBUSY ;else { - error =security_inode_unlink (dir, dentry); + error =security_inode_unlink (dir, dentry, mnt);if (!error) error = dir->i_op->unlink (dir, dentry); }
include/linux/security.h +8 -4
@@ -298,6 +298,7 @@ struct request_sock;* Check the permission to remove a hard link to a file. * @dir contains the inode structure of parent directory of the file. * @dentry contains the dentry structure for file to be unlinked. +* @mnt is the vfsmount corresponding to @dentry (may be NULL). * Return 0 if permission is granted. * @inode_symlink: * Check the permission to create a symbolic link to a file.
@@ -1218,7 +1219,8 @@ struct security_operations {int (*inode_link) (struct dentry *old_dentry,struct vfsmount *old_mnt,struct inode *dir,struct dentry *new_dentry,struct vfsmount *new_mnt); -int (*inode_unlink) (struct inode *dir,struct dentry *dentry); +int (*inode_unlink) (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt);int (*inode_symlink) (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt,const char *old_name); int (*inode_mkdir) (struct inode *dir, struct dentry *dentry,
@@ -1645,11 +1647,12 @@ static inline int security_inode_link (s }static inline int security_inode_unlink (struct inode *dir, -struct dentry *dentry) +struct dentry *dentry, +struct vfsmount *mnt) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_unlink (dir, dentry); +return security_ops->inode_unlink (dir, dentry, mnt); } static inline int security_inode_symlink (struct inode *dir,
@@ -2377,7 +2380,8 @@ static inline int security_inode_link (s }static inline int security_inode_unlink (struct inode *dir, -struct dentry *dentry) +struct dentry *dentry, +struct vfsmount *mnt) {return 0 ; }
security/dummy.c +2 -1
@@ -278,7 +278,8 @@ static int dummy_inode_link (struct dentreturn 0 ; } -static int dummy_inode_unlink (struct inode *inode,struct dentry *dentry) +static int dummy_inode_unlink (struct inode *inode,struct dentry *dentry, +struct vfsmount *mnt) {return 0 ; }
security/selinux/hooks.c +3 -2
@@ -2197,11 +2197,12 @@ static int selinux_inode_link(struct denreturn may_link (dir, old_dentry,MAY_LINK ); } -static int selinux_inode_unlink (struct inode *dir,struct dentry *dentry) +static int selinux_inode_unlink (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt) {int rc; - rc = secondary_ops->inode_unlink (dir, dentry); + rc = secondary_ops->inode_unlink (dir, dentry, mnt);if (rc)return rc;return may_link (dir, dentry,MAY_UNLINK );
PATCH 19/44 Add struct vfsmount parameters to vfs_rename()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/ecryptfs/inode.c | 7 ++++++- fs/namei.c | 19 ++++++++++++------- fs/nfsd/vfs.c | 3 ++- include/linux/fs.h | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-)
fs/ecryptfs/inode.c +6 -1
@@ -598,19 +598,24 @@ ecryptfs_rename(struct inode *old_dir, s {int rc;struct dentry *lower_old_dentry; +struct vfsmount *lower_old_mnt;struct dentry *lower_new_dentry; +struct vfsmount *lower_new_mnt;struct dentry *lower_old_dir_dentry;struct dentry *lower_new_dir_dentry; lower_old_dentry =ecryptfs_dentry_to_lower (old_dentry); + lower_old_mnt =ecryptfs_dentry_to_lower_mnt (old_dentry); lower_new_dentry =ecryptfs_dentry_to_lower (new_dentry); + lower_new_mnt =ecryptfs_dentry_to_lower_mnt (new_dentry);dget (lower_old_dentry);dget (lower_new_dentry); lower_old_dir_dentry =dget_parent (lower_old_dentry); lower_new_dir_dentry =dget_parent (lower_new_dentry);lock_rename (lower_old_dir_dentry, lower_new_dir_dentry); rc =vfs_rename (lower_old_dir_dentry->d_inode, lower_old_dentry, - lower_new_dir_dentry->d_inode, lower_new_dentry); + lower_old_mnt, lower_new_dir_dentry->d_inode, + lower_new_dentry, lower_new_mnt);if (rc) goto out_lock;fsstack_copy_attr_all (new_dir, lower_new_dir_dentry->d_inode,NULL );
fs/namei.c +12 -7
@@ -2401,7 +2401,8 @@ asmlinkage long sys_link(const char __us* locking]. */ static int vfs_rename_dir (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry) +struct vfsmount *old_mnt,struct inode *new_dir, +struct dentry *new_dentry,struct vfsmount *new_mnt) {int error =0 ;struct inode *target;
@@ -2444,7 +2445,8 @@ static int vfs_rename_dir(struct inode * }static int vfs_rename_other (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry) +struct vfsmount *old_mnt,struct inode *new_dir, +struct dentry *new_dentry,struct vfsmount *new_mnt) {struct inode *target;int error;
@@ -2472,7 +2474,8 @@ static int vfs_rename_other(struct inode }int vfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry) +struct vfsmount *old_mnt,struct inode *new_dir, +struct dentry *new_dentry,struct vfsmount *new_mnt) {int error;int is_dir =S_ISDIR (old_dentry->d_inode->i_mode);
@@ -2501,9 +2504,11 @@ int vfs_rename(struct inode *old_dir, st old_name =fsnotify_oldname_init (old_dentry->d_name.name);if (is_dir) - error =vfs_rename_dir (old_dir,old_dentry,new_dir,new_dentry); + error =vfs_rename_dir (old_dir, old_dentry, old_mnt, + new_dir, new_dentry, new_mnt);else - error =vfs_rename_other (old_dir,old_dentry,new_dir,new_dentry); + error =vfs_rename_other (old_dir, old_dentry, old_mnt, + new_dir, new_dentry, new_mnt);if (!error) {const char *new_name = old_dentry->d_name.name; fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
@@ -2575,8 +2580,8 @@ static int do_rename(int olddfd, const cif (new_dentry == trap) goto exit5; - error =vfs_rename (old_dir->d_inode, old_dentry, - new_dir->d_inode, new_dentry); + error =vfs_rename (old_dir->d_inode, old_dentry, oldnd.mnt, + new_dir->d_inode, new_dentry, newnd.mnt); exit5:dput (new_dentry); exit4:
fs/nfsd/vfs.c +2 -1
@@ -1630,7 +1630,8 @@ nfsd_rename(struct svc_rqst *rqstp, stru host_err = -EPERM ; } else#endif - host_err =vfs_rename (fdir, odentry, tdir, ndentry); + host_err =vfs_rename (fdir, odentry, ffhp->fh_export->ex_mnt, + tdir, ndentry, tfhp->fh_export->ex_mnt);if (!host_err &&EX_ISSYNC (tfhp->fh_export)) { host_err =nfsd_sync_dir (tdentry);if (!host_err)
include/linux/fs.h +1 -1
@@ -999,7 +999,7 @@ extern int vfs_symlink(struct inode *, sextern int vfs_link (struct dentry *,struct vfsmount *,struct inode *,struct dentry *,struct vfsmount *);extern int vfs_rmdir (struct inode *,struct dentry *,struct vfsmount *);extern int vfs_unlink (struct inode *,struct dentry *,struct vfsmount *); -extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *); +extern int vfs_rename (struct inode *,struct dentry *,struct vfsmount *,struct inode *,struct dentry *,struct vfsmount *);/* * VFS dentry helper functions.
PATCH 20/44 Pass struct vfsmount to the inode_rename LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/namei.c | 6 ++++-- include/linux/security.h | 18 +++++++++++++----- security/dummy.c | 4 +++- security/selinux/hooks.c | 8 ++++++-- 4 files changed, 26 insertions(+), 10 deletions(-)
fs/namei.c +4 -2
@@ -2417,7 +2417,8 @@ static int vfs_rename_dir(struct inode *return error; } - error =security_inode_rename (old_dir, old_dentry, new_dir, new_dentry); + error =security_inode_rename (old_dir, old_dentry, old_mnt, + new_dir, new_dentry, new_mnt);if (error)return error;
@@ -2451,7 +2452,8 @@ static int vfs_rename_other(struct inodestruct inode *target;int error; - error =security_inode_rename (old_dir, old_dentry, new_dir, new_dentry); + error =security_inode_rename (old_dir, old_dentry, old_mnt, + new_dir, new_dentry, new_mnt);if (error)return error;
include/linux/security.h +13 -5
@@ -336,8 +336,10 @@ struct request_sock;* Check for permission to rename a file or directory. * @old_dir contains the inode structure for parent of the old link. * @old_dentry contains the dentry structure of the old link. +* @old_mnt is the vfsmount corresponding to @old_dentry (may be NULL). * @new_dir contains the inode structure for parent of the new link. * @new_dentry contains the dentry structure of the new link. +* @new_mnt is the vfsmount corresponding to @new_dentry (may be NULL). * Return 0 if permission is granted. * @inode_readlink: * Check the permission to read the symbolic link.
@@ -1230,7 +1232,9 @@ struct security_operations {int (*inode_mknod) (struct inode *dir,struct dentry *dentry,struct vfsmount *mnt,int mode,dev_t dev);int (*inode_rename) (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry); +struct vfsmount *old_mnt, +struct inode *new_dir,struct dentry *new_dentry, +struct vfsmount *new_mnt);int (*inode_readlink) (struct dentry *dentry,struct vfsmount *mnt);int (*inode_follow_link) (struct dentry *dentry,struct nameidata *nd);int (*inode_permission) (struct inode *inode,int mask,struct nameidata *nd);
@@ -1696,14 +1700,16 @@ static inline int security_inode_mknod (static inline int security_inode_rename (struct inode *old_dir,struct dentry *old_dentry, +struct vfsmount *old_mnt,struct inode *new_dir, -struct dentry *new_dentry) +struct dentry *new_dentry, +struct vfsmount *new_mnt) {if (unlikely (IS_PRIVATE (old_dentry->d_inode) || (new_dentry->d_inode &&IS_PRIVATE (new_dentry->d_inode))))return 0 ; -return security_ops->inode_rename (old_dir, old_dentry, - new_dir, new_dentry); +return security_ops->inode_rename (old_dir, old_dentry, old_mnt, + new_dir, new_dentry, new_mnt); } static inline int security_inode_readlink (struct dentry *dentry,
@@ -2419,8 +2425,10 @@ static inline int security_inode_mknod (static inline int security_inode_rename (struct inode *old_dir,struct dentry *old_dentry, +struct vfsmount *old_mnt,struct inode *new_dir, -struct dentry *new_dentry) +struct dentry *new_dentry, +struct vfsmount *new_mnt) {return 0 ; }
security/dummy.c +3 -1
@@ -310,8 +310,10 @@ static int dummy_inode_mknod (struct inostatic int dummy_inode_rename (struct inode *old_inode,struct dentry *old_dentry, +struct vfsmount *old_mnt,struct inode *new_inode, -struct dentry *new_dentry) +struct dentry *new_dentry, +struct vfsmount *new_mnt) {return 0 ; }
security/selinux/hooks.c +6 -2
@@ -2238,8 +2238,12 @@ static int selinux_inode_mknod(struct inreturn may_create (dir, dentry,inode_mode_to_security_class (mode)); } -static int selinux_inode_rename (struct inode *old_inode,struct dentry *old_dentry, -struct inode *new_inode,struct dentry *new_dentry) +static int selinux_inode_rename (struct inode *old_inode, +struct dentry *old_dentry, +struct vfsmount *old_mnt, +struct inode *new_inode, +struct dentry *new_dentry, +struct vfsmount *new_mnt) {return may_rename (old_inode, old_dentry, new_inode, new_dentry); }
PATCH 21/44 Add a struct vfsmount parameter to vfs_setxattr()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/nfsd/vfs.c | 16 +++++++++++----- fs/xattr.c | 16 ++++++++-------- include/linux/xattr.h | 3 ++- 3 files changed, 21 insertions(+), 14 deletions(-)
fs/nfsd/vfs.c +11 -5
@@ -396,7 +396,8 @@ static ssize_t nfsd_getxattr(struct dent#if defined(CONFIG_NFSD_V4 )static int -set_nfsv4_acl_one (struct dentry *dentry,struct posix_acl *pacl,char *key) +set_nfsv4_acl_one (struct dentry *dentry,struct vfsmount *mnt, +struct posix_acl *pacl,char *key) {int len;size_t buflen;
@@ -415,7 +416,7 @@ set_nfsv4_acl_one(struct dentry *dentry, goto out; } - error =vfs_setxattr (dentry, key, buf, len,0 ); + error =vfs_setxattr (dentry, mnt, key, buf, len,0 ); out:kfree (buf);return error;
@@ -428,6 +429,7 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst__be32 error;int host_error;struct dentry *dentry; +struct vfsmount *mnt;struct inode *inode;struct posix_acl *pacl =NULL , *dpacl =NULL ;unsigned int flags =0 ;
@@ -438,6 +440,7 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst goto out; dentry = fhp->fh_dentry; + mnt = fhp->fh_export->ex_mnt; inode = dentry->d_inode;if (S_ISDIR (inode->i_mode)) flags =NFS4_ACL_DIR ;
@@ -449,12 +452,14 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqst }else if (host_error <0 ) goto out_nfserr; - host_error =set_nfsv4_acl_one (dentry, pacl,POSIX_ACL_XATTR_ACCESS ); + host_error =set_nfsv4_acl_one (dentry, mnt, pacl, +POSIX_ACL_XATTR_ACCESS );if (host_error <0 ) goto out_nfserr;if (S_ISDIR (inode->i_mode)) { - host_error =set_nfsv4_acl_one (dentry, dpacl,POSIX_ACL_XATTR_DEFAULT ); + host_error =set_nfsv4_acl_one (dentry, mnt, dpacl, +POSIX_ACL_XATTR_DEFAULT );if (host_error <0 ) goto out_nfserr; }
@@ -1982,7 +1987,8 @@ nfsd_set_posix_acl(struct svc_fh *fhp, i size =0 ;if (size) - error =vfs_setxattr (fhp->fh_dentry, name, value, size,0 ); + error =vfs_setxattr (fhp->fh_dentry, fhp->fh_export->ex_mnt, + name, value, size,0 );else {if (!S_ISDIR (inode->i_mode) && type ==ACL_TYPE_DEFAULT ) error =0 ;
fs/xattr.c +8 -8
@@ -69,8 +69,8 @@ xattr_permission(struct inode *inode, co }int -vfs_setxattr (struct dentry *dentry,char *name,void *value, -size_t size,int flags) +vfs_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name, +void *value,size_t size,int flags) {struct inode *inode = dentry->d_inode;int error;
@@ -193,8 +193,8 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);* Extended attribute SET operations */ static long -setxattr (struct dentry *d,char __user *name,void __user *value, -size_t size,int flags) +setxattr (struct dentry *dentry,struct vfsmount *mnt,char __user *name, +void __user *value,size_t size,int flags) {int error;void *kvalue =NULL ;
@@ -221,7 +221,7 @@ setxattr(struct dentry *d, char __user * } } - error =vfs_setxattr (d, kname, kvalue, size, flags); + error =vfs_setxattr (dentry, mnt, kname, kvalue, size, flags);kfree (kvalue);return error; }
@@ -236,7 +236,7 @@ sys_setxattr(char __user *path, char __u error =user_path_walk (path, &nd);if (error)return error; - error =setxattr (nd.dentry, name, value, size, flags); + error =setxattr (nd.dentry, nd.mnt, name, value, size, flags);path_release (&nd);return error; }
@@ -251,7 +251,7 @@ sys_lsetxattr(char __user *path, char __ error =user_path_walk_link (path, &nd);if (error)return error; - error =setxattr (nd.dentry, name, value, size, flags); + error =setxattr (nd.dentry, nd.mnt, name, value, size, flags);path_release (&nd);return error; }
@@ -269,7 +269,7 @@ sys_fsetxattr(int fd, char __user *name,return error; dentry = f->f_path.dentry;audit_inode (NULL , dentry->d_inode); - error =setxattr (dentry, name, value, size, flags); + error =setxattr (dentry, f->f_vfsmnt, name, value, size, flags);fput (f);return error; }
include/linux/xattr.h +2 -1
@@ -48,7 +48,8 @@ struct xattr_handler {ssize_t vfs_getxattr (struct dentry *,char *,void *,size_t );ssize_t vfs_listxattr (struct dentry *d,char *list,size_t size); -int vfs_setxattr (struct dentry *,char *,void *,size_t ,int ); +int vfs_setxattr (struct dentry *,struct vfsmount *,char *,void *,size_t , +int );int vfs_removexattr (struct dentry *,char *);ssize_t generic_getxattr (struct dentry *dentry,const char *name,void *buffer,size_t size);
PATCH 22/44 Pass struct vfsmount to the inode_setxattr LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/xattr.c | 4 ++-- include/linux/security.h | 40 +++++++++++++++++++++++++--------------- security/commoncap.c | 4 ++-- security/dummy.c | 9 ++++++--- security/selinux/hooks.c | 8 ++++++-- 5 files changed, 41 insertions(+), 24 deletions(-)
fs/xattr.c +2 -2
@@ -80,7 +80,7 @@ vfs_setxattr(struct dentry *dentry, strureturn error;mutex_lock (&inode->i_mutex); - error =security_inode_setxattr (dentry, name, value, size, flags); + error =security_inode_setxattr (dentry, mnt, name, value, size, flags);if (error) goto out; error = -EOPNOTSUPP ;
@@ -88,7 +88,7 @@ vfs_setxattr(struct dentry *dentry, stru error = inode->i_op->setxattr (dentry, name, value, size, flags);if (!error) {fsnotify_xattr (dentry); -security_inode_post_setxattr (dentry, name, value, +security_inode_post_setxattr (dentry, mnt, name, value, size, flags); } } else if (!strncmp(name, XATTR_SECURITY_PREFIX,
include/linux/security.h +25 -15
@@ -49,7 +49,7 @@ extern void cap_capset_set (struct task_extern int cap_bprm_set_security (struct linux_binprm *bprm);extern void cap_bprm_apply_creds (struct linux_binprm *bprm,int unsafe);extern int cap_bprm_secureexec (struct linux_binprm *bprm); -extern int cap_inode_setxattr (struct dentry *dentry,char *name,void *value,size_t size,int flags); +extern int cap_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name,void *value,size_t size,int flags);extern int cap_inode_removexattr (struct dentry *dentry,char *name);extern int cap_task_post_setuid (uid_t old_ruid,uid_t old_euid,uid_t old_suid,int flags);extern void cap_task_reparent_to_init (struct task_struct *p);
@@ -384,11 +384,11 @@ struct request_sock;* inode. * @inode_setxattr: * Check permission before setting the extended attributes -* @value identified by @name for @dentry. +* @value identified by @name for @dentry and @mnt. * Return 0 if permission is granted. * @inode_post_setxattr: * Update inode security field after successful setxattr operation. -* @value identified by @name for @dentry. +* @value identified by @name for @dentry and @mnt. * @inode_getxattr: * Check permission before obtaining the extended attributes * identified by @name for @dentry.
@@ -1242,9 +1242,11 @@ struct security_operations { struct iattr *attr);int (*inode_getattr) (struct vfsmount *mnt,struct dentry *dentry);void (*inode_delete) (struct inode *inode); -int (*inode_setxattr) (struct dentry *dentry,char *name,void *value, -size_t size,int flags); -void (*inode_post_setxattr) (struct dentry *dentry,char *name,void *value, +int (*inode_setxattr) (struct dentry *dentry,struct vfsmount *mnt, +char *name,void *value,size_t size,int flags); +void (*inode_post_setxattr) (struct dentry *dentry, +struct vfsmount *mnt, +char *name,void *value,size_t size,int flags);int (*inode_getxattr) (struct dentry *dentry,char *name);int (*inode_listxattr) (struct dentry *dentry);
@@ -1760,20 +1762,24 @@ static inline void security_inode_delete security_ops->inode_delete (inode); } -static inline int security_inode_setxattr (struct dentry *dentry,char *name, +static inline int security_inode_setxattr (struct dentry *dentry, +struct vfsmount *mnt,char *name,void *value,size_t size,int flags) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_setxattr (dentry, name, value, size, flags); +return security_ops->inode_setxattr (dentry, mnt, name, value, size, + flags); } -static inline void security_inode_post_setxattr (struct dentry *dentry,char *name, -void *value,size_t size,int flags) +static inline void security_inode_post_setxattr (struct dentry *dentry, +struct vfsmount *mnt, +char *name,void *value, +size_t size,int flags) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return ; - security_ops->inode_post_setxattr (dentry, name, value, size, flags); + security_ops->inode_post_setxattr (dentry, mnt, name, value, size, flags); }static inline int security_inode_getxattr (struct dentry *dentry,char *name)
@@ -2467,14 +2473,18 @@ static inline int security_inode_getattrstatic inline void security_inode_delete (struct inode *inode) { } -static inline int security_inode_setxattr (struct dentry *dentry,char *name, +static inline int security_inode_setxattr (struct dentry *dentry, +struct vfsmount *mnt,char *name,void *value,size_t size,int flags) { -return cap_inode_setxattr (dentry, name, value, size, flags); +return cap_inode_setxattr (dentry, mnt, name, value, size, flags); } -static inline void security_inode_post_setxattr (struct dentry *dentry,char *name, -void *value,size_t size,int flags) +static inline void security_inode_post_setxattr (struct dentry *dentry, +struct vfsmount *mnt, +char *name, +void *value,size_t size, +int flags) { }static inline int security_inode_getxattr (struct dentry *dentry,char *name)
security/commoncap.c +2 -2
@@ -190,8 +190,8 @@ int cap_bprm_secureexec (struct linux_bi current->egid != current->gid); } -int cap_inode_setxattr (struct dentry *dentry,char *name,void *value, -size_t size,int flags) +int cap_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name, +void *value,size_t size,int flags) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
security/dummy.c +6 -3
@@ -350,8 +350,9 @@ static void dummy_inode_delete (struct ireturn ; } -static int dummy_inode_setxattr (struct dentry *dentry,char *name,void *value, -size_t size,int flags) +static int dummy_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt, +char *name,void *value,size_t size, +int flags) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
@@ -360,7 +361,9 @@ static int dummy_inode_setxattr (structreturn 0 ; } -static void dummy_inode_post_setxattr (struct dentry *dentry,char *name,void *value, +static void dummy_inode_post_setxattr (struct dentry *dentry, +struct vfsmount *mnt, +char *name,void *value,size_t size,int flags) { }
security/selinux/hooks.c +6 -2
@@ -2305,7 +2305,9 @@ static int selinux_inode_getattr(structreturn dentry_has_perm (current, mnt, dentry,FILE__GETATTR ); } -static int selinux_inode_setxattr (struct dentry *dentry,char *name,void *value,size_t size,int flags) +static int selinux_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt, +char *name,void *value,size_t size, +int flags) {struct task_security_struct *tsec = current->security;struct inode *inode = dentry->d_inode;
@@ -2365,7 +2367,9 @@ static int selinux_inode_setxattr(struct &ad); } -static void selinux_inode_post_setxattr (struct dentry *dentry,char *name, +static void selinux_inode_post_setxattr (struct dentry *dentry, +struct vfsmount *mnt, +char *name,void *value,size_t size,int flags) {struct inode *inode = dentry->d_inode;
PATCH 23/44 Add a struct vfsmount parameter to vfs_getxattr()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/nfsd/nfs4xdr.c | 2 +- fs/nfsd/vfs.c | 21 ++++++++++++--------- fs/xattr.c | 14 ++++++++------ include/linux/nfsd/nfsd.h | 3 ++- include/linux/xattr.h | 3 ++- 5 files changed, 25 insertions(+), 18 deletions(-)
fs/nfsd/nfs4xdr.c +1 -1
@@ -1469,7 +1469,7 @@ nfsd4_encode_fattr(struct svc_fh *fhp, s }if (bmval0 & (FATTR4_WORD0_ACL |FATTR4_WORD0_ACLSUPPORT |FATTR4_WORD0_SUPPORTED_ATTRS )) { - err =nfsd4_get_nfs4_acl (rqstp, dentry, &acl); + err =nfsd4_get_nfs4_acl (rqstp, dentry, exp->ex_mnt, &acl); aclsupport = (err ==0 );if (bmval0 &FATTR4_WORD0_ACL ) {if (err == -EOPNOTSUPP )
fs/nfsd/vfs.c +12 -9
@@ -378,11 +378,12 @@ out_nfserr:#if defined(CONFIG_NFSD_V2_ACL ) || \ defined(CONFIG_NFSD_V3_ACL ) || \ defined(CONFIG_NFSD_V4 ) -static ssize_t nfsd_getxattr (struct dentry *dentry,char *key,void **buf) +static ssize_t nfsd_getxattr (struct dentry *dentry,struct vfsmount *mnt, +char *key,void **buf) {ssize_t buflen; - buflen =vfs_getxattr (dentry, key,NULL ,0 ); + buflen =vfs_getxattr (dentry, mnt, key,NULL ,0 );if (buflen <=0 )return buflen;
@@ -390,7 +391,7 @@ static ssize_t nfsd_getxattr(struct dentif (!*buf)return -ENOMEM ; - return vfs_getxattr(dentry, key, *buf, buflen); + return vfs_getxattr(dentry, mnt, key, *buf, buflen); }#endif
@@ -479,13 +480,13 @@ out_nfserr: }static struct posix_acl * -_get_posix_acl (struct dentry *dentry,char *key) +_get_posix_acl (struct dentry *dentry,struct vfsmount *mnt,char *key) {void *buf =NULL ;struct posix_acl *pacl =NULL ;int buflen; - buflen =nfsd_getxattr (dentry, key, &buf); + buflen =nfsd_getxattr (dentry, mnt, key, &buf);if (!buflen) buflen = -ENODATA ;if (buflen <=0 )
@@ -497,14 +498,15 @@ _get_posix_acl(struct dentry *dentry, ch }int -nfsd4_get_nfs4_acl (struct svc_rqst *rqstp,struct dentry *dentry,struct nfs4_acl **acl) +nfsd4_get_nfs4_acl (struct svc_rqst *rqstp,struct dentry *dentry, +struct vfsmount *mnt,struct nfs4_acl **acl) {struct inode *inode = dentry->d_inode;int error =0 ;struct posix_acl *pacl =NULL , *dpacl =NULL ;unsigned int flags =0 ; - pacl =_get_posix_acl (dentry,POSIX_ACL_XATTR_ACCESS ); + pacl =_get_posix_acl (dentry, mnt,POSIX_ACL_XATTR_ACCESS );if (IS_ERR (pacl) &&PTR_ERR (pacl) == -ENODATA ) pacl =posix_acl_from_mode (inode->i_mode,GFP_KERNEL );if (IS_ERR (pacl)) {
@@ -514,7 +516,7 @@ nfsd4_get_nfs4_acl(struct svc_rqst *rqst }if (S_ISDIR (inode->i_mode)) { - dpacl =_get_posix_acl (dentry,POSIX_ACL_XATTR_DEFAULT ); + dpacl =_get_posix_acl (dentry, mnt,POSIX_ACL_XATTR_DEFAULT );if (IS_ERR (dpacl) &&PTR_ERR (dpacl) == -ENODATA ) dpacl =NULL ;else if (IS_ERR (dpacl)) {
@@ -1942,7 +1944,8 @@ nfsd_get_posix_acl(struct svc_fh *fhp, ireturn ERR_PTR (-EOPNOTSUPP ); } - size =nfsd_getxattr (fhp->fh_dentry, name, &value); + size =nfsd_getxattr (fhp->fh_dentry, fhp->fh_export->ex_mnt, name, + &value);if (size <0 )return ERR_PTR (size);
fs/xattr.c +8 -6
@@ -106,7 +106,8 @@ out:EXPORT_SYMBOL_GPL (vfs_setxattr);ssize_t -vfs_getxattr (struct dentry *dentry,char *name,void *value,size_t size) +vfs_getxattr (struct dentry *dentry,struct vfsmount *mnt,char *name, +void *value,size_t size) {struct inode *inode = dentry->d_inode;int error;
@@ -278,7 +279,8 @@ sys_fsetxattr(int fd, char __user *name,* Extended attribute GET operations */ static ssize_t -getxattr (struct dentry *d,char __user *name,void __user *value,size_t size) +getxattr (struct dentry *dentry,struct vfsmount *mnt,char __user *name, +void __user *value,size_t size) {ssize_t error;void *kvalue =NULL ;
@@ -298,7 +300,7 @@ getxattr(struct dentry *d, char __user *return -ENOMEM ; } - error =vfs_getxattr (d, kname, kvalue, size); + error =vfs_getxattr (dentry, mnt, kname, kvalue, size);if (error >0 ) {if (size &©_to_user (value, kvalue, error)) error = -EFAULT ;
@@ -321,7 +323,7 @@ sys_getxattr(char __user *path, char __u error =user_path_walk (path, &nd);if (error)return error; - error =getxattr (nd.dentry, name, value, size); + error =getxattr (nd.dentry, nd.mnt, name, value, size);path_release (&nd);return error; }
@@ -336,7 +338,7 @@ sys_lgetxattr(char __user *path, char __ error =user_path_walk_link (path, &nd);if (error)return error; - error =getxattr (nd.dentry, name, value, size); + error =getxattr (nd.dentry, nd.mnt, name, value, size);path_release (&nd);return error; }
@@ -351,7 +353,7 @@ sys_fgetxattr(int fd, char __user *name,if (!f)return error;audit_inode (NULL , f->f_path.dentry->d_inode); - error =getxattr (f->f_path.dentry, name, value, size); + error =getxattr (f->f_path.dentry, f->f_path.mnt, name, value, size);fput (f);return error; }
include/linux/nfsd/nfsd.h +2 -1
@@ -77,7 +77,8 @@ __be32 nfsd_setattr(struct svc_rqst *,#ifdef CONFIG_NFSD_V4 __be32 nfsd4_set_nfs4_acl (struct svc_rqst *,struct svc_fh *,struct nfs4_acl *); -int nfsd4_get_nfs4_acl (struct svc_rqst *,struct dentry *,struct nfs4_acl **); +int nfsd4_get_nfs4_acl (struct svc_rqst *,struct dentry *, +struct vfsmount *mnt,struct nfs4_acl **);#endif /* CONFIG_NFSD_V4 */ __be32 nfsd_create(struct svc_rqst *, struct svc_fh *, char *name, int len, struct iattr *attrs,
include/linux/xattr.h +2 -1
@@ -46,7 +46,8 @@ struct xattr_handler { size_t size, int flags); }; -ssize_t vfs_getxattr (struct dentry *,char *,void *,size_t ); +ssize_t vfs_getxattr (struct dentry *,struct vfsmount *,char *,void *, +size_t );ssize_t vfs_listxattr (struct dentry *d,char *list,size_t size);int vfs_setxattr (struct dentry *,struct vfsmount *,char *,void *,size_t ,int );
PATCH 24/44 Pass struct vfsmount to the inode_getxattr LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/xattr.c | 2 +- include/linux/security.h | 13 ++++++++----- security/dummy.c | 3 ++- security/selinux/hooks.c | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-)
fs/xattr.c +1 -1
@@ -116,7 +116,7 @@ vfs_getxattr(struct dentry *dentry, struif (error)return error; - error =security_inode_getxattr (dentry, name); + error =security_inode_getxattr (dentry, mnt, name);if (error)return error;
include/linux/security.h +8 -5
@@ -391,7 +391,7 @@ struct request_sock;* @value identified by @name for @dentry and @mnt. * @inode_getxattr: * Check permission before obtaining the extended attributes -* identified by @name for @dentry. +* identified by @name for @dentry and @mnt. * Return 0 if permission is granted. * @inode_listxattr: * Check permission before obtaining the list of extended attribute
@@ -1248,7 +1248,8 @@ struct security_operations {struct vfsmount *mnt, char *name, void *value, size_t size, int flags); -int (*inode_getxattr) (struct dentry *dentry,char *name); +int (*inode_getxattr) (struct dentry *dentry,struct vfsmount *mnt, +char *name);int (*inode_listxattr) (struct dentry *dentry);int (*inode_removexattr) (struct dentry *dentry,char *name);const char *(*inode_xattr_getsuffix) (void );
@@ -1782,11 +1783,12 @@ static inline void security_inode_post_s security_ops->inode_post_setxattr (dentry, mnt, name, value, size, flags); } -static inline int security_inode_getxattr (struct dentry *dentry,char *name) +static inline int security_inode_getxattr (struct dentry *dentry, +struct vfsmount *mnt,char *name) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_getxattr (dentry, name); +return security_ops->inode_getxattr (dentry, mnt, name); }static inline int security_inode_listxattr (struct dentry *dentry)
@@ -2487,7 +2489,8 @@ static inline void security_inode_post_s int flags) { } -static inline int security_inode_getxattr (struct dentry *dentry,char *name) +static inline int security_inode_getxattr (struct dentry *dentry, +struct vfsmount *mnt,char *name) {return 0 ; }
security/dummy.c +2 -1
@@ -368,7 +368,8 @@ static void dummy_inode_post_setxattr (s { } -static int dummy_inode_getxattr (struct dentry *dentry,char *name) +static int dummy_inode_getxattr (struct dentry *dentry, +struct vfsmount *mnt,char *name) {return 0 ; }
security/selinux/hooks.c +2 -1
@@ -2393,7 +2393,8 @@ static void selinux_inode_post_setxattr(return ; } -static int selinux_inode_getxattr (struct dentry *dentry,char *name) +static int selinux_inode_getxattr (struct dentry *dentry,struct vfsmount *mnt, +char *name) {return dentry_has_perm (current,NULL , dentry,FILE__GETATTR ); }
PATCH 25/44 Add a struct vfsmount parameter to vfs_listxattr()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/xattr.c | 25 ++++++++++++++----------- include/linux/xattr.h | 3 ++- 2 files changed, 16 insertions(+), 12 deletions(-)
fs/xattr.c +14 -11
@@ -143,18 +143,20 @@ vfs_getxattr(struct dentry *dentry, struEXPORT_SYMBOL_GPL (vfs_getxattr);ssize_t -vfs_listxattr (struct dentry *d,char *list,size_t size) +vfs_listxattr (struct dentry *dentry,struct vfsmount *mnt,char *list, +size_t size) { +struct inode *inode = dentry->d_inode;ssize_t error; - error =security_inode_listxattr (d); + error =security_inode_listxattr (dentry);if (error)return error; error = -EOPNOTSUPP ; -if (d->d_inode->i_op && d->d_inode->i_op->listxattr) { - error = d->d_inode->i_op->listxattr (d, list, size); - }else { - error =security_inode_listsecurity (d->d_inode, list, size); +if (inode->i_op && inode->i_op->listxattr) + error = inode->i_op->listxattr (dentry, list, size); +else { + error =security_inode_listsecurity (inode, list, size);if (size && error > size) error = -ERANGE ; }
@@ -362,7 +364,8 @@ sys_fgetxattr(int fd, char __user *name,* Extended attribute LIST operations */ static ssize_t -listxattr (struct dentry *d,char __user *list,size_t size) +listxattr (struct dentry *dentry,struct vfsmount *mnt,char __user *list, +size_t size) {ssize_t error;char *klist =NULL ;
@@ -375,7 +378,7 @@ listxattr(struct dentry *d, char __userreturn -ENOMEM ; } - error =vfs_listxattr (d, klist, size); + error =vfs_listxattr (dentry, mnt, klist, size);if (error >0 ) {if (size &©_to_user (list, klist, error)) error = -EFAULT ;
@@ -397,7 +400,7 @@ sys_listxattr(char __user *path, char __ error =user_path_walk (path, &nd);if (error)return error; - error =listxattr (nd.dentry, list, size); + error =listxattr (nd.dentry, nd.mnt, list, size);path_release (&nd);return error; }
@@ -411,7 +414,7 @@ sys_llistxattr(char __user *path, char _ error =user_path_walk_link (path, &nd);if (error)return error; - error =listxattr (nd.dentry, list, size); + error =listxattr (nd.dentry, nd.mnt, list, size);path_release (&nd);return error; }
@@ -426,7 +429,7 @@ sys_flistxattr(int fd, char __user *listif (!f)return error;audit_inode (NULL , f->f_path.dentry->d_inode); - error =listxattr (f->f_path.dentry, list, size); + error =listxattr (f->f_path.dentry, f->f_path.mnt, list, size);fput (f);return error; }
include/linux/xattr.h +2 -1
@@ -48,7 +48,8 @@ struct xattr_handler {ssize_t vfs_getxattr (struct dentry *,struct vfsmount *,char *,void *,size_t ); -ssize_t vfs_listxattr (struct dentry *d,char *list,size_t size); +ssize_t vfs_listxattr (struct dentry *d,struct vfsmount *,char *list, +size_t size);int vfs_setxattr (struct dentry *,struct vfsmount *,char *,void *,size_t ,int );int vfs_removexattr (struct dentry *,char *);
PATCH 26/44 Pass struct vfsmount to the inode_listxattr LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/xattr.c | 2 +- include/linux/security.h | 12 +++++++----- security/dummy.c | 2 +- security/selinux/hooks.c | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-)
fs/xattr.c +1 -1
@@ -149,7 +149,7 @@ vfs_listxattr(struct dentry *dentry, strstruct inode *inode = dentry->d_inode;ssize_t error; - error =security_inode_listxattr (dentry); + error =security_inode_listxattr (dentry, mnt);if (error)return error; error = -EOPNOTSUPP ;
include/linux/security.h +7 -5
@@ -395,7 +395,7 @@ struct request_sock;* Return 0 if permission is granted. * @inode_listxattr: * Check permission before obtaining the list of extended attribute -* names for @dentry. +* names for @dentry and @mnt. * Return 0 if permission is granted. * @inode_removexattr: * Check permission before removing the extended attribute
@@ -1250,7 +1250,7 @@ struct security_operations { size_t size, int flags);int (*inode_getxattr) (struct dentry *dentry,struct vfsmount *mnt,char *name); -int (*inode_listxattr) (struct dentry *dentry); +int (*inode_listxattr) (struct dentry *dentry,struct vfsmount *mnt);int (*inode_removexattr) (struct dentry *dentry,char *name);const char *(*inode_xattr_getsuffix) (void );int (*inode_getsecurity)(const struct inode *inode,const char *name,void *buffer,size_t size,int err);
@@ -1791,11 +1791,12 @@ static inline int security_inode_getxattreturn security_ops->inode_getxattr (dentry, mnt, name); } -static inline int security_inode_listxattr (struct dentry *dentry) +static inline int security_inode_listxattr (struct dentry *dentry, +struct vfsmount *mnt) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_listxattr (dentry); +return security_ops->inode_listxattr (dentry, mnt); }static inline int security_inode_removexattr (struct dentry *dentry,char *name)
@@ -2495,7 +2496,8 @@ static inline int security_inode_getxattreturn 0 ; } -static inline int security_inode_listxattr (struct dentry *dentry) +static inline int security_inode_listxattr (struct dentry *dentry, +struct vfsmount *mnt) {return 0 ; }
security/dummy.c +1 -1
@@ -374,7 +374,7 @@ static int dummy_inode_getxattr (structreturn 0 ; } -static int dummy_inode_listxattr (struct dentry *dentry) +static int dummy_inode_listxattr (struct dentry *dentry,struct vfsmount *mnt) {return 0 ; }
security/selinux/hooks.c +1 -1
@@ -2399,7 +2399,7 @@ static int selinux_inode_getxattr (strucreturn dentry_has_perm (current,NULL , dentry,FILE__GETATTR ); } -static int selinux_inode_listxattr (struct dentry *dentry) +static int selinux_inode_listxattr (struct dentry *dentry,struct vfsmount *mnt) {return dentry_has_perm (current,NULL , dentry,FILE__GETATTR ); }
PATCH 27/44 Add a struct vfsmount parameter to vfs_removexattr()
In reply to [email protected]The vfsmount will be passed down to the LSM hook so that LSMs can compute pathnames.
--- fs/nfsd/vfs.c | 7 ++++--- fs/xattr.c | 12 ++++++------ include/linux/xattr.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-)
fs/nfsd/vfs.c +4 -3
@@ -1957,6 +1957,7 @@ nfsd_get_posix_acl(struct svc_fh *fhp, iint nfsd_set_posix_acl (struct svc_fh *fhp,int type,struct posix_acl *acl) { +struct vfsmount *mnt;struct inode *inode = fhp->fh_dentry->d_inode;char *name;void *value =NULL ;
@@ -1989,14 +1990,14 @@ nfsd_set_posix_acl(struct svc_fh *fhp, i }else size =0 ; + mnt = fhp->fh_export->ex_mnt;if (size) - error =vfs_setxattr (fhp->fh_dentry, fhp->fh_export->ex_mnt, - name, value, size,0 ); + error =vfs_setxattr (fhp->fh_dentry, mnt, name, value, size,0 );else {if (!S_ISDIR (inode->i_mode) && type ==ACL_TYPE_DEFAULT ) error =0 ;else { - error =vfs_removexattr (fhp->fh_dentry, name); + error =vfs_removexattr (fhp->fh_dentry, mnt, name);if (error == -ENODATA ) error =0 ; }
fs/xattr.c +6 -6
@@ -165,7 +165,7 @@ vfs_listxattr(struct dentry *dentry, strEXPORT_SYMBOL_GPL (vfs_listxattr);int -vfs_removexattr (struct dentry *dentry,char *name) +vfs_removexattr (struct dentry *dentry,struct vfsmount *mnt,char *name) {struct inode *inode = dentry->d_inode;int error;
@@ -438,7 +438,7 @@ sys_flistxattr(int fd, char __user *list* Extended attribute REMOVE operations */ static long -removexattr (struct dentry *d,char __user *name) +removexattr (struct dentry *dentry,struct vfsmount *mnt,char __user *name) {int error;char kname[XATTR_NAME_MAX +1 ];
@@ -449,7 +449,7 @@ removexattr(struct dentry *d, char __useif (error <0 )return error; -return vfs_removexattr (d, kname); +return vfs_removexattr (dentry, mnt, kname); }asmlinkage long
@@ -461,7 +461,7 @@ sys_removexattr(char __user *path, char error =user_path_walk (path, &nd);if (error)return error; - error =removexattr (nd.dentry, name); + error =removexattr (nd.dentry, nd.mnt, name);path_release (&nd);return error; }
@@ -475,7 +475,7 @@ sys_lremovexattr(char __user *path, char error =user_path_walk_link (path, &nd);if (error)return error; - error =removexattr (nd.dentry, name); + error =removexattr (nd.dentry, nd.mnt, name);path_release (&nd);return error; }
@@ -492,7 +492,7 @@ sys_fremovexattr(int fd, char __user *nareturn error; dentry = f->f_path.dentry;audit_inode (NULL , dentry->d_inode); - error =removexattr (dentry, name); + error =removexattr (dentry, f->f_path.mnt, name);fput (f);return error; }
include/linux/xattr.h +1 -1
@@ -52,7 +52,7 @@ ssize_t vfs_listxattr(struct dentry *d, size_t size);int vfs_setxattr (struct dentry *,struct vfsmount *,char *,void *,size_t ,int ); -int vfs_removexattr (struct dentry *,char *); +int vfs_removexattr (struct dentry *,struct vfsmount *,char *);ssize_t generic_getxattr (struct dentry *dentry,const char *name,void *buffer,size_t size);ssize_t generic_listxattr (struct dentry *dentry,char *buffer,size_t buffer_size);
PATCH 28/44 Pass struct vfsmount to the inode_removexattr LSM hook
In reply to [email protected]This is needed for computing pathnames in the AppArmor LSM.
--- fs/xattr.c | 2 +- include/linux/security.h | 15 +++++++++------ security/commoncap.c | 3 ++- security/dummy.c | 3 ++- security/selinux/hooks.c | 3 ++- 5 files changed, 16 insertions(+), 10 deletions(-)
fs/xattr.c +1 -1
@@ -177,7 +177,7 @@ vfs_removexattr(struct dentry *dentry, sif (error)return error; - error =security_inode_removexattr (dentry, name); + error =security_inode_removexattr (dentry, mnt, name);if (error)return error;
include/linux/security.h +9 -6
@@ -50,7 +50,7 @@ extern int cap_bprm_set_security (structextern void cap_bprm_apply_creds (struct linux_binprm *bprm,int unsafe);extern int cap_bprm_secureexec (struct linux_binprm *bprm);extern int cap_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name,void *value,size_t size,int flags); -extern int cap_inode_removexattr (struct dentry *dentry,char *name); +extern int cap_inode_removexattr (struct dentry *dentry,struct vfsmount *mnt,char *name);extern int cap_task_post_setuid (uid_t old_ruid,uid_t old_euid,uid_t old_suid,int flags);extern void cap_task_reparent_to_init (struct task_struct *p);extern int cap_syslog (int type);
@@ -1251,7 +1251,8 @@ struct security_operations {int (*inode_getxattr) (struct dentry *dentry,struct vfsmount *mnt,char *name);int (*inode_listxattr) (struct dentry *dentry,struct vfsmount *mnt); -int (*inode_removexattr) (struct dentry *dentry,char *name); +int (*inode_removexattr) (struct dentry *dentry,struct vfsmount *mnt, +char *name);const char *(*inode_xattr_getsuffix) (void );int (*inode_getsecurity)(const struct inode *inode,const char *name,void *buffer,size_t size,int err);int (*inode_setsecurity)(struct inode *inode,const char *name,const void *value,size_t size,int flags);
@@ -1799,11 +1800,12 @@ static inline int security_inode_listxatreturn security_ops->inode_listxattr (dentry, mnt); } -static inline int security_inode_removexattr (struct dentry *dentry,char *name) +static inline int security_inode_removexattr (struct dentry *dentry, +struct vfsmount *mnt,char *name) {if (unlikely (IS_PRIVATE (dentry->d_inode)))return 0 ; -return security_ops->inode_removexattr (dentry, name); +return security_ops->inode_removexattr (dentry, mnt, name); }static inline const char *security_inode_xattr_getsuffix (void )
@@ -2502,9 +2504,10 @@ static inline int security_inode_listxatreturn 0 ; } -static inline int security_inode_removexattr (struct dentry *dentry,char *name) +static inline int security_inode_removexattr (struct dentry *dentry, +struct vfsmount *mnt,char *name) { -return cap_inode_removexattr (dentry, name); +return cap_inode_removexattr (dentry, mnt, name); }static inline const char *security_inode_xattr_getsuffix (void )
security/commoncap.c +2 -1
@@ -200,7 +200,8 @@ int cap_inode_setxattr(struct dentry *dereturn 0 ; } -int cap_inode_removexattr (struct dentry *dentry,char *name) +int cap_inode_removexattr (struct dentry *dentry,struct vfsmount *mnt, +char *name) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
security/dummy.c +2 -1
@@ -379,7 +379,8 @@ static int dummy_inode_listxattr (structreturn 0 ; } -static int dummy_inode_removexattr (struct dentry *dentry,char *name) +static int dummy_inode_removexattr (struct dentry *dentry,struct vfsmount *mnt, +char *name) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
security/selinux/hooks.c +2 -1
@@ -2404,7 +2404,8 @@ static int selinux_inode_listxattr (strureturn dentry_has_perm (current,NULL , dentry,FILE__GETATTR ); } -static int selinux_inode_removexattr (struct dentry *dentry, char *name) +static int selinux_inode_removexattr (struct dentry *dentry, + struct vfsmount *mnt, char *name) { if (strcmp(name, XATTR_NAME_SELINUX)) { if (!strncmp(name, XATTR_SECURITY_PREFIX,
PATCH 29/44 Fix __d_path() for lazy unmounts and make it unambiguous
In reply to [email protected]First, when __d_path() hits a lazily unmounted mount point, it tries to prepend the name of the lazily unmounted dentry to the path name. It gets this wrong, and also overwrites the slash that separates the name from the following pathname component. This patch fixes that; if a process was in directory /foo/bar and /foo got lazily unmounted, the old result was ``foobar'' (note the missing slash), while the new result with this patch is ``foo/bar''.
Second, it isn't always possible to tell from the __d_path() result whether the specified root and rootmnt (i.e., the chroot) was reached. We need an unambiguous result for AppArmor at least though, so we make sure that paths will only start with a slash if the path leads all the way up to the root.
We also add a @fail_deleted argument, which allows to get rid of some of the mess in sys_getcwd().
This patch leaves getcwd() and d_path() as they were before for everything except for bind-mounted directories; for them, it reports ``/foo/bar'' instead of ``foobar'' in the example described above.
--- fs/dcache.c | 169 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 98 insertions(+), 71 deletions(-)
fs/dcache.c +98 -71
@@ -1761,52 +1761,51 @@ shouldnt_be_hashed: }/** -* d_path - return the path of a dentry +* __d_path - return the path of a dentry * @dentry: dentry to report * @vfsmnt: vfsmnt to which the dentry belongs * @root: root dentry * @rootmnt: vfsmnt to which the root dentry belongs * @buffer: buffer to return value in * @buflen: buffer length +* @fail_deleted: what to return for deleted files * -* Convert a dentry into an ASCII path name. If the entry has been deleted +* Convert a dentry into an ASCII path name. If the entry has been deleted, +* then if @fail_deleted is true, ERR_PTR(-ENOENT) is returned. Otherwise, * the string " (deleted)" is appended. Note that this is ambiguous. * -* Returns the buffer or an error code if the path was too long. +* If @dentry is not connected to @root, the path returned will be relative +* (i.e., it will not start with a slash). * -* "buflen" should be positive. Caller holds the dcache_lock. +* Returns the buffer or an error code. */ -static char *__d_path (struct dentry *dentry,struct vfsmount *vfsmnt, -struct dentry *root,struct vfsmount *rootmnt, -char *buffer,int buflen) -{ -char * end = buffer+buflen; -char * retval; -int namelen; +static char *__d_path (struct dentry *dentry,struct vfsmount *vfsmnt, +struct dentry *root,struct vfsmount *rootmnt, +char *buffer,int buflen,int fail_deleted) +{ +int namelen, is_slash; + +if (buflen <2 ) +return ERR_PTR (-ENAMETOOLONG ); + buffer += --buflen; + *buffer ='\0' ; - *--end ='\0' ; - buflen--; +spin_lock (&dcache_lock);if (!IS_ROOT (dentry) &&d_unhashed (dentry)) { - buflen -=10 ; - end -=10 ; -if (buflen <0 ) +if (fail_deleted) { + buffer =ERR_PTR (-ENOENT ); + goto out; + } +if (buflen <10 ) goto Elong; -memcpy (end," (deleted)" ,10 ); + buflen -=10 ; + buffer -=10 ; +memcpy (buffer," (deleted)" ,10 ); } - -if (buflen <1 ) - goto Elong; -/* Get '/' right */ - retval = end-1 ; - *retval ='/' ; - -for (;;) { +while (dentry != root || vfsmnt != rootmnt) {struct dentry * parent; -if (dentry == root && vfsmnt == rootmnt) -break ;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) { -/* Global root? */ spin_lock (&vfsmount_lock);if (vfsmnt->mnt_parent == vfsmnt) {spin_unlock (&vfsmount_lock);
@@ -1820,33 +1819,72 @@ static char * __d_path( struct dentry *d parent = dentry->d_parent;prefetch (parent); namelen = dentry->d_name.len; - buflen -= namelen +1 ; -if (buflen <0 ) +if (buflen < namelen +1 ) goto Elong; - end -= namelen; -memcpy (end, dentry->d_name.name, namelen); - *--end ='/' ; - retval = end; + buflen -= namelen +1 ; + buffer -= namelen; +memcpy (buffer, dentry->d_name.name, namelen); + *--buffer ='/' ; dentry = parent; } +/* Get '/' right. */ +if (*buffer !='/' ) + *--buffer ='/' ; -return retval; +out: +spin_unlock (&dcache_lock); +return buffer; global_root: +/* +* We went past the (vfsmount, dentry) we were looking for and have +* either hit a root dentry, a lazily unmounted dentry, an +* unconnected dentry, or the file is on a pseudo filesystem. +*/ namelen = dentry->d_name.len; - buflen -= namelen; -if (buflen <0 ) + is_slash = (namelen ==1 && *dentry->d_name.name =='/' ); +if (is_slash || (dentry->d_sb->s_flags &MS_NOUSER )) { +/* +* Make sure we won't return a pathname starting with '/'. +* +* Historically, we also glue together the root dentry and +* remaining name for pseudo filesystems like pipefs, which +* have the MS_NOUSER flag set. This results in pathnames +* like "pipe:[439336]". +*/ +if (*buffer =='/' ) { + buffer++; + buflen++; + } +if (is_slash) + goto out; + } +if (buflen < namelen) goto Elong; - retval -= namelen-1 ;/* hit the slash */ -memcpy (retval, dentry->d_name.name, namelen); -return retval; + buffer -= namelen; +memcpy (buffer, dentry->d_name.name, namelen); + goto out; + Elong: -return ERR_PTR (-ENAMETOOLONG ); + buffer =ERR_PTR (-ENAMETOOLONG ); + goto out; +} + +static char *__connect_d_path (char *path,char *buffer) +{ +if (!IS_ERR (path) && *path !='/' ) { +/* Pretend that disconnected paths are hanging off the root. */ +if (path == buffer) + path =ERR_PTR (-ENAMETOOLONG ); +else + *--path ='/' ; + } +return path; }/* write full pathname into buffer and return start of pathname */ -char *d_path (struct dentry *dentry,struct vfsmount *vfsmnt, -char *buf,int buflen) +char *d_path (struct dentry *dentry,struct vfsmount *vfsmnt,char *buf, +int buflen) {char *res;struct vfsmount *rootmnt;
@@ -1866,9 +1904,8 @@ char * d_path(struct dentry *dentry, str rootmnt =mntget (current->fs->rootmnt); root =dget (current->fs->root);read_unlock (¤t->fs->lock); -spin_lock (&dcache_lock); - res =__d_path (dentry, vfsmnt, root, rootmnt, buf, buflen); -spin_unlock (&dcache_lock); + res =__d_path (dentry, vfsmnt, root, rootmnt, buf, buflen,0 ); + res =__connect_d_path (res, buf);dput (root);mntput (rootmnt);return res;
@@ -1915,10 +1952,10 @@ char *dynamic_dname(struct dentry *dentr*/ asmlinkage long sys_getcwd (char __user *buf,unsigned long size) { -int error; +int error, len;struct vfsmount *pwdmnt, *rootmnt;struct dentry *pwd, *root; -char *page = (char *)__get_free_page (GFP_USER ); +char *page = (char *)__get_free_page (GFP_USER ), *cwd;if (!page)return -ENOMEM ;
@@ -1930,29 +1967,19 @@ asmlinkage long sys_getcwd(char __user * root =dget (current->fs->root);read_unlock (¤t->fs->lock); - error = -ENOENT ; -/* Has the current directory has been unlinked? */ -spin_lock (&dcache_lock); -if (pwd->d_parent == pwd || !d_unhashed (pwd)) { -unsigned long len; -char * cwd; - - cwd =__d_path (pwd, pwdmnt, root, rootmnt, page,PAGE_SIZE ); -spin_unlock (&dcache_lock); - - error =PTR_ERR (cwd); -if (IS_ERR (cwd)) - goto out; - - error = -ERANGE ; - len =PAGE_SIZE + page - cwd; -if (len <= size) { - error = len; -if (copy_to_user (buf, cwd, len)) - error = -EFAULT ; - } - }else -spin_unlock (&dcache_lock); + cwd =__d_path (pwd, pwdmnt, root, rootmnt, page,PAGE_SIZE ,1 ); + cwd =__connect_d_path (cwd, page); + error =PTR_ERR (cwd); +if (IS_ERR (cwd)) + goto out; + + error = -ERANGE ; + len =PAGE_SIZE + page - cwd; +if (len <= size) { + error = len; +if (copy_to_user (buf, cwd, len)) + error = -EFAULT ; + } out:dput (pwd);
PATCH 30/44 Make d_path() consistent across mount operations
In reply to [email protected]The path that __d_path() computes can become slightly inconsistent when it races with mount operations: it grabs the vfsmount_lock when traversing mount points but immediately drops it again, only to re-grab it when it reaches the next mount point. The result is that the filename computed is not always consisent, and the file may never have had that name. (This is unlikely, but still possible.)
Fix this by grabbing the vfsmount_lock when the first mount point is reached, and holding onto it until the d_cache lookup is completed.
--- fs/dcache.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
fs/dcache.c +8 -6
@@ -1783,7 +1783,7 @@ static char *__d_path(struct dentry *den struct dentry *root, struct vfsmount *rootmnt, char *buffer, int buflen, int fail_deleted) { - int namelen, is_slash; + int namelen, is_slash, vfsmount_locked = 0;if (buflen <2 )return ERR_PTR (-ENAMETOOLONG );
@@ -1806,14 +1806,14 @@ static char *__d_path(struct dentry *denstruct dentry * parent;if (dentry == vfsmnt->mnt_root ||IS_ROOT (dentry)) { -spin_lock (&vfsmount_lock); -if (vfsmnt->mnt_parent == vfsmnt) { -spin_unlock (&vfsmount_lock); - goto global_root; +if (!vfsmount_locked) { +spin_lock (&vfsmount_lock); + vfsmount_locked =1 ; } +if (vfsmnt->mnt_parent == vfsmnt) + goto global_root; dentry = vfsmnt->mnt_mountpoint; vfsmnt = vfsmnt->mnt_parent; -spin_unlock (&vfsmount_lock);continue ; } parent = dentry->d_parent;
@@ -1832,6 +1832,8 @@ static char *__d_path(struct dentry *den *--buffer ='/' ; out: +if (vfsmount_locked) +spin_unlock (&vfsmount_lock);spin_unlock (&dcache_lock);return buffer;
PATCH 31/44 Add d_namespace_path() to compute namespace relative pathnames
In reply to [email protected]In AppArmor, we are interested in pathnames relative to the namespace root. This is the same as d_path() except for the root where the search ends. Add a function for computing the namespace-relative path.
--- fs/dcache.c | 6 +++--- fs/namespace.c | 27 +++++++++++++++++++++++++++ include/linux/dcache.h | 2 ++ include/linux/mount.h | 2 ++ 4 files changed, 34 insertions(+), 3 deletions(-)
fs/dcache.c +3 -3
@@ -1779,9 +1779,9 @@ shouldnt_be_hashed:* * Returns the buffer or an error code. */ -static char *__d_path (struct dentry *dentry,struct vfsmount *vfsmnt, -struct dentry *root,struct vfsmount *rootmnt, -char *buffer,int buflen,int fail_deleted) +char *__d_path (struct dentry *dentry,struct vfsmount *vfsmnt, +struct dentry *root,struct vfsmount *rootmnt, +char *buffer,int buflen,int fail_deleted) {int namelen, is_slash, vfsmount_locked =0 ;
fs/namespace.c +27 -0
@@ -1868,3 +1868,30 @@ void __put_mnt_ns(struct mnt_namespace *release_mounts (&umount_list);kfree (ns); } + +char *d_namespace_path (struct dentry *dentry,struct vfsmount *vfsmnt, +char *buf,int buflen) +{ +struct vfsmount *rootmnt, *nsrootmnt =NULL ; +struct dentry *root =NULL ; +char *res; + +read_lock (¤t->fs->lock); + rootmnt =mntget (current->fs->rootmnt); +read_unlock (¤t->fs->lock); +spin_lock (&vfsmount_lock); +if (rootmnt->mnt_ns) + nsrootmnt =mntget (rootmnt->mnt_ns->root); +spin_unlock (&vfsmount_lock); +mntput (rootmnt); +if (nsrootmnt) + root =dget (nsrootmnt->mnt_root); + res =__d_path (dentry, vfsmnt, root, nsrootmnt, buf, buflen,1 ); +dput (root); +mntput (nsrootmnt); +/* Prevent empty path for lazily unmounted filesystems. */ +if (!IS_ERR (res) && *res =='\0' ) + *--res ='.' ; +return res; +} +EXPORT_SYMBOL (d_namespace_path);
include/linux/dcache.h +2 -0
@@ -299,6 +299,8 @@ extern int d_validate(struct dentry *, s*/ extern char *dynamic_dname (struct dentry *,char *,int ,const char *, ...); +extern char *__d_path (struct dentry *,struct vfsmount *,struct dentry *, +struct vfsmount *,char *,int ,int );extern char *d_path (struct dentry *,struct vfsmount *,char *,int );/* Allocation counts.. */
include/linux/mount.h +2 -0
@@ -103,5 +103,7 @@ extern void shrink_submounts(struct vfsmextern spinlock_t vfsmount_lock;extern dev_t name_to_dev_t (char *name); +extern char *d_namespace_path (struct dentry *,struct vfsmount *,char *,int ); +#endif #endif /* _LINUX_MOUNT_H */
PATCH 32/44 Enable LSM hooks to distinguish operations on file descriptors from operations on pathnames
In reply to [email protected]Struct iattr already contains ia_file since commit cc4e69de from Miklos (which is related to commit befc649c). Use this to pass struct file down the setattr hooks. This allows LSMs to distinguish operations on file descriptors from operations on paths.
--- fs/nfsd/vfs.c | 12 +++++++----- fs/open.c | 16 +++++++++++----- include/linux/fs.h | 3 +++ 3 files changed, 21 insertions(+), 10 deletions(-)
fs/nfsd/vfs.c +7 -5
@@ -383,7 +383,7 @@ static ssize_t nfsd_getxattr(struct dent {ssize_t buflen; - buflen =vfs_getxattr (dentry, mnt, key,NULL ,0 ); + buflen =vfs_getxattr (dentry, mnt, key,NULL ,0 ,NULL );if (buflen <=0 )return buflen;
@@ -391,7 +391,7 @@ static ssize_t nfsd_getxattr(struct dentif (!*buf)return -ENOMEM ; - return vfs_getxattr(dentry, mnt, key, *buf, buflen); + return vfs_getxattr(dentry, mnt, key, *buf, buflen, NULL); }#endif
@@ -417,7 +417,7 @@ set_nfsv4_acl_one(struct dentry *dentry, goto out; } - error =vfs_setxattr (dentry, mnt, key, buf, len,0 ); + error =vfs_setxattr (dentry, mnt, key, buf, len,0 ,NULL ); out:kfree (buf);return error;
@@ -1992,12 +1992,14 @@ nfsd_set_posix_acl(struct svc_fh *fhp, i mnt = fhp->fh_export->ex_mnt;if (size) - error =vfs_setxattr (fhp->fh_dentry, mnt, name, value, size,0 ); + error =vfs_setxattr (fhp->fh_dentry, mnt, name, value, size,0 , +NULL );else {if (!S_ISDIR (inode->i_mode) && type ==ACL_TYPE_DEFAULT ) error =0 ;else { - error =vfs_removexattr (fhp->fh_dentry, mnt, name); + error =vfs_removexattr (fhp->fh_dentry, mnt, name, +NULL );if (error == -ENODATA ) error =0 ; }
fs/open.c +11 -5
@@ -522,6 +522,8 @@ asmlinkage long sys_fchmod(unsigned int mode = inode->i_mode; newattrs.ia_mode = (mode &S_IALLUGO ) | (inode->i_mode & ~S_IALLUGO ); newattrs.ia_valid =ATTR_MODE |ATTR_CTIME ; + newattrs.ia_valid |=ATTR_FILE ; + newattrs.ia_file = file; err =notify_change (dentry, file->f_path.mnt, &newattrs);mutex_unlock (&inode->i_mutex);
@@ -572,7 +574,7 @@ asmlinkage long sys_chmod(const char __u }static int chown_common (struct dentry * dentry,struct vfsmount *mnt, -uid_t user,gid_t group) +uid_t user,gid_t group,struct file *file) {struct inode * inode;int error;
@@ -600,6 +602,10 @@ static int chown_common(struct dentry * }if (!S_ISDIR (inode->i_mode)) newattrs.ia_valid |=ATTR_KILL_SUID |ATTR_KILL_SGID ; +if (file) { + newattrs.ia_file = file; + newattrs.ia_valid |=ATTR_FILE ; + }mutex_lock (&inode->i_mutex); error =notify_change (dentry, mnt, &newattrs);mutex_unlock (&inode->i_mutex);
@@ -615,7 +621,7 @@ asmlinkage long sys_chown(const char __u error =user_path_walk (filename, &nd);if (error) goto out; - error =chown_common (nd.dentry, nd.mnt, user, group); + error =chown_common (nd.dentry, nd.mnt, user, group,NULL );path_release (&nd); out:return error;
@@ -635,7 +641,7 @@ asmlinkage long sys_fchownat(int dfd, co error =__user_walk_fd (dfd, filename, follow, &nd);if (error) goto out; - error =chown_common (nd.dentry, nd.mnt, user, group); + error =chown_common (nd.dentry, nd.mnt, user, group,NULL );path_release (&nd); out:return error;
@@ -649,7 +655,7 @@ asmlinkage long sys_lchown(const char __ error =user_path_walk_link (filename, &nd);if (error) goto out; - error =chown_common (nd.dentry, nd.mnt, user, group); + error =chown_common (nd.dentry, nd.mnt, user, group,NULL );path_release (&nd); out:return error;
@@ -668,7 +674,7 @@ asmlinkage long sys_fchown(unsigned int dentry = file->f_path.dentry;audit_inode (NULL , dentry->d_inode); - error =chown_common (dentry, file->f_path.mnt, user, group); + error =chown_common (dentry, file->f_path.mnt, user, group, file);fput (file); out:return error;
include/linux/fs.h +3 -0
@@ -351,6 +351,9 @@ struct iattr {* Not an attribute, but an auxilary info for filesystems wanting to * implement an ftruncate() like method. NOTE: filesystem should * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). +* +* The LSM hooks also use this to distinguish operations on a file +* descriptors from operations on pathnames. */ struct file *ia_file; };
James Morris
maintainerRe: [AppArmor 32/44] Enable LSM hooks to distinguish operations on file descriptors from operations on pathnames
Quoted 4 lines · On Tue, 26 Jun 2007, [email protected] wrote:
Struct iattr already contains
ia_filesince commitcc4e69defrom Miklos (which is related to commitbefc649c). Use this to pass struct file down the setattr hooks. This allows LSMs to distinguish operations on file descriptors from operations on paths.
I'm not quite sure I understand this.
Why would you distinguish operations based on whether you have a pathname or an inode for an object ?
Are you trying to cater for the case where you're holding an open fd for a file which has been deleted, and thus has no pathname?
- James
Signature · 2 lines
James Morris <[email protected]>
Re: [AppArmor 32/44] Enable LSM hooks to distinguish operations on file descriptors from operations on pathnames
Quoted 2 lines · James Morris
Are you trying to cater for the case where you're holding an open fd for a file which has been deleted, and thus has no pathname?
Yes, see the AA_CHECK_FD flag in security/apparmor/main.c:aa_perm_dentry(). We want to distinguish between the following two cases:
- process performs an operation on an open file descriptor,
- process performs an operation on a pathname, and between the dentry lookup and the LSM permission check, the file gets deleted.
In the former case, we obviously want to continue giving the process access to his fd (the classical pattern: open temporary file; delete it so that it will self-recycle, continue using the open file descriptor).
In the latter case, The file still existed at the time of the lookup but not anymore at the time of the permission check. The file obviously doesn't have a filename anymore, so we cannot check permissions. If we granted access in that case, processes could bypass their profile permissions in that race window. We close the race by returning -ENOENT in that case, the same result as if the file had already been deleted before the lookup.
Andreas
Re: [AppArmor 32/44] Enable LSM hooks to distinguish operations on file descriptors from operations on pathnames
Quoted 16 lines · Andreas Gruenbacher
Quoted 2 lines · James Morris
Are you trying to cater for the case where you're holding an open fd for a file which has been deleted, and thus has no pathname?
Yes, see the
AA_CHECK_FDflag in security/apparmor/main.c:aa_perm_dentry(). We want to distinguish between the following two cases:- process performs an operation on an open file descriptor,
- process performs an operation on a pathname, and between the dentry lookup and the LSM permission check, the file gets deleted.
In the former case, we obviously want to continue giving the process access to his fd (the classical pattern: open temporary file; delete it so that it will self-recycle, continue using the open file descriptor).
Quoted 6 lines
In the latter case, The file still existed at the time of the lookup but not anymore at the time of the permission check. The file obviously doesn't have a filename anymore, so we cannot check permissions. If we granted access in that case, processes could bypass their profile permissions in that race window. We close the race by returning
-ENOENTin that case, the same result as if the file had already been deleted before the lookup.
So you don't actually need/use the struct file pointer; you just need a flag indicating whether or not access was by open file descriptor or by pathname?
And what does this mean for a process that has "changed hats"? Which might not be authorized to access the file anymore, even via an already opened descriptor.
Signature · 2 lines
Stephen Smalley National Security Agency
Re: [AppArmor 32/44] Enable LSM hooks to distinguish operations on file descriptors from operations on pathnames
Quoted 3 lines · Stephen Smalley
So you don't actually need/use the struct file pointer; you just need a flag indicating whether or not access was by open file descriptor or by pathname?
Yes, indeed. Given that struct iattr already defines ATTR_FILE and ia_file, I didn't see a good reason to invent something new when we can just use the existing mechanism.
Quoted 3 lines
And what does this mean for a process that has "changed hats"? Which might not be authorized to access the file anymore, even via an already opened descriptor.
If that file is still part of the namespace (i.e., not deleted), then access to the file descriptor is revalidated against the new profile ("changing hat" is switching to a different profile). If the file has already been deleted, then access is granted. There isn't that much of a difference between a deleted file and say, and anonymous pipe: both can be used by processes to communicate, and both will cease their lives once no longer referenced.
Later with IPC mediation, we'll obviously have to control which profiles may communicate with which other profiles. One possibility for that would be to map profiles and allowed communication channels to labels and access rules.
Andreas
PATCH 33/44 Pass struct file down the inode_*xattr security LSM hooks
In reply to [email protected]This allows LSMs to also distinguish between file descriptor and path access for the xattr operations. (The other relevant operations are covered by the setattr hook.)
--- fs/xattr.c | 58 ++++++++++++++++++++++++----------------------- include/linux/security.h | 53 +++++++++++++++++++++++++----------------- include/linux/xattr.h | 8 +++--- security/commoncap.c | 4 +-- security/dummy.c | 10 ++++---- security/selinux/hooks.c | 10 ++++---- 6 files changed, 80 insertions(+), 63 deletions(-)
fs/xattr.c +30 -28
@@ -70,7 +70,7 @@ xattr_permission(struct inode *inode, coint vfs_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name, -void *value,size_t size,int flags) +void *value,size_t size,int flags,struct file *file) {struct inode *inode = dentry->d_inode;int error;
@@ -80,7 +80,7 @@ vfs_setxattr(struct dentry *dentry, strureturn error;mutex_lock (&inode->i_mutex); - error =security_inode_setxattr (dentry, mnt, name, value, size, flags); + error =security_inode_setxattr (dentry, mnt, name, value, size, flags, file);if (error) goto out; error = -EOPNOTSUPP ;
@@ -107,7 +107,7 @@ EXPORT_SYMBOL_GPL(vfs_setxattr);ssize_t vfs_getxattr (struct dentry *dentry,struct vfsmount *mnt,char *name, -void *value,size_t size) +void *value,size_t size,struct file *file) {struct inode *inode = dentry->d_inode;int error;
@@ -116,7 +116,7 @@ vfs_getxattr(struct dentry *dentry, struif (error)return error; - error =security_inode_getxattr (dentry, mnt, name); + error =security_inode_getxattr (dentry, mnt, name, file);if (error)return error;
@@ -144,12 +144,12 @@ EXPORT_SYMBOL_GPL(vfs_getxattr);ssize_t vfs_listxattr (struct dentry *dentry,struct vfsmount *mnt,char *list, -size_t size) +size_t size,struct file *file) {struct inode *inode = dentry->d_inode;ssize_t error; - error =security_inode_listxattr (dentry, mnt); + error =security_inode_listxattr (dentry, mnt, file);if (error)return error; error = -EOPNOTSUPP ;
@@ -165,7 +165,8 @@ vfs_listxattr(struct dentry *dentry, strEXPORT_SYMBOL_GPL (vfs_listxattr);int -vfs_removexattr (struct dentry *dentry,struct vfsmount *mnt,char *name) +vfs_removexattr (struct dentry *dentry,struct vfsmount *mnt,char *name, +struct file *file) {struct inode *inode = dentry->d_inode;int error;
@@ -177,7 +178,7 @@ vfs_removexattr(struct dentry *dentry, sif (error)return error; - error =security_inode_removexattr (dentry, mnt, name); + error =security_inode_removexattr (dentry, mnt, name, file);if (error)return error;
@@ -197,7 +198,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);*/ static long setxattr (struct dentry *dentry,struct vfsmount *mnt,char __user *name, -void __user *value,size_t size,int flags) +void __user *value,size_t size,int flags,struct file *file) {int error;void *kvalue =NULL ;
@@ -224,7 +225,7 @@ setxattr(struct dentry *dentry, struct v } } - error =vfs_setxattr (dentry, mnt, kname, kvalue, size, flags); + error =vfs_setxattr (dentry, mnt, kname, kvalue, size, flags, file);kfree (kvalue);return error; }
@@ -239,7 +240,7 @@ sys_setxattr(char __user *path, char __u error =user_path_walk (path, &nd);if (error)return error; - error =setxattr (nd.dentry, nd.mnt, name, value, size, flags); + error =setxattr (nd.dentry, nd.mnt, name, value, size, flags,NULL );path_release (&nd);return error; }
@@ -254,7 +255,7 @@ sys_lsetxattr(char __user *path, char __ error =user_path_walk_link (path, &nd);if (error)return error; - error =setxattr (nd.dentry, nd.mnt, name, value, size, flags); + error =setxattr (nd.dentry, nd.mnt, name, value, size, flags,NULL );path_release (&nd);return error; }
@@ -272,7 +273,7 @@ sys_fsetxattr(int fd, char __user *name,return error; dentry = f->f_path.dentry;audit_inode (NULL , dentry->d_inode); - error =setxattr (dentry, f->f_vfsmnt, name, value, size, flags); + error =setxattr (dentry, f->f_vfsmnt, name, value, size, flags, f);fput (f);return error; }
@@ -282,7 +283,7 @@ sys_fsetxattr(int fd, char __user *name,*/ static ssize_t getxattr (struct dentry *dentry,struct vfsmount *mnt,char __user *name, -void __user *value,size_t size) +void __user *value,size_t size,struct file *file) {ssize_t error;void *kvalue =NULL ;
@@ -302,7 +303,7 @@ getxattr(struct dentry *dentry, struct vreturn -ENOMEM ; } - error =vfs_getxattr (dentry, mnt, kname, kvalue, size); + error =vfs_getxattr (dentry, mnt, kname, kvalue, size, file);if (error >0 ) {if (size &©_to_user (value, kvalue, error)) error = -EFAULT ;
@@ -325,7 +326,7 @@ sys_getxattr(char __user *path, char __u error =user_path_walk (path, &nd);if (error)return error; - error =getxattr (nd.dentry, nd.mnt, name, value, size); + error =getxattr (nd.dentry, nd.mnt, name, value, size,NULL );path_release (&nd);return error; }
@@ -340,7 +341,7 @@ sys_lgetxattr(char __user *path, char __ error =user_path_walk_link (path, &nd);if (error)return error; - error =getxattr (nd.dentry, nd.mnt, name, value, size); + error =getxattr (nd.dentry, nd.mnt, name, value, size,NULL );path_release (&nd);return error; }
@@ -355,7 +356,7 @@ sys_fgetxattr(int fd, char __user *name,if (!f)return error;audit_inode (NULL , f->f_path.dentry->d_inode); - error =getxattr (f->f_path.dentry, f->f_path.mnt, name, value, size); + error =getxattr (f->f_path.dentry, f->f_path.mnt, name, value, size, f);fput (f);return error; }
@@ -365,7 +366,7 @@ sys_fgetxattr(int fd, char __user *name,*/ static ssize_t listxattr (struct dentry *dentry,struct vfsmount *mnt,char __user *list, -size_t size) +size_t size,struct file *file) {ssize_t error;char *klist =NULL ;
@@ -378,7 +379,7 @@ listxattr(struct dentry *dentry, structreturn -ENOMEM ; } - error =vfs_listxattr (dentry, mnt, klist, size); + error =vfs_listxattr (dentry, mnt, klist, size, file);if (error >0 ) {if (size &©_to_user (list, klist, error)) error = -EFAULT ;
@@ -400,7 +401,7 @@ sys_listxattr(char __user *path, char __ error =user_path_walk (path, &nd);if (error)return error; - error =listxattr (nd.dentry, nd.mnt, list, size); + error =listxattr (nd.dentry, nd.mnt, list, size,NULL );path_release (&nd);return error; }
@@ -414,7 +415,7 @@ sys_llistxattr(char __user *path, char _ error =user_path_walk_link (path, &nd);if (error)return error; - error =listxattr (nd.dentry, nd.mnt, list, size); + error =listxattr (nd.dentry, nd.mnt, list, size,NULL );path_release (&nd);return error; }
@@ -429,7 +430,7 @@ sys_flistxattr(int fd, char __user *listif (!f)return error;audit_inode (NULL , f->f_path.dentry->d_inode); - error =listxattr (f->f_path.dentry, f->f_path.mnt, list, size); + error =listxattr (f->f_path.dentry, f->f_path.mnt, list, size, f);fput (f);return error; }
@@ -438,7 +439,8 @@ sys_flistxattr(int fd, char __user *list* Extended attribute REMOVE operations */ static long -removexattr (struct dentry *dentry,struct vfsmount *mnt,char __user *name) +removexattr (struct dentry *dentry,struct vfsmount *mnt,char __user *name, +struct file *file) {int error;char kname[XATTR_NAME_MAX +1 ];
@@ -449,7 +451,7 @@ removexattr(struct dentry *dentry, strucif (error <0 )return error; -return vfs_removexattr (dentry, mnt, kname); +return vfs_removexattr (dentry, mnt, kname, file); }asmlinkage long
@@ -461,7 +463,7 @@ sys_removexattr(char __user *path, char error =user_path_walk (path, &nd);if (error)return error; - error =removexattr (nd.dentry, nd.mnt, name); + error =removexattr (nd.dentry, nd.mnt, name,NULL );path_release (&nd);return error; }
@@ -475,7 +477,7 @@ sys_lremovexattr(char __user *path, char error =user_path_walk_link (path, &nd);if (error)return error; - error =removexattr (nd.dentry, nd.mnt, name); + error =removexattr (nd.dentry, nd.mnt, name,NULL );path_release (&nd);return error; }
@@ -492,7 +494,7 @@ sys_fremovexattr(int fd, char __user *nareturn error; dentry = f->f_path.dentry;audit_inode (NULL , dentry->d_inode); - error =removexattr (dentry, f->f_path.mnt, name); + error =removexattr (dentry, f->f_path.mnt, name, f);fput (f);return error; }
include/linux/security.h +32 -21
129 lines not on this page · raw message
include/linux/xattr.h +4 -4
@@ -47,12 +47,12 @@ struct xattr_handler { };ssize_t vfs_getxattr (struct dentry *,struct vfsmount *,char *,void *, -size_t ); +size_t ,struct file *);ssize_t vfs_listxattr (struct dentry *d,struct vfsmount *,char *list, -size_t size); +size_t size,struct file *);int vfs_setxattr (struct dentry *,struct vfsmount *,char *,void *,size_t , -int ); -int vfs_removexattr (struct dentry *,struct vfsmount *,char *); +int ,struct file *); +int vfs_removexattr (struct dentry *,struct vfsmount *,char *,struct file *);ssize_t generic_getxattr (struct dentry *dentry,const char *name,void *buffer,size_t size);ssize_t generic_listxattr (struct dentry *dentry,char *buffer,size_t buffer_size);
security/commoncap.c +2 -2
@@ -191,7 +191,7 @@ int cap_bprm_secureexec (struct linux_bi }int cap_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name, -void *value,size_t size,int flags) +void *value,size_t size,int flags,struct file *file) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
@@ -201,7 +201,7 @@ int cap_inode_setxattr(struct dentry *de }int cap_inode_removexattr (struct dentry *dentry,struct vfsmount *mnt, -char *name) +char *name,struct file *file) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
security/dummy.c +6 -4
@@ -352,7 +352,7 @@ static void dummy_inode_delete (struct istatic int dummy_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name,void *value,size_t size, -int flags) +int flags,struct file *file) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
@@ -369,18 +369,20 @@ static void dummy_inode_post_setxattr (s }static int dummy_inode_getxattr (struct dentry *dentry, -struct vfsmount *mnt,char *name) +struct vfsmount *mnt,char *name, +struct file *file) {return 0 ; } -static int dummy_inode_listxattr (struct dentry *dentry,struct vfsmount *mnt) +static int dummy_inode_listxattr (struct dentry *dentry,struct vfsmount *mnt, +struct file *file) {return 0 ; }static int dummy_inode_removexattr (struct dentry *dentry,struct vfsmount *mnt, -char *name) +char *name,struct file *file) { if (!strncmp(name, XATTR_SECURITY_PREFIX, sizeof(XATTR_SECURITY_PREFIX) - 1) &&
security/selinux/hooks.c +6 -4
@@ -2307,7 +2307,7 @@ static int selinux_inode_getattr(structstatic int selinux_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt,char *name,void *value,size_t size, -int flags) +int flags,struct file *file) {struct task_security_struct *tsec = current->security;struct inode *inode = dentry->d_inode;
@@ -2394,18 +2394,20 @@ static void selinux_inode_post_setxattr( }static int selinux_inode_getxattr (struct dentry *dentry,struct vfsmount *mnt, -char *name) +char *name,struct file *file) {return dentry_has_perm (current,NULL , dentry,FILE__GETATTR ); } -static int selinux_inode_listxattr (struct dentry *dentry,struct vfsmount *mnt) +static int selinux_inode_listxattr (struct dentry *dentry,struct vfsmount *mnt, +struct file *file) {return dentry_has_perm (current,NULL , dentry,FILE__GETATTR ); } static int selinux_inode_removexattr (struct dentry *dentry, - struct vfsmount *mnt, char *name) + struct vfsmount *mnt, char *name, + struct file *file) { if (strcmp(name, XATTR_NAME_SELINUX)) { if (!strncmp(name, XATTR_SECURITY_PREFIX,
PATCH 34/44 Factor out sysctl pathname code
In reply to [email protected]Convert the selinux sysctl pathname computation code into a standalone function.
--- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 27 +++++++++++++++++++++++++++ security/selinux/hooks.c | 35 +++++------------------------------ 3 files changed, 34 insertions(+), 30 deletions(-)
include/linux/sysctl.h +2 -0
@@ -963,6 +963,8 @@ extern int proc_doulongvec_minmax(ctl_taextern int proc_doulongvec_ms_jiffies_minmax (ctl_table *table,int ,struct file *,void __user *,size_t *,loff_t *); +extern char *sysctl_pathname (ctl_table *,char *,int ); +extern int do_sysctl (int __user *name,int nlen,void __user *oldval,size_t __user *oldlenp,void __user *newval,size_t newlen);
kernel/sysctl.c +27 -0
@@ -1110,6 +1110,33 @@ struct ctl_table_header *sysctl_head_nexreturn NULL ; } +char *sysctl_pathname (ctl_table *table,char *buffer,int buflen) +{ +if (buflen <1 ) +return NULL ; + buffer += --buflen; + *buffer ='\0' ; + +while (table) { +int namelen =strlen (table->procname); + +if (buflen < namelen +1 ) +return NULL ; + buflen -= namelen +1 ; + buffer -= namelen; +memcpy (buffer, table->procname, namelen); + *--buffer ='/' ; + table = table->parent; + } +if (buflen <4 ) +return NULL ; + buffer -=4 ; +memcpy (buffer,"/sys" ,4 ); + +return buffer; +} +EXPORT_SYMBOL (sysctl_pathname); +#ifdef CONFIG_SYSCTL_SYSCALL int do_sysctl (int __user *name,int nlen,void __user *oldval,size_t __user *oldlenp,void __user *newval,size_t newlen)
security/selinux/hooks.c +5 -30
@@ -1427,40 +1427,15 @@ static int selinux_capable(struct task_sstatic int selinux_sysctl_get_sid (ctl_table *table,u16 tclass,u32 *sid) { -int buflen, rc; -char *buffer, *path, *end; +char *buffer, *path; +int rc = -ENOMEM ; - rc = -ENOMEM ; buffer = (char *)__get_free_page (GFP_KERNEL );if (!buffer) goto out; - - buflen =PAGE_SIZE ; - end = buffer+buflen; - *--end ='\0' ; - buflen--; - path = end-1 ; - *path ='/' ; -while (table) { -const char *name = table->procname; -size_t namelen =strlen (name); - buflen -= namelen +1 ; -if (buflen <0 ) - goto out_free; - end -= namelen; -memcpy (end, name, namelen); - *--end ='/' ; - path = end; - table = table->parent; - } - buflen -=4 ; -if (buflen <0 ) - goto out_free; - end -=4 ; -memcpy (end,"/sys" ,4 ); - path = end; - rc =security_genfs_sid ("proc" , path, tclass, sid); -out_free: + path =sysctl_pathname (table, buffer,PAGE_SIZE ); +if (path) + rc =security_genfs_sid ("proc" , path, tclass, sid);free_page ((unsigned long )buffer); out:return rc;
PATCH 35/44 Allow permission functions to tell between parent and leaf checks
In reply to [email protected]Set the LOOKUP_CONTINUE flag when checking parent permissions. This allows permission functions to tell between parent and leaf checks.
--- fs/namei.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/namei.c +6 -0
@@ -1409,6 +1409,10 @@ static int may_delete(struct inode *dir,BUG_ON (victim->d_parent->d_inode != dir);audit_inode_child (victim->d_name.name, victim->d_inode, dir); +#if 0 +if (nd) + nd->flags |=LOOKUP_CONTINUE ; +#endif error =permission (dir,MAY_WRITE |MAY_EXEC ,NULL );if (error)return error;
@@ -1446,6 +1450,8 @@ static inline int may_create(struct inodreturn -EEXIST ;if (IS_DEADDIR (dir))return -ENOENT ; +if (nd) + nd->flags |=LOOKUP_CONTINUE ;return permission (dir,MAY_WRITE |MAY_EXEC , nd); }
PATCH 36/44 Export audit subsystem for use by modules
In reply to [email protected]Update kenel audit range comments to show AppArmor's registered range of 1500-1599. This range used to be reserved for LSPP but LSPP uses the SE Linux range and the range was given to AppArmor.
Adds necessary export symbols for audit subsystem routines. Changes audit_log_vformat to be externally visible (analagous to vprintf) Patch is not in mainline -- pending AppArmor code submission to lkml
--- include/linux/audit.h | 12 +++++++++++- kernel/audit.c | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-)
include/linux/audit.h +11 -1
@@ -33,7 +33,7 @@* 1200 - 1299 messages internal to the audit daemon * 1300 - 1399 audit event messages * 1400 - 1499 SE Linux use -* 1500 - 1599 kernel LSPP events +* 1500 - 1599 AppArmor use * 1600 - 1699 kernel crypto events * 1700 - 1799 kernel anomaly records * 1800 - 1999 future kernel use (maybe integrity labels and related events)
@@ -109,6 +109,13 @@#define AUDIT_MAC_IPSEC_ADDSPD 1413/* Add a XFRM policy */ #define AUDIT_MAC_IPSEC_DELSPD 1414/* Delete a XFRM policy */ +#define AUDIT_APPARMOR_AUDIT 1501/* AppArmor audited grants */ +#define AUDIT_APPARMOR_ALLOWED 1502/* Allowed Access for learning */ +#define AUDIT_APPARMOR_DENIED 1503 +#define AUDIT_APPARMOR_HINT 1504/* Process Tracking information */ +#define AUDIT_APPARMOR_STATUS 1505/* Changes in config */ +#define AUDIT_APPARMOR_ERROR 1506/* Internal AppArmor Errors */ +#define AUDIT_FIRST_KERN_ANOM_MSG 1700#define AUDIT_LAST_KERN_ANOM_MSG 1799#define AUDIT_ANOM_PROMISCUOUS 1700/* Device changed promiscuous mode */
@@ -499,6 +506,9 @@ extern void audit_log(struct audit_ __attribute__((format(printf,4,5)));extern struct audit_buffer *audit_log_start (struct audit_context *ctx,gfp_t gfp_mask,int type); +extern void audit_log_vformat (struct audit_buffer *ab, +const char *fmt,va_list args) + __attribute__((format (printf,2 ,0 )));extern void audit_log_format (struct audit_buffer *ab,const char *fmt, ...) __attribute__((format (printf,2 ,3 )));
kernel/audit.c +4 -2
@@ -1054,8 +1054,7 @@ static inline int audit_expand(struct au* will be called a second time. Currently, we assume that a printk * can't format message larger than 1024 bytes, so we don't either. */ -static void audit_log_vformat (struct audit_buffer *ab,const char *fmt, -va_list args) +void audit_log_vformat (struct audit_buffer *ab,const char *fmt,va_list args) {int len, avail;struct sk_buff *skb;
@@ -1311,3 +1310,6 @@ EXPORT_SYMBOL(audit_log_start);EXPORT_SYMBOL (audit_log_end);EXPORT_SYMBOL (audit_log_format);EXPORT_SYMBOL (audit_log); +EXPORT_SYMBOL_GPL (audit_log_vformat); +EXPORT_SYMBOL_GPL (audit_log_untrustedstring); +EXPORT_SYMBOL_GPL (audit_log_d_path);
PATCH 37/44 AppArmor: Main Part
In reply to [email protected]The underlying functions by which the AppArmor LSM hooks are implemented.
--- security/apparmor/main.c | 1255 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1255 insertions(+)
security/apparmor/main.c new file +1255 -0
@@ -0,0 +1,1255 @@ +/* +* Copyright (C) 2002-2007 Novell/SUSE +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +* AppArmor Core +*/ + +#include <linux/security.h> +#include <linux/namei.h> +#include <linux/audit.h> +#include <linux/mount.h> +#include <linux/ptrace.h> + +#include "apparmor.h" + +#include "inline.h" + +/* +* Table of capability names: we generate it from capabilities.h. +*/ +static const char *capability_names[] = { +#include "capability_names.h" +}; + +/* NULL complain profile +* +* Used when in complain mode, to emit Permitting messages for non-existant +* profiles and hats. This is necessary because of selective mode, in which +* case we need a complain null_profile and enforce null_profile +* +* The null_complain_profile cannot be statically allocated, because it +* can be associated to files which keep their reference even if apparmor is +* unloaded +*/ +struct aa_profile *null_complain_profile; + +/** +* aa_file_denied - check for @mask access on a file +* @profile: profile to check against +* @name: pathname of file +* @mask: permission mask requested for file +* +* Return %0 on success, or else the permissions in @mask that the +* profile denies. +*/ +static int aa_file_denied (struct aa_profile *profile,const char *name, +int mask) +{ +return (mask & ~aa_match (profile->file_rules, name)); +} + +/** +* aa_link_denied - check for permission to link a file +* @profile: profile to check against +* @link: pathname of link being created +* @target: pathname of target to be linked to +* @request_mask: the permissions subset valid only if link succeeds +* Return %0 on success, or else the permissions that the profile denies. +*/ +static int aa_link_denied (struct aa_profile *profile,const char *link, +const char *target,int *request_mask) +{ +int l_mode, t_mode, denied_mask; + + l_mode =aa_match (profile->file_rules, link); + t_mode =aa_match (profile->file_rules, target); + +/* Ignore valid-profile-transition flags. */ + l_mode &= ~AA_CHANGE_PROFILE ; + t_mode &= ~AA_CHANGE_PROFILE ; + + *request_mask = l_mode |AA_MAY_LINK ; + +/* Link always requires 'l' on the link, a subset of the +* target's 'r', 'w', 'x', and 'm' permissions on the link, and +* if the link has 'x', an exact match of all the execute flags +* ('i', 'u', 'U', 'p', 'P'). +*/ +#define RWXM (MAY_READ | MAY_WRITE | MAY_EXEC | AA_EXEC_MMAP) + denied_mask = ~l_mode &AA_MAY_LINK ; +if (l_mode &RWXM ) + denied_mask |= (l_mode & ~AA_MAY_LINK ) & ~t_mode; +else + denied_mask |= t_mode |AA_MAY_LINK ; +if (denied_mask &AA_EXEC_MODIFIERS ) + denied_mask |=MAY_EXEC ; + +#undef RWXM + +return denied_mask; +} + +/** +* aa_get_name - compute the pathname of a file +* @dentry: dentry of the file +* @mnt: vfsmount of the file +* @buffer: buffer that aa_get_name() allocated +* @check: AA_CHECK_DIR is set if the file is a directory +* +* Returns a pointer to the beginning of the pathname (which usually differs +* from the beginning of the buffer), or an error code. +* +* We need @check to indicate whether the file is a directory or not because +* the file may not yet exist, and so we cannot check the inode's file type. +*/ +static char *aa_get_name (struct dentry *dentry,struct vfsmount *mnt, +char **buffer,int check) +{ +char *name; +int is_dir, size =256 ; + + is_dir = (check &AA_CHECK_DIR ) ?1 :0 ; + +for (;;) { +char *buf =kmalloc (size,GFP_KERNEL ); +if (!buf) +return ERR_PTR (-ENOMEM ); + + name =d_namespace_path (dentry, mnt, buf, size - is_dir); +if (!IS_ERR (name)) { +if (name[0 ] !='/' ) { +/* +* This dentry is not connected to the +* namespace root -- reject access. +*/ +kfree (buf); +return ERR_PTR (-ENOENT ); + } +if (is_dir && name[1 ] !='\0' ) { +/* +* Append "/" to the pathname. The root +* directory is a special case; it already +* ends in slash. +*/ + buf[size -2 ] ='/' ; + buf[size -1 ] ='\0' ; + } + + *buffer = buf; +return name; + } +if (PTR_ERR (name) != -ENAMETOOLONG ) +return name; + +kfree (buf); + size <<=1 ; +if (size > apparmor_path_max) +return ERR_PTR (-ENAMETOOLONG ); + } +} + +static inline void aa_put_name_buffer (char *buffer) +{ +kfree (buffer); +} + +/** +* aa_perm_dentry - check if @profile allows @mask for a file +* @profile: profile to check against +* @dentry: dentry of the file +* @mnt: vfsmount o the file +* @sa: audit context +* @mask: requested profile permissions +* @check: kind of check to perform +* +* Returns 0 upon success, or else an error code. +* +* @check indicates the file type, and whether the file was accessed through +* an open file descriptor (AA_CHECK_FD) or not. +*/ +static int aa_perm_dentry (struct aa_profile *profile,struct dentry *dentry, +struct vfsmount *mnt,struct aa_audit *sa,int check) +{ +int error; +char *buffer =NULL ; + + sa->name =aa_get_name (dentry, mnt, &buffer, check); + +if (IS_ERR (sa->name)) { +/* +* deleted files are given a pass on permission checks when +* accessed through a file descriptor. +*/ +if (PTR_ERR (sa->name) == -ENOENT && (check &AA_CHECK_FD )) + sa->denied_mask =0 ; +else + sa->denied_mask =PTR_ERR (sa->name); + sa->name =NULL ; + }else + sa->denied_mask =aa_file_denied (profile, sa->name, + sa->requested_mask); + +if (!sa->denied_mask) + sa->error_code =0 ; + + error =aa_audit (profile, sa); +aa_put_name_buffer (buffer); + +return error; +} + +/** +* alloc_null_complain_profile - Allocate the global null_complain_profile. +* +* Return %0 (success) or error (-%ENOMEM) +*/ +int alloc_null_complain_profile (void ) +{ + null_complain_profile =alloc_aa_profile (); +if (!null_complain_profile) + goto fail; + + null_complain_profile->name = +kstrdup ("null-complain-profile" ,GFP_KERNEL ); + +if (!null_complain_profile->name) + goto fail; + + null_complain_profile->flags.complain =1 ; + +return 0 ; + +fail: +/* free_aa_profile is safe for freeing partially constructed objects */ +free_aa_profile (null_complain_profile); + null_complain_profile =NULL ; + +return -ENOMEM ; +} + +/** +* free_null_complain_profile - Free null profiles +*/ +void free_null_complain_profile (void ) +{ +aa_put_profile (null_complain_profile); + null_complain_profile =NULL ; +} + +static void aa_audit_file_mask (struct audit_buffer *ab,const char *name, +int mask) +{ +char mask_str[10 ], *m = mask_str; + +if (mask &AA_EXEC_MMAP ) + *m++ ='m' ; +if (mask &MAY_READ ) + *m++ ='r' ; +if (mask &MAY_WRITE ) + *m++ ='w' ; +if (mask & (MAY_EXEC |AA_EXEC_MODIFIERS )) { +if (mask &AA_EXEC_UNSAFE ) { +if (mask &AA_EXEC_INHERIT ) + *m++ ='i' ; +if (mask &AA_EXEC_UNCONFINED ) + *m++ ='u' ; +if (mask &AA_EXEC_PROFILE ) + *m++ ='p' ; + }else { +if (mask &AA_EXEC_INHERIT ) + *m++ ='I' ; +if (mask &AA_EXEC_UNCONFINED ) + *m++ ='U' ; +if (mask &AA_EXEC_PROFILE ) + *m++ ='P' ; + } +if (mask &MAY_EXEC ) + *m++ ='x' ; + } +if (mask &AA_MAY_LINK ) + *m++ ='l' ; + *m++ ='\0' ; + +audit_log_format (ab," %s=\"%s\"" , name, mask_str); +} + +/** +* aa_audit - Log an audit event to the audit subsystem +* @profile: profile to check against +* @sa: audit event +* @audit_cxt: audit context to log message to +* @type: audit event number +*/ +static int aa_audit_base (struct aa_profile *profile,struct aa_audit *sa, +struct audit_context *audit_cxt,int type) +{ +struct audit_buffer *ab =NULL ; + + ab =audit_log_start (audit_cxt, sa->gfp_mask, type); + +if (!ab) { +AA_ERROR ("Unable to log event (%d) to audit subsys\n" , + type); +/* don't fail operations in complain mode even if logging +* fails */ +return type ==AUDIT_APPARMOR_ALLOWED ?0 : -ENOMEM ; + } + +if (sa->operation) +audit_log_format (ab,"operation=\"%s\"" , sa->operation); + +if (sa->info) +audit_log_format (ab," info=\"%s\"" , sa->info); + +if (sa->requested_mask) +aa_audit_file_mask (ab,"requested_mask" , sa->requested_mask); + +if (sa->denied_mask) +aa_audit_file_mask (ab,"denied_mask" , sa->denied_mask); + +if (sa->iattr) { +struct iattr *iattr = sa->iattr; + +audit_log_format (ab," attribute=\"%s%s%s%s%s%s%s\"" , + iattr->ia_valid &ATTR_MODE ?"mode," :"" , + iattr->ia_valid &ATTR_UID ?"uid," :"" , + iattr->ia_valid &ATTR_GID ?"gid," :"" , + iattr->ia_valid &ATTR_SIZE ?"size," :"" , + iattr->ia_valid & (ATTR_ATIME |ATTR_ATIME_SET ) ? +"atime," :"" , + iattr->ia_valid & (ATTR_MTIME |ATTR_MTIME_SET ) ? +"mtime," :"" , + iattr->ia_valid &ATTR_CTIME ?"ctime," :"" ); + } + +if (sa->task) +audit_log_format (ab," task=%d" , sa->task); + +if (sa->parent) +audit_log_format (ab," parent=%d" , sa->parent); + +if (sa->name) { +audit_log_format (ab," name=" ); +audit_log_untrustedstring (ab, sa->name); + } + +if (sa->name2) { +audit_log_format (ab," name2=" ); +audit_log_untrustedstring (ab, sa->name2); + } + +if (sa->cookie) +audit_log_format (ab," cookie=%llu" , sa->cookie); + +audit_log_format (ab," pid=%d" , current->pid); + +if (profile) { +audit_log_format (ab," profile=" ); +audit_log_untrustedstring (ab, profile->name); + } + +audit_log_end (ab); + +return type ==AUDIT_APPARMOR_ALLOWED ?0 : sa->error_code; +} + +/** +* aa_audit_syscallreject - Log a syscall rejection to the audit subsystem +* @profile: profile to check against +* @gfp: memory allocation flags +* @msg: string describing syscall being rejected +*/ +int aa_audit_syscallreject (struct aa_profile *profile,gfp_t gfp, +const char *msg) +{ +struct aa_audit sa; +memset (&sa,0 ,sizeof (sa)); + sa.operation ="syscall" ; + sa.name = msg; + sa.gfp_mask = gfp; + sa.error_code = -EPERM ; + +return aa_audit_base (profile, &sa, current->audit_context, +AUDIT_APPARMOR_DENIED ); +} + +int aa_audit_message (struct aa_profile *profile,struct aa_audit *sa, +int type) +{ +struct audit_context *audit_cxt; + + audit_cxt = apparmor_logsyscall ? current->audit_context :NULL ; +return aa_audit_base (profile, sa, audit_cxt, type); +} + +void aa_audit_hint (struct aa_profile *profile,struct aa_audit *sa) +{ +aa_audit_message (profile, sa,AUDIT_APPARMOR_HINT ); +} + +void aa_audit_status (struct aa_profile *profile,struct aa_audit *sa) +{ +aa_audit_message (profile, sa,AUDIT_APPARMOR_STATUS ); +} + +int aa_audit_reject (struct aa_profile *profile,struct aa_audit *sa) +{ +return aa_audit_message (profile, sa,AUDIT_APPARMOR_DENIED ); +} + +/** +* aa_audit - Log an audit event to the audit subsystem +* @profile: profile to check against +* @sa: audit event +*/ +int aa_audit (struct aa_profile *profile,struct aa_audit *sa) +{ +int type =AUDIT_APPARMOR_DENIED ; +struct audit_context *audit_cxt; + +if (likely (!sa->error_code)) { +if (likely (!PROFILE_AUDIT (profile))) +/* nothing to log */ +return 0 ; +else + type =AUDIT_APPARMOR_AUDIT ; + }else if (PROFILE_COMPLAIN (profile)) { + type =AUDIT_APPARMOR_ALLOWED ; + } + + audit_cxt = apparmor_logsyscall ? current->audit_context :NULL ; +return aa_audit_base (profile, sa, audit_cxt, type); +} + +/** +* aa_attr - check if attribute change is allowed +* @profile: profile to check against +* @dentry: dentry of the file to check +* @mnt: vfsmount of the file to check +* @iattr: attribute changes requested +*/ +int aa_attr (struct aa_profile *profile,struct dentry *dentry, +struct vfsmount *mnt,struct iattr *iattr) +{ +struct inode *inode = dentry->d_inode; +int error, check; +struct aa_audit sa; + +memset (&sa,0 ,sizeof (sa)); + sa.operation ="setattr" ; + sa.gfp_mask =GFP_KERNEL ; + sa.iattr = iattr; + sa.requested_mask =MAY_WRITE ; + sa.error_code = -EACCES ; + + check =0 ; +if (inode &&S_ISDIR (inode->i_mode)) + check |=AA_CHECK_DIR ; +if (iattr->ia_valid &ATTR_FILE ) + check |=AA_CHECK_FD ; + + error =aa_perm_dentry (profile, dentry, mnt, &sa, check); + +return error; +} + +/** +* aa_perm_xattr - check if xattr attribute change is allowed +* @profile: profile to check against +* @dentry: dentry of the file to check +* @mnt: vfsmount of the file to check +* @operation: xattr operation being done +* @mask: access mode requested +* @check: kind of check to perform +*/ +int aa_perm_xattr (struct aa_profile *profile,const char *operation, +struct dentry *dentry,struct vfsmount *mnt,int mask, +int check) +{ +struct inode *inode = dentry->d_inode; +int error; +struct aa_audit sa; + +memset (&sa,0 ,sizeof (sa)); + sa.operation = operation; + sa.gfp_mask =GFP_KERNEL ; + sa.requested_mask = mask; + sa.error_code = -EACCES ; + +if (inode &&S_ISDIR (inode->i_mode)) + check |=AA_CHECK_DIR ; + + error =aa_perm_dentry (profile, dentry, mnt, &sa, check); + +return error; +} + +/** +* aa_perm - basic apparmor permissions check +* @profile: profile to check against +* @dentry: dentry of the file to check +* @mnt: vfsmount of the file to check +* @mask: access mode requested +* @check: kind of check to perform +* +* Determine if access @mask for the file is authorized by @profile. +* Returns 0 on success, or else an error code. +*/ +int aa_perm (struct aa_profile *profile,const char *operation, +struct dentry *dentry,struct vfsmount *mnt,int mask,int check) +{ +struct aa_audit sa; +int error =0 ; + +if (mask ==0 ) + goto out; + +memset (&sa,0 ,sizeof (sa)); + sa.operation = operation; + sa.gfp_mask =GFP_KERNEL ; + sa.requested_mask = mask; + sa.error_code = -EACCES ; + + error =aa_perm_dentry (profile, dentry, mnt, &sa, check); + +out: +return error; +} + +/** +* aa_perm_dir +* @profile: profile to check against +* @dentry: dentry of directory to check +* @mnt: vfsmount of directory to check +* @operation: directory operation being performed +* @mask: access mode requested +* +* Determine if directory operation (make/remove) for dentry is authorized +* by @profile. +* Returns 0 on success, or else an error code. +*/ +int aa_perm_dir (struct aa_profile *profile,const char *operation, +struct dentry *dentry,struct vfsmount *mnt,int mask) +{ +struct aa_audit sa; + +memset (&sa,0 ,sizeof (sa)); + sa.operation = operation; + sa.gfp_mask =GFP_KERNEL ; + sa.requested_mask = mask; + sa.error_code = -EACCES ; + +return aa_perm_dentry (profile, dentry, mnt, &sa,AA_CHECK_DIR ); +} + +int aa_perm_path (struct aa_profile *profile,const char *operation, +const char *name,int mask) +{ +struct aa_audit sa; + +memset (&sa,0 ,sizeof (sa)); + sa.operation = operation; + sa.gfp_mask =GFP_KERNEL ; + sa.requested_mask = mask; + sa.name = name; + + sa.denied_mask =aa_file_denied (profile, name, mask); + sa.error_code = sa.denied_mask ? -EACCES :0 ; + +return aa_audit (profile, &sa); +} + +/** +* aa_capability - test permission to use capability +* @cxt: aa_task_context with profile to check against +* @cap: capability to be tested +* +* Look up capability in profile capability set. +* Returns 0 on success, or else an error code. +*/ +int aa_capability (struct aa_task_context *cxt,int cap) +{ +int error =cap_raised (cxt->profile->capabilities, cap) ?0 : -EPERM ; +struct aa_audit sa; + +/* test if cap has alread been logged */ +if (cap_raised (cxt->caps_logged, cap)) { +if (PROFILE_COMPLAIN (cxt->profile)) + error =0 ; +return error; + }else +/* don't worry about rcu replacement of the cxt here. +* caps_logged is a cache to reduce the occurence of +* duplicate messages in the log. The worst that can +* happen is duplicate capability messages shows up in +* the audit log +*/ +cap_raise (cxt->caps_logged, cap); + +memset (&sa,0 ,sizeof (sa)); + sa.operation ="capable" ; + sa.gfp_mask =GFP_ATOMIC ; + sa.name = capability_names[cap]; + sa.error_code = error; + + error =aa_audit (cxt->profile, &sa); + +return error; +} + +/* must be used inside rcu_read_lock or task_lock */ +int aa_may_ptrace (struct aa_task_context *cxt,struct aa_profile *tracee) +{ +if (!cxt || cxt->profile == tracee) +return 0 ; +return aa_capability (cxt,CAP_SYS_PTRACE ); +} + +/** +* aa_link - hard link check +* @profile: profile to check against +* @link: dentry of link being created +* @link_mnt: vfsmount of link being created +* @target: dentry of link target +* @target_mnt: vfsmunt of link target +* +* Returns 0 on success, or else an error code. +*/ +int aa_link (struct aa_profile *profile, +struct dentry *link,struct vfsmount *link_mnt, +struct dentry *target,struct vfsmount *target_mnt) +{ +int error, check =0 ; +struct aa_audit sa; +char *buffer =NULL , *buffer2 =NULL ; + +memset (&sa,0 ,sizeof (sa)); + sa.operation ="inode_link" ; + sa.gfp_mask =GFP_KERNEL ; + sa.name =aa_get_name (link, link_mnt, &buffer, check); + sa.name2 =aa_get_name (target, target_mnt, &buffer2, check); + +if (IS_ERR (sa.name)) { + sa.error_code =PTR_ERR (sa.name); + sa.name =NULL ; + } +if (IS_ERR (sa.name2)) { + sa.error_code =PTR_ERR (sa.name2); + sa.name2 =NULL ; + } + +if (sa.name && sa.name2) { + sa.requested_mask =AA_MAY_LINK ; + sa.denied_mask =aa_link_denied (profile, sa.name, sa.name2, + &sa.requested_mask); + sa.error_code = sa.denied_mask ? -EACCES :0 ; + } + + error =aa_audit (profile, &sa); + +aa_put_name_buffer (buffer); +aa_put_name_buffer (buffer2); + +return error; +} + +/******************************* +* Global task related functions +*******************************/ + +/** +* aa_clone - initialize the task context for a new task +* @child: task that is being created +* +* Returns 0 on success, or else an error code. +*/ +int aa_clone (struct task_struct *child) +{ +struct aa_task_context *cxt, *child_cxt; +struct aa_profile *profile; + +if (!aa_task_context (current)) +return 0 ; + child_cxt =aa_alloc_task_context (GFP_KERNEL ); +if (!child_cxt) +return -ENOMEM ; + +repeat: + profile =aa_get_profile (current); +if (profile) { +lock_profile (profile); + cxt =aa_task_context (current); +if (unlikely (profile->isstale || !cxt || + cxt->profile != profile)) { +/** +* Race with profile replacement or removal, or with +* task context removal. +*/ +unlock_profile (profile); +aa_put_profile (profile); + goto repeat; + } + +/* No need to grab the child's task lock here. */ +aa_change_task_context (child, child_cxt, profile, + cxt->cookie, cxt->previous_profile); +unlock_profile (profile); + +if (APPARMOR_COMPLAIN (child_cxt) && + profile == null_complain_profile) { +struct aa_audit sa; +memset (&sa,0 ,sizeof (sa)); + sa.operation ="clone" ; + sa.gfp_mask =GFP_KERNEL ; + sa.task = child->pid; +aa_audit_hint (profile, &sa); + } +aa_put_profile (profile); + }else +aa_free_task_context (child_cxt); + +return 0 ; +} + +static struct aa_profile * +aa_register_find (struct aa_profile *profile,const char *name,int mandatory, +int complain,struct aa_audit *sa) +{ +struct aa_profile *new_profile; + +/* Locate new profile */ + new_profile =aa_find_profile (name); +if (new_profile) { +AA_DEBUG ("%s: setting profile %s\n" , + __FUNCTION__, new_profile->name); + }else if (mandatory && profile) { + sa->info ="mandatory profile missing" ; + sa->denied_mask =MAY_EXEC ; +if (complain) { +aa_audit_hint (profile, sa); + profile =aa_dup_profile (null_complain_profile); + }else { +aa_audit_reject (profile, sa); +return ERR_PTR (-EACCES );/* was -EPERM */ + } + }else { +/* Only way we can get into this code is if task +* is unconfined. +*/ +AA_DEBUG ("%s: No profile found for exec image '%s'\n" , + __FUNCTION__, + name); + } +return new_profile; +} + +/** +* aa_register - register a new program +* @bprm: binprm of program being registered +* +* Try to register a new program during execve(). This should give the +* new program a valid aa_task_context if confined. +*/ +int aa_register (struct linux_binprm *bprm) +{ +const char *filename; +char *buffer =NULL ; +struct file *filp = bprm->file; +struct aa_profile *profile, *old_profile, *new_profile =NULL ; +int exec_mode =AA_EXEC_UNSAFE , complain =0 ; +struct aa_audit sa; + +AA_DEBUG ("%s\n" , __FUNCTION__); + + filename =aa_get_name (filp->f_dentry, filp->f_vfsmnt, &buffer,0 ); +if (IS_ERR (filename)) { +AA_ERROR ("%s: Failed to get filename" , __FUNCTION__); +return -ENOENT ; + } + +memset (&sa,0 ,sizeof (sa)); + sa.operation ="exec" ; + sa.gfp_mask =GFP_KERNEL ; + sa.name = filename; + sa.requested_mask =MAY_EXEC ; + +repeat: + profile =aa_get_profile (current); +if (profile) { + complain =PROFILE_COMPLAIN (profile); + +/* Confined task, determine what mode inherit, unconfined or +* mandatory to load new profile +*/ + exec_mode =aa_match (profile->file_rules, filename); + +if (exec_mode & (MAY_EXEC |AA_EXEC_MODIFIERS )) { +switch (exec_mode & (MAY_EXEC |AA_EXEC_MODIFIERS )) { +case MAY_EXEC |AA_EXEC_INHERIT : +AA_DEBUG ("%s: INHERIT %s\n" , + __FUNCTION__, + filename); +/* nothing to be done here */ + goto cleanup; + +case MAY_EXEC |AA_EXEC_UNCONFINED : +AA_DEBUG ("%s: UNCONFINED %s\n" , + __FUNCTION__, + filename); + +/* detach current profile */ + new_profile =NULL ; +break ; + +case MAY_EXEC |AA_EXEC_PROFILE : +AA_DEBUG ("%s: PROFILE %s\n" , + __FUNCTION__, + filename); + new_profile =aa_register_find (profile, + filename, +1 , complain, + &sa); +break ; + } + + }else if (complain) { +/* There was no entry in calling profile +* describing mode to execute image in. +* Drop into null-profile (disabling secure exec). +*/ + new_profile =aa_dup_profile (null_complain_profile); + exec_mode |=AA_EXEC_UNSAFE ; + }else { + sa.denied_mask =MAY_EXEC ; +aa_audit_reject (profile, &sa); + new_profile =ERR_PTR (-EPERM ); + } + }else { +/* Unconfined task, load profile if it exists */ + new_profile =aa_register_find (NULL , filename,0 ,0 , &sa); +if (new_profile ==NULL ) + goto cleanup; + } + +if (IS_ERR (new_profile)) + goto cleanup; + + old_profile =__aa_replace_profile (current, new_profile); +if (IS_ERR (old_profile)) { +aa_put_profile (new_profile); +aa_put_profile (profile); +if (PTR_ERR (old_profile) == -ESTALE ) + goto repeat; +if (PTR_ERR (old_profile) == -EPERM ) { + sa.denied_mask =MAY_EXEC ; + sa.info ="unable to set profile due to ptrace" ; + sa.task = current->parent->pid; +aa_audit_reject (profile, &sa); + } + new_profile = old_profile; + goto cleanup; + } +aa_put_profile (old_profile); +aa_put_profile (profile); + +/* Handle confined exec. +* Can be at this point for the following reasons: +* 1. unconfined switching to confined +* 2. confined switching to different confinement +* 3. confined switching to unconfined +* +* Cases 2 and 3 are marked as requiring secure exec +* (unless policy specified "unsafe exec") +*/ +if (!(exec_mode &AA_EXEC_UNSAFE )) { +unsigned long bprm_flags; + + bprm_flags =AA_SECURE_EXEC_NEEDED ; + bprm->security = (void *) + ((unsigned long )bprm->security | bprm_flags); + } + +if (complain && new_profile == null_complain_profile) { + sa.requested_mask =0 ; + sa.name =NULL ; + sa.info ="set profile" ; +aa_audit_hint (new_profile, &sa); + } +cleanup: +aa_put_name_buffer (buffer); +if (IS_ERR (new_profile)) +return PTR_ERR (new_profile); +aa_put_profile (new_profile); +return 0 ; +} + +/** +* aa_release - release a task context +* @task: task being released +* +* This is called after a task has exited and the parent has reaped it. +*/ +void aa_release (struct task_struct *task) +{ +struct aa_task_context *cxt; +struct aa_profile *profile; +/* +* While the task context is still on a profile's task context +* list, another process could replace the profile under us, +* leaving us with a locked profile that is no longer attached +* to this task. So after locking the profile, we check that +* the profile is still attached. The profile lock is +* sufficient to prevent the replacement race so we do not lock +* the task. +* +* Use lock subtyping to avoid lockdep reporting a false irq +* possible inversion between the task_lock and profile_lock +* +* We also avoid taking the task_lock here because lock_dep +* would report another false {softirq-on-W} potential irq_lock +* inversion. +* +* If the task does not have a profile attached we are safe; +* nothing can race with us at this point. +*/ + +repeat: + profile =aa_get_profile (task); +if (profile) { +lock_profile_nested (profile, aa_lock_task_release); + cxt =aa_task_context (task); +if (unlikely (!cxt || cxt->profile != profile)) { +unlock_profile (profile); +aa_put_profile (profile); + goto repeat; + } +aa_change_task_context (task,NULL ,NULL ,0 ,NULL ); +unlock_profile (profile); +aa_put_profile (profile); + } +} + +static int do_change_profile (struct aa_profile *expected,const char *name, +u64 cookie,int restore,struct aa_audit *sa) +{ +struct aa_profile *profile =NULL , *old_profile =NULL , + *previous_profile =NULL ; +struct aa_task_context *new_cxt, *cxt; +int error =0 ; + + sa->name = name; + + new_cxt =aa_alloc_task_context (GFP_KERNEL ); +if (!new_cxt) +return -ENOMEM ; + + profile =aa_find_profile (name); +if (!profile && !restore) + profile =aa_dup_profile (null_complain_profile); + + cxt =lock_task_and_profiles (current, profile); +if (!cxt) { + error = -EPERM ; + goto out; + } + old_profile = cxt->profile; + +if (cxt->profile != expected || (profile && profile->isstale)) { + error = -ESTALE ; + goto out; + } + +if (cxt->previous_profile) { +if (cxt->cookie != cookie) { + error = -EACCES ; + sa->info ="killing process" ; +aa_audit_reject (cxt->profile, sa); +/* terminate process */ + (void )send_sig_info (SIGKILL ,NULL , current); + goto out; + } + +if (!restore) + previous_profile = cxt->previous_profile; + }else + previous_profile = cxt->profile; + +if ((current->ptrace &PT_PTRACED ) &&aa_may_ptrace (cxt, profile)) { + error = -EACCES ; + goto out; + } + +if (profile == null_complain_profile) { +if (APPARMOR_COMPLAIN (cxt)) { +aa_audit_hint (cxt->profile, sa); + }else { + error = -ENOENT ; + goto out; + } + } + +if (APPARMOR_AUDIT (cxt)) +aa_audit_message (cxt->profile, sa,AUDIT_APPARMOR_AUDIT ); + +if (!restore && cookie) +aa_change_task_context (current, new_cxt, profile, cookie, + previous_profile); +else +/* either return to previous_profile, or a permanent change */ +aa_change_task_context (current, new_cxt, profile,0 ,NULL ); + +out: +if (aa_task_context (current) != new_cxt) +aa_free_task_context (new_cxt); +task_unlock (current); +unlock_both_profiles (old_profile, profile); +aa_put_profile (profile); +return error; +} + + +/** +* aa_change_profile - change profile to/from previous stored profile +* @name: name of profile to change to +* @cookie: magic value to validate the profile change +* +* Change to new profile @name, and store the @cookie in the current task +* context. If the new @name is %NULL and the @cookie matches that +* stored in the current task context, return to the previous profile. +* +* Returns %0 on success, error otherwise. +*/ +int aa_change_profile (const char *name,u64 cookie) +{ +struct aa_task_context *cxt; +struct aa_profile *profile, *previous_profile; +struct aa_audit sa; +int error =0 ; + +memset (&sa,0 ,sizeof (sa)); + sa.gfp_mask =GFP_ATOMIC ; + sa.cookie = cookie; + sa.operation ="change_profile" ; + +repeat: +task_lock (current); + cxt =aa_task_context (current); +if (!cxt) { +task_unlock (current); +return -EPERM ; + } + profile =aa_dup_profile (cxt->profile); + previous_profile =aa_dup_profile (cxt->previous_profile); +task_unlock (current); + +if (name) { +if (profile != null_complain_profile && + !(aa_match (profile->file_rules, name) & +AA_CHANGE_PROFILE )) { +/* no permission to transition to profile @name */ +aa_put_profile (profile); +return -EACCES ; + } + error =do_change_profile (profile, name, cookie,0 , &sa); + }else if (previous_profile) + error =do_change_profile (profile, previous_profile->name, + cookie,1 , &sa); +/* else ignore restores when there is no saved profile */ + +aa_put_profile (previous_profile); +aa_put_profile (profile); +if (error == -ESTALE ) + goto repeat; + +return error; +} + +/** +* aa_change_hat - change hat to/from subprofile +* @hat_name: hat to change to +* @cookie: magic value to validate the hat change +* +* Change to new @hat_name, and store the @hat_magic in the current task +* context. If the new @hat_name is %NULL and the @cookie matches that +* stored in the current task context and is not 0, return to the top level +* profile. +* Returns %0 on success, error otherwise. +*/ +int aa_change_hat (const char *hat_name,u64 cookie) +{ +struct aa_task_context *cxt; +struct aa_profile *profile, *previous_profile; +struct aa_audit sa; +int error =0 ; + +memset (&sa,0 ,sizeof (sa)); + sa.gfp_mask =GFP_ATOMIC ; + sa.cookie = cookie; + sa.operation ="change_hat" ; + +repeat: +task_lock (current); + cxt =aa_task_context (current); +if (!cxt) { +task_unlock (current); +return -EPERM ; + } + profile =aa_dup_profile (cxt->profile); + previous_profile =aa_dup_profile (cxt->previous_profile); +task_unlock (current); + +if (hat_name) { +char *name, *profile_name; +if (previous_profile) + profile_name = previous_profile->name; +else + profile_name = profile->name; + + name =kmalloc (strlen (hat_name) +3 +strlen (profile_name), +GFP_KERNEL ); +if (!name) { + error = -ENOMEM ; + goto out; + } +sprintf (name,"%s//%s" , profile_name, hat_name); + error =do_change_profile (profile, name, cookie,0 , &sa); +kfree (name); + }else if (previous_profile) + error =do_change_profile (profile, previous_profile->name, + cookie,1 , &sa); +/* else ignore restores when there is no saved profile */ + +out: +aa_put_profile (previous_profile); +aa_put_profile (profile); +if (error == -ESTALE ) + goto repeat; + +return error; +} + +/** +* __aa_replace_profile - replace a task's profile +* @task: task to switch the profile of +* @profile: profile to switch to +* +* Returns a handle to the previous profile upon success, or else an +* error code. +*/ +struct aa_profile *__aa_replace_profile (struct task_struct *task, +struct aa_profile *profile) +{ +struct aa_task_context *cxt, *new_cxt =NULL ; +struct aa_profile *old_profile =NULL ; + +if (profile) { + new_cxt =aa_alloc_task_context (GFP_KERNEL ); +if (!new_cxt) +return ERR_PTR (-ENOMEM ); + } + + cxt =lock_task_and_profiles (task, profile); +if (unlikely (profile && profile->isstale)) { +task_unlock (task); +unlock_both_profiles (profile, cxt ? cxt->profile :NULL ); +aa_free_task_context (new_cxt); +return ERR_PTR (-ESTALE ); + } + +if ((current->ptrace &PT_PTRACED ) &&aa_may_ptrace (cxt, profile)) { +task_unlock (task); +unlock_both_profiles (profile, cxt ? cxt->profile :NULL ); +aa_free_task_context (new_cxt); +return ERR_PTR (-EPERM ); + } + +if (cxt) + old_profile =aa_dup_profile (cxt->profile); +aa_change_task_context (task, new_cxt, profile,0 ,NULL ); + +task_unlock (task); +unlock_both_profiles (profile, old_profile); +return old_profile; +} + +/** +* lock_task_and_profiles - lock the task and confining profiles and @profile +* @task: task to lock +* @profile: extra profile to lock in addition to the current profile +* +* Handle the spinning on locking to make sure the task context and +* profile are consistent once all locks are aquired. +* +* return the aa_task_context currently confining the task. The task lock +* will be held whether or not the task is confined. +*/ +struct aa_task_context * +lock_task_and_profiles (struct task_struct *task,struct aa_profile *profile) +{ +struct aa_task_context *cxt; +struct aa_profile *old_profile =NULL ; + +rcu_read_lock (); +repeat: + cxt =aa_task_context (task); +if (cxt) + old_profile = cxt->profile; + +lock_both_profiles (profile, old_profile); +task_lock (task); + +/* check for race with profile transition, replacement or removal */ +if (unlikely (cxt !=aa_task_context (task))) { +task_unlock (task); +unlock_both_profiles (profile, old_profile); + old_profile =NULL ; + goto repeat; + } +rcu_read_unlock (); +return cxt; +} + +static void free_aa_task_context_rcu_callback (struct rcu_head *head) +{ +struct aa_task_context *cxt; + + cxt = container_of(head, struct aa_task_context, rcu); +aa_free_task_context (cxt); +} + +/** +* aa_change_task_context - switch a task to use a new context and profile +* @task: task that is having its task context changed +* @new_cxt: new task context to use after the switch +* @profile: new profile to use after the switch +* @cookie: magic value to switch to +* @previous_profile: profile the task can return to +*/ +void aa_change_task_context (struct task_struct *task, +struct aa_task_context *new_cxt, +struct aa_profile *profile,u64 cookie, +struct aa_profile *previous_profile) +{ +struct aa_task_context *old_cxt =aa_task_context (task); + +if (old_cxt) { +list_del_init (&old_cxt->list); +call_rcu (&old_cxt->rcu, free_aa_task_context_rcu_callback); + } +if (new_cxt) { +/* clear the caps_logged cache, so that new profile/hat has +* chance to emit its own set of cap messages */ + new_cxt->caps_logged =CAP_EMPTY_SET ; + new_cxt->cookie = cookie; + new_cxt->task = task; + new_cxt->profile =aa_dup_profile (profile); + new_cxt->previous_profile =aa_dup_profile (previous_profile); +list_move (&new_cxt->list, &profile->task_contexts); + } +rcu_assign_pointer (task->security, new_cxt); +}
PATCH 38/44 AppArmor: Module and LSM hooks
In reply to [email protected]Module parameters, LSM hooks, initialization and teardown.
--- security/apparmor/lsm.c | 817 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 817 insertions(+)
security/apparmor/lsm.c new file +817 -0
@@ -0,0 +1,817 @@ +/* +* Copyright (C) 1998-2007 Novell/SUSE +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +* AppArmor LSM interface +*/ + +#include <linux/security.h> +#include <linux/module.h> +#include <linux/mm.h> +#include <linux/mman.h> +#include <linux/mount.h> +#include <linux/namei.h> +#include <linux/ctype.h> +#include <linux/sysctl.h> +#include <linux/audit.h> + +#include "apparmor.h" +#include "inline.h" + +static int param_set_aabool (const char *val,struct kernel_param *kp); +static int param_get_aabool (char *buffer,struct kernel_param *kp); +#define param_check_aabool (name, p) __param_check(name, p, int) + +static int param_set_aauint (const char *val,struct kernel_param *kp); +static int param_get_aauint (char *buffer,struct kernel_param *kp); +#define param_check_aauint (name, p) __param_check(name, p, int) + +/* Flag values, also controllable via /sys/module/apparmor/parameters +* We define special types as we want to do additional mediation. +* +* Complain mode -- in complain mode access failures result in auditing only +* and task is allowed access. audit events are processed by userspace to +* generate policy. Default is 'enforce' (0). +* Value is also togglable per profile and referenced when global value is +* enforce. +*/ +int apparmor_complain =0 ; +module_param_named (complain, apparmor_complain, aabool,S_IRUSR |S_IWUSR ); +MODULE_PARM_DESC (apparmor_complain,"Toggle AppArmor complain mode" ); + +/* Debug mode */ +int apparmor_debug =0 ; +module_param_named (debug, apparmor_debug, aabool,S_IRUSR |S_IWUSR ); +MODULE_PARM_DESC (apparmor_debug,"Toggle AppArmor debug mode" ); + +/* Audit mode */ +int apparmor_audit =0 ; +module_param_named (audit, apparmor_audit, aabool,S_IRUSR |S_IWUSR ); +MODULE_PARM_DESC (apparmor_audit,"Toggle AppArmor audit mode" ); + +/* Syscall logging mode */ +int apparmor_logsyscall =0 ; +module_param_named (logsyscall, apparmor_logsyscall, aabool,S_IRUSR |S_IWUSR ); +MODULE_PARM_DESC (apparmor_logsyscall,"Toggle AppArmor logsyscall mode" ); + +/* Maximum pathname length before accesses will start getting rejected */ +unsigned int apparmor_path_max =2 *PATH_MAX ; +module_param_named (path_max, apparmor_path_max, aauint,S_IRUSR |S_IWUSR ); +MODULE_PARM_DESC (apparmor_path_max,"Maximum pathname length allowed" ); + +static int param_set_aabool (const char *val,struct kernel_param *kp) +{ +if (aa_task_context (current)) +return -EPERM ; +return param_set_bool (val, kp); +} + +static int param_get_aabool (char *buffer,struct kernel_param *kp) +{ +if (aa_task_context (current)) +return -EPERM ; +return param_get_bool (buffer, kp); +} + +static int param_set_aauint (const char *val,struct kernel_param *kp) +{ +if (aa_task_context (current)) +return -EPERM ; +return param_set_uint (val, kp); +} + +static int param_get_aauint (char *buffer,struct kernel_param *kp) +{ +if (aa_task_context (current)) +return -EPERM ; +return param_get_uint (buffer, kp); +} + +static int aa_reject_syscall (struct task_struct *task,gfp_t flags, +const char *name) +{ +struct aa_profile *profile =aa_get_profile (task); +int error =0 ; + +if (profile) { + error =aa_audit_syscallreject (profile, flags, name); +aa_put_profile (profile); + } + +return error; +} + +static int apparmor_ptrace (struct task_struct *parent, +struct task_struct *child) +{ +struct aa_task_context *cxt; +int error =0 ; + +/* +* parent can ptrace child when +* - parent is unconfined +* - parent & child are in the same namespace && +* - parent is in complain mode +* - parent and child are confined by the same profile +* - parent profile has CAP_SYS_PTRACE +*/ + +rcu_read_lock (); + cxt =aa_task_context (parent); +if (cxt) { +if (parent->nsproxy != child->nsproxy) { +struct aa_audit sa; +memset (&sa,0 ,sizeof (sa)); + sa.operation ="ptrace" ; + sa.gfp_mask =GFP_ATOMIC ; + sa.parent = parent->pid; + sa.task = child->pid; + sa.info ="different namespaces" ; +aa_audit_reject (cxt->profile, &sa); + error = -EPERM ; + }else { +struct aa_task_context *child_cxt = +aa_task_context (child); + + error =aa_may_ptrace (cxt, child_cxt ? + child_cxt->profile :NULL ); +if (PROFILE_COMPLAIN (cxt->profile)) { +struct aa_audit sa; +memset (&sa,0 ,sizeof (sa)); + sa.operation ="ptrace" ; + sa.gfp_mask =GFP_ATOMIC ; + sa.parent = parent->pid; + sa.task = child->pid; +aa_audit_hint (cxt->profile, &sa); + } + } + } +rcu_read_unlock (); + +return error; +} + +static int apparmor_capable (struct task_struct *task,int cap) +{ +int error; + +/* cap_capable returns 0 on success, else -EPERM */ + error =cap_capable (task, cap); + +if (!error) { +struct aa_task_context *cxt; + +rcu_read_lock (); + cxt =aa_task_context (task); +if (cxt) + error =aa_capability (cxt, cap); +rcu_read_unlock (); + } + +return error; +} + +static int apparmor_sysctl (struct ctl_table *table,int op) +{ +struct aa_profile *profile =aa_get_profile (current); +int error =0 ; + +if (profile) { +char *buffer, *name; +int mask; + + mask =0 ; +if (op &4 ) + mask |=MAY_READ ; +if (op &2 ) + mask |=MAY_WRITE ; + + error = -ENOMEM ; + buffer = (char *)__get_free_page (GFP_KERNEL ); +if (!buffer) + goto out; + name =sysctl_pathname (table, buffer,PAGE_SIZE ); +if (name && name - buffer >=5 ) { + name -=5 ; +memcpy (name,"/proc" ,5 ); + error =aa_perm_path (profile,"sysctl" , name, mask); + } +free_page ((unsigned long )buffer); + } + +out: +return error; +} + +static int apparmor_bprm_set_security (struct linux_binprm *bprm) +{ +/* handle capability bits with setuid, etc */ +cap_bprm_set_security (bprm); +/* already set based on script name */ +if (bprm->sh_bang) +return 0 ; +return aa_register (bprm); +} + +static int apparmor_bprm_secureexec (struct linux_binprm *bprm) +{ +int ret =cap_bprm_secureexec (bprm); + +if (!ret && (unsigned long )bprm->security &AA_SECURE_EXEC_NEEDED ) { +AA_DEBUG ("%s: secureexec required for %s\n" , + __FUNCTION__, bprm->filename); + ret =1 ; + } + +return ret; +} + +static int apparmor_sb_mount (char *dev_name,struct nameidata *nd,char *type, +unsigned long flags,void *data) +{ +return aa_reject_syscall (current,GFP_KERNEL ,"mount" ); +} + +static int apparmor_umount (struct vfsmount *mnt,int flags) +{ +return aa_reject_syscall (current,GFP_KERNEL ,"umount" ); +} + +static int apparmor_inode_mkdir (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mask) +{ +struct aa_profile *profile; +int error =0 ; + +if (!mnt || !mediated_filesystem (dir)) + goto out; + + profile =aa_get_profile (current); + +if (profile) + error =aa_perm_dir (profile,"inode_mkdir" , dentry, mnt, +MAY_WRITE ); + +aa_put_profile (profile); + +out: +return error; +} + +static int apparmor_inode_rmdir (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt) +{ +struct aa_profile *profile; +int error =0 ; + +if (!mnt || !mediated_filesystem (dir)) + goto out; + + profile =aa_get_profile (current); + +if (profile) + error =aa_perm_dir (profile,"inode_rmdir" , dentry, mnt, +MAY_WRITE ); + +aa_put_profile (profile); + +out: +return error; +} + +static int aa_permission (struct inode *inode,const char *operation, +struct dentry *dentry,struct vfsmount *mnt, +int mask,int check) +{ +int error =0 ; + +if (mnt &&mediated_filesystem (inode)) { +struct aa_profile *profile; + + profile =aa_get_profile (current); +if (profile) + error =aa_perm (profile, operation, dentry, mnt, mask, + check); +aa_put_profile (profile); + } +return error; +} + +static int apparmor_inode_create (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mask) +{ +return aa_permission (dir,"inode_create" , dentry, mnt,MAY_WRITE ,0 ); +} + +static int apparmor_inode_link (struct dentry *old_dentry, +struct vfsmount *old_mnt,struct inode *dir, +struct dentry *new_dentry, +struct vfsmount *new_mnt) +{ +int error =0 ; +struct aa_profile *profile; + +if (!old_mnt || !new_mnt || !mediated_filesystem (dir)) + goto out; + + profile =aa_get_profile (current); + +if (profile) + error =aa_link (profile, new_dentry, new_mnt, + old_dentry, old_mnt); + +aa_put_profile (profile); + +out: +return error; +} + +static int apparmor_inode_unlink (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt) +{ +int check =0 ; + +if (S_ISDIR (dentry->d_inode->i_mode)) + check |=AA_CHECK_DIR ; +return aa_permission (dir,"inode_unlink" , dentry, mnt,MAY_WRITE , + check); +} + +static int apparmor_inode_symlink (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,const char *old_name) +{ +return aa_permission (dir,"inode_symlink" , dentry, mnt,MAY_WRITE ,0 ); +} + +static int apparmor_inode_mknod (struct inode *dir,struct dentry *dentry, +struct vfsmount *mnt,int mode,dev_t dev) +{ +return aa_permission (dir,"inode_mknod" , dentry, mnt,MAY_WRITE ,0 ); +} + +static int apparmor_inode_rename (struct inode *old_dir, +struct dentry *old_dentry, +struct vfsmount *old_mnt, +struct inode *new_dir, +struct dentry *new_dentry, +struct vfsmount *new_mnt) +{ +struct aa_profile *profile; +int error =0 ; + +if ((!old_mnt && !new_mnt) || !mediated_filesystem (old_dir)) + goto out; + + profile =aa_get_profile (current); + +if (profile) { +struct inode *inode = old_dentry->d_inode; +int check =0 ; + +if (inode &&S_ISDIR (inode->i_mode)) + check |=AA_CHECK_DIR ; +if (old_mnt) + error =aa_perm (profile,"inode_rename" , old_dentry, + old_mnt,MAY_READ |MAY_WRITE , check); + +if (!error && new_mnt) { + error =aa_perm (profile,"inode_rename" , new_dentry, + new_mnt,MAY_WRITE , check); + } + } + +aa_put_profile (profile); + +out: +return error; +} + +static int apparmor_inode_permission (struct inode *inode,int mask, +struct nameidata *nd) +{ +int check =0 ; + +if (!nd || nd->flags & (LOOKUP_PARENT |LOOKUP_CONTINUE )) +return 0 ; + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC ); +if (S_ISDIR (inode->i_mode)) { + check |=AA_CHECK_DIR ; +/* allow traverse accesses to directories */ + mask &= ~MAY_EXEC ; + } +return aa_permission (inode,"inode_permission" , nd->dentry, nd->mnt, + mask, check); +} + +static int apparmor_inode_setattr (struct dentry *dentry,struct vfsmount *mnt, +struct iattr *iattr) +{ +int error =0 ; + +if (!mnt) + goto out; + +if (mediated_filesystem (dentry->d_inode)) { +struct aa_profile *profile; + + profile =aa_get_profile (current); +/* +* Mediate any attempt to change attributes of a file +* (chmod, chown, chgrp, etc) +*/ +if (profile) + error =aa_attr (profile, dentry, mnt, iattr); + +aa_put_profile (profile); + } + +out: +return error; +} + +static int aa_xattr_permission (struct dentry *dentry,struct vfsmount *mnt, +const char *operation,int mask, +struct file *file) +{ +int error =0 ; + +if (mnt &&mediated_filesystem (dentry->d_inode)) { +struct aa_profile *profile =aa_get_profile (current); +int check = file ?AA_CHECK_FD :0 ; + +if (profile) + error =aa_perm_xattr (profile, operation, dentry, mnt, + mask, check); +aa_put_profile (profile); + } + +return error; +} + +static int apparmor_inode_setxattr (struct dentry *dentry,struct vfsmount *mnt, +char *name,void *value,size_t size, +int flags,struct file *file) +{ +return aa_xattr_permission (dentry, mnt,"xattr set" ,MAY_WRITE , file); +} + +static int apparmor_inode_getxattr (struct dentry *dentry,struct vfsmount *mnt, +char *name,struct file *file) +{ +return aa_xattr_permission (dentry, mnt,"xattr get" ,MAY_READ , file); +} + +static int apparmor_inode_listxattr (struct dentry *dentry,struct vfsmount *mnt, +struct file *file) +{ +return aa_xattr_permission (dentry, mnt,"xattr list" ,MAY_READ , file); +} + +static int apparmor_inode_removexattr (struct dentry *dentry, +struct vfsmount *mnt,char *name, +struct file *file) +{ +return aa_xattr_permission (dentry, mnt,"xattr remove" ,MAY_WRITE , + file); +} + +static int apparmor_file_permission (struct file *file,int mask) +{ +struct aa_profile *profile; +struct aa_profile *file_profile = (struct aa_profile *)file->f_security; +int error =0 ; + +if (!file_profile) + goto out; + +/* +* If this file was opened under a different profile, we +* revalidate the access against the current profile. +*/ + profile =aa_get_profile (current); +if (profile && file_profile != profile) { +struct dentry *dentry = file->f_dentry; +struct vfsmount *mnt = file->f_vfsmnt; +struct inode *inode = dentry->d_inode; +int check =AA_CHECK_FD ; + +/* +* FIXME: We should remember which profiles we revalidated +* against. +*/ +if (S_ISDIR (inode->i_mode)) + check |=AA_CHECK_DIR ; + mask &= (MAY_READ |MAY_WRITE |MAY_EXEC ); + error =aa_permission (inode,"file_permission" , dentry, mnt, + mask, check); + } +aa_put_profile (profile); + +out: +return error; +} + +static int apparmor_file_alloc_security (struct file *file) +{ +struct aa_profile *profile; + + profile =aa_get_profile (current); +if (profile) + file->f_security = profile; + +return 0 ; +} + +static void apparmor_file_free_security (struct file *file) +{ +struct aa_profile *file_profile = (struct aa_profile *)file->f_security; + +aa_put_profile (file_profile); +} + +static inline int aa_mmap (struct file *file,const char *operation, +unsigned long prot,unsigned long flags) +{ +struct dentry *dentry; +int mask =0 ; + +if (!file || !file->f_security) +return 0 ; + +if (prot &PROT_READ ) + mask |=MAY_READ ; +/* Private mappings don't require write perms since they don't +* write back to the files */ +if ((prot &PROT_WRITE ) && !(flags &MAP_PRIVATE )) + mask |=MAY_WRITE ; +if (prot &PROT_EXEC ) + mask |=AA_EXEC_MMAP ; + + dentry = file->f_dentry; +return aa_permission (dentry->d_inode, operation, dentry, + file->f_vfsmnt, mask,AA_CHECK_FD ); +} + +static int apparmor_file_mmap (struct file *file,unsigned long reqprot, +unsigned long prot,unsigned long flags) +{ +return aa_mmap (file,"file_mmap" , prot, flags); +} + +static int apparmor_file_mprotect (struct vm_area_struct *vma, +unsigned long reqprot,unsigned long prot) +{ +return aa_mmap (vma->vm_file,"file_mprotect" , prot, + !(vma->vm_flags &VM_SHARED ) ?MAP_PRIVATE :0 ); +} + +static int apparmor_task_alloc_security (struct task_struct *task) +{ +return aa_clone (task); +} + +/* +* Called from IRQ context from RCU callback. +*/ +static void apparmor_task_free_security (struct task_struct *task) +{ +aa_release (task); +} + +static int apparmor_getprocattr (struct task_struct *task,char *name, +char **value) +{ +unsigned len; +int error; +struct aa_profile *profile; + +/* AppArmor only supports the "current" process attribute */ +if (strcmp (name,"current" ) !=0 ) +return -EINVAL ; + +/* must be task querying itself or admin */ +if (current != task && !capable (CAP_SYS_ADMIN )) +return -EPERM ; + + profile =aa_get_profile (task); + error =aa_getprocattr (profile, value, &len); +aa_put_profile (profile); +if (!error) + error = len; + +return error; +} + +static int apparmor_setprocattr (struct task_struct *task,char *name, +void *value,size_t size) +{ +char *command, *args; +int error; + +if (strcmp (name,"current" ) !=0 || size ==0 || size >=PAGE_SIZE ) +return -EINVAL ; + args = value; + args[size] ='\0' ; + args =strstrip (args); + command =strsep (&args," " ); +if (!args) +return -EINVAL ; +while (isspace (*args)) + args++; +if (!*args) +return -EINVAL ; + +if (strcmp (command,"changehat" ) ==0 ) { +if (current != task) +return -EACCES ; + error =aa_setprocattr_changehat (args); + }else if (strcmp (command,"changeprofile" ) ==0 ) { +if (current != task) +return -EACCES ; + error =aa_setprocattr_changeprofile (args); + }else if (strcmp (command,"setprofile" )) { +struct aa_profile *profile; + +/* Only an unconfined process with admin capabilities +* may change the profile of another task. +*/ + +if (!capable (CAP_SYS_ADMIN )) +return -EACCES ; + + profile =aa_get_profile (current); +if (profile) { +struct aa_audit sa; +memset (&sa,0 ,sizeof (sa)); + sa.operation ="profile_set" ; + sa.gfp_mask =GFP_KERNEL ; + sa.task = task->pid; + sa.info ="from confined process" ; +aa_audit_reject (profile, &sa); +aa_put_profile (profile); +return -EACCES ; + } + error =aa_setprocattr_setprofile (task, args); + }else { +struct aa_audit sa; +memset (&sa,0 ,sizeof (sa)); + sa.operation ="setprocattr" ; + sa.gfp_mask =GFP_KERNEL ; + sa.info ="invalid command" ; + sa.name = command; + sa.task = task->pid; +aa_audit_reject (NULL , &sa); +return -EINVAL ; + } + +if (!error) + error = size; +return error; +} + +struct security_operations apparmor_ops = { + .ptrace = apparmor_ptrace, + .capget = cap_capget, + .capset_check = cap_capset_check, + .capset_set = cap_capset_set, + .sysctl = apparmor_sysctl, + .capable = apparmor_capable, + .syslog = cap_syslog, + + .netlink_send = cap_netlink_send, + .netlink_recv = cap_netlink_recv, + + .bprm_apply_creds = cap_bprm_apply_creds, + .bprm_set_security = apparmor_bprm_set_security, + .bprm_secureexec = apparmor_bprm_secureexec, + + .sb_mount = apparmor_sb_mount, + .sb_umount = apparmor_umount, + + .inode_mkdir = apparmor_inode_mkdir, + .inode_rmdir = apparmor_inode_rmdir, + .inode_create = apparmor_inode_create, + .inode_link = apparmor_inode_link, + .inode_unlink = apparmor_inode_unlink, + .inode_symlink = apparmor_inode_symlink, + .inode_mknod = apparmor_inode_mknod, + .inode_rename = apparmor_inode_rename, + .inode_permission = apparmor_inode_permission, + .inode_setattr = apparmor_inode_setattr, + .inode_setxattr = apparmor_inode_setxattr, + .inode_getxattr = apparmor_inode_getxattr, + .inode_listxattr = apparmor_inode_listxattr, + .inode_removexattr = apparmor_inode_removexattr, + .file_permission = apparmor_file_permission, + .file_alloc_security = apparmor_file_alloc_security, + .file_free_security = apparmor_file_free_security, + .file_mmap = apparmor_file_mmap, + .file_mprotect = apparmor_file_mprotect, + + .task_alloc_security = apparmor_task_alloc_security, + .task_free_security = apparmor_task_free_security, + .task_post_setuid = cap_task_post_setuid, + .task_reparent_to_init = cap_task_reparent_to_init, + + .getprocattr = apparmor_getprocattr, + .setprocattr = apparmor_setprocattr, +}; + +static void info_message (const char *str) +{ +struct aa_audit sa; +memset (&sa,0 ,sizeof (sa)); + sa.gfp_mask =GFP_KERNEL ; + sa.info = str; +printk (KERN_INFO "AppArmor: %s" , str); +aa_audit_message (NULL , &sa,AUDIT_APPARMOR_STATUS ); +} + +static int __init apparmor_init (void ) +{ +int error; + +if ((error =create_apparmorfs ())) { +AA_ERROR ("Unable to activate AppArmor filesystem\n" ); + goto createfs_out; + } + +if ((error =alloc_null_complain_profile ())){ +AA_ERROR ("Unable to allocate null complain profile\n" ); + goto alloc_out; + } + +if ((error =register_security (&apparmor_ops))) { +AA_ERROR ("Unable to register AppArmor\n" ); + goto register_security_out; + } + +if (apparmor_complain) +info_message ("AppArmor initialized: complainmode enabled" ); +else +info_message ("AppArmor initialized" ); + +return error; + +register_security_out: +free_null_complain_profile (); + +alloc_out: +destroy_apparmorfs (); + +createfs_out: +return error; + +} + +static void __exit apparmor_exit(void) +{ +/* Remove and release all the profiles on the profile list. */ +mutex_lock (&aa_interface_lock); +write_lock (&profile_list_lock); +while (!list_empty (&profile_list)) { +struct aa_profile *profile = + list_entry(profile_list.next, struct aa_profile, list); + +/* Remove the profile from each task context it is on. */ +lock_profile (profile); + profile->isstale =1 ; +aa_unconfine_tasks (profile); +unlock_profile (profile); + +/* Release the profile itself. */ +list_del_init (&profile->list); +aa_put_profile (profile); + } +write_unlock (&profile_list_lock); + +/* FIXME: cleanup profiles references on files */ + +free_null_complain_profile (); + +/* +* Delay for an rcu cycle to make sure that all active task +* context readers have finished, and all profiles have been +* freed by their rcu callbacks. +*/ +synchronize_rcu (); + +destroy_apparmorfs (); +mutex_unlock (&aa_interface_lock); + +if (unregister_security (&apparmor_ops)) +info_message ("Unable to properly unregister AppArmor" ); + +info_message ("AppArmor protection removed" ); +} + +module_init (apparmor_init); +module_exit (apparmor_exit); + +MODULE_DESCRIPTION ("AppArmor process confinement" ); +MODULE_AUTHOR ("Novell/Immunix, http://bugs.opensuse.org" ); +MODULE_LICENSE ("GPL" );
PATCH 39/44 AppArmor: Profile loading and manipulation, pathname matching
In reply to [email protected]Pathname matching, transition table loading, profile loading and manipulation.
--- security/apparmor/match.c | 248 ++++++++++++++ security/apparmor/match.h | 83 ++++ security/apparmor/module_interface.c | 589 +++++++++++++++++++++++++++++++++++ 3 files changed, 920 insertions(+)
security/apparmor/match.c new file +248 -0
@@ -0,0 +1,248 @@ +/* +* Copyright (C) 2007 Novell/SUSE +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation, version 2 of the +* License. +* +* Regular expression transition table matching +*/ + +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/errno.h> +#include "apparmor.h" +#include "match.h" + +static struct table_header *unpack_table (void *blob,size_t bsize) +{ +struct table_header *table =NULL ; +struct table_header th; +size_t tsize; + +if (bsize <sizeof (struct table_header )) + goto out; + + th.td_id =be16_to_cpu (*(u16 *) (blob)); + th.td_flags =be16_to_cpu (*(u16 *) (blob +2 )); + th.td_lolen =be32_to_cpu (*(u32 *) (blob +8 )); + blob +=sizeof (struct table_header ); + +if (!(th.td_flags ==YYTD_DATA16 || th.td_flags ==YYTD_DATA32 || + th.td_flags ==YYTD_DATA8 )) + goto out; + + tsize =table_size (th.td_lolen, th.td_flags); +if (bsize < tsize) + goto out; + + table =kmalloc (tsize,GFP_KERNEL ); +if (table) { + *table = th; +if (th.td_flags ==YYTD_DATA8 ) +UNPACK_ARRAY (table->td_data, blob, th.td_lolen, + u8, byte_to_byte); +else if (th.td_flags ==YYTD_DATA16 ) +UNPACK_ARRAY (table->td_data, blob, th.td_lolen, + u16, be16_to_cpu); +else +UNPACK_ARRAY (table->td_data, blob, th.td_lolen, + u32, be32_to_cpu); + } + +out: +return table; +} + +int unpack_dfa (struct aa_dfa *dfa,void *blob,size_t size) +{ +int hsize, i; +int error = -ENOMEM ; + +/* get dfa table set header */ +if (size <sizeof (struct table_set_header )) + goto fail; + +if (ntohl (*(u32 *)blob) !=YYTH_MAGIC ) + goto fail; + + hsize =ntohl (*(u32 *)(blob +4 )); +if (size < hsize) + goto fail; + + blob += hsize; + size -= hsize; + + error = -EPROTO ; +while (size >0 ) { +struct table_header *table; + table =unpack_table (blob, size); +if (!table) + goto fail; + +switch (table->td_id) { +case YYTD_ID_ACCEPT : +case YYTD_ID_BASE : + dfa->tables[table->td_id -1 ] = table; +if (table->td_flags !=YYTD_DATA32 ) + goto fail; +break ; +case YYTD_ID_DEF : +case YYTD_ID_NXT : +case YYTD_ID_CHK : + dfa->tables[table->td_id -1 ] = table; +if (table->td_flags !=YYTD_DATA16 ) + goto fail; +break ; +case YYTD_ID_EC : + dfa->tables[table->td_id -1 ] = table; +if (table->td_flags !=YYTD_DATA8 ) + goto fail; +break ; +default : +kfree (table); + goto fail; + } + + blob +=table_size (table->td_lolen, table->td_flags); + size -=table_size (table->td_lolen, table->td_flags); + } + +return 0 ; + +fail: +for (i =0 ; i <ARRAY_SIZE (dfa->tables); i++) { +if (dfa->tables[i]) { +kfree (dfa->tables[i]); + dfa->tables[i] =NULL ; + } + } +return error; +} + +/** +* verify_dfa - verify that all the transitions and states in the dfa tables +* are in bounds. +* @dfa: dfa to test +* +* assumes dfa has gone through the verification done by unpacking +*/ +int verify_dfa (struct aa_dfa *dfa) +{ +size_t i, state_count, trans_count; +int error = -EPROTO ; + +/* check that required tables exist */ +if (!(dfa->tables[YYTD_ID_ACCEPT -1 ] && + dfa->tables[YYTD_ID_DEF -1 ] && + dfa->tables[YYTD_ID_BASE -1 ] && + dfa->tables[YYTD_ID_NXT -1 ] && + dfa->tables[YYTD_ID_CHK -1 ])) + goto out; + +/* accept.size == default.size == base.size */ + state_count = dfa->tables[YYTD_ID_BASE -1 ]->td_lolen; +if (!(state_count == dfa->tables[YYTD_ID_DEF -1 ]->td_lolen && + state_count == dfa->tables[YYTD_ID_ACCEPT -1 ]->td_lolen)) + goto out; + +/* next.size == chk.size */ + trans_count = dfa->tables[YYTD_ID_NXT -1 ]->td_lolen; +if (trans_count != dfa->tables[YYTD_ID_CHK -1 ]->td_lolen) + goto out; + +/* if equivalence classes then its table size must be 256 */ +if (dfa->tables[YYTD_ID_EC -1 ] && + dfa->tables[YYTD_ID_EC -1 ]->td_lolen !=256 ) + goto out; + +for (i =0 ; i < state_count; i++) { +if (DEFAULT_TABLE (dfa)[i] >= state_count) + goto out; +if (BASE_TABLE (dfa)[i] >= trans_count +256 ) + goto out; + } + +for (i =0 ; i < trans_count ; i++) { +if (NEXT_TABLE (dfa)[i] >= state_count) + goto out; +if (CHECK_TABLE (dfa)[i] >= state_count) + goto out; + } + +/* verify accept permissions */ +for (i =0 ; i < state_count; i++) { +int mode =ACCEPT_TABLE (dfa)[i]; + +if (mode & ~AA_VALID_PERM_MASK ) + goto out; + +/* if MAY_EXEC, exactly one exec modifier must be set */ +if (mode &MAY_EXEC ) { + mode &=AA_EXEC_MODIFIERS ; +if (mode & (mode -1 )) + goto out; + } + } + + error =0 ; +out: +return error; +} + +struct aa_dfa *aa_match_alloc (void ) +{ +return kzalloc (sizeof (struct aa_dfa ),GFP_KERNEL ); +} + +void aa_match_free (struct aa_dfa *dfa) +{ +if (dfa) { +int i; + +for (i =0 ; i <ARRAY_SIZE (dfa->tables); i++) +kfree (dfa->tables[i]); + } +kfree (dfa); +} + +/** +* aa_dfa_match - match @path against @dfa starting in @state +* @dfa: the dfa to match @path against +* @state: the state to start matching in +* @path: the path to match against the dfa +* +* aa_dfa_match will match the full path length and return the state it +* finished matching in. The final state is used to look up the accepting +* label. +*/ +unsigned int aa_dfa_match (struct aa_dfa *dfa,const char *str) +{ +u16 *def =DEFAULT_TABLE (dfa); +u32 *base =BASE_TABLE (dfa); +u16 *next =NEXT_TABLE (dfa); +u16 *check =CHECK_TABLE (dfa); +unsigned int state =1 , pos; + +/* current state is <state>, matching character *str */ +if (dfa->tables[YYTD_ID_EC -1 ]) { +u8 *equiv =EQUIV_TABLE (dfa); +while (*str) { + pos = base[state] + equiv[(u8)*str++]; +if (check[pos] == state) + state = next[pos]; +else + state = def[state]; + } + }else { +while (*str) { + pos = base[state] + (u8)*str++; +if (check[pos] == state) + state = next[pos]; +else + state = def[state]; + } + } +return ACCEPT_TABLE (dfa)[state]; +}
security/apparmor/match.h new file +83 -0
83 lines not on this page · raw message
security/apparmor/module_interface.c new file +589 -0
589 lines not on this page · raw message
PATCH 40/44 AppArmor: all the rest
In reply to [email protected]All the things that didn't nicely fit in a category on their own: kbuild code, declararions and inline functions, /sys/kernel/security/apparmor filesystem for controlling apparmor from user space, profile list functions, locking documentation, /proc/$pid/task/$tid/attr/current access.
--- security/apparmor/Kconfig | 9 + security/apparmor/Makefile | 13 ++ security/apparmor/apparmor.h | 265 +++++++++++++++++++++++++++++++++++++++++ security/apparmor/apparmorfs.c | 252 ++++++++++++++++++++++++++++++++++++++ security/apparmor/inline.h | 211 ++++++++++++++++++++++++++++++++ security/apparmor/list.c | 94 ++++++++++++++ security/apparmor/locking.txt | 68 ++++++++++ security/apparmor/procattr.c | 155 +++++++++++++++++++++++ 8 files changed, 1067 insertions(+)
security/apparmor/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +config SECURITY_APPARMOR + tristate "AppArmor support" + depends on SECURITY!=n + help + This enables the AppArmor security module. + Required userspace tools (if they are not included in your + distribution) and further information may be found at + <http://forge.novell.com/modules/xfmod/project/?apparmor> + If you are unsure how to answer this question, answer N.
security/apparmor/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# Makefile for AppArmor Linux Security Module +# +obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o + +apparmor-y := main.o list.o procattr.o lsm.o apparmorfs.o \ + module_interface.o match.o + +quiet_cmd_make-caps = GEN $@ +cmd_make-caps = sed -n -e "/CAP_FS_MASK/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\$$/[\\2] = \"\\1\",/p" $< | tr A-Z a-z > $@ + +$(obj)/main.o : $(obj)/capability_names.h +$(obj)/capability_names.h : $(srctree)/include/linux/capability.h + $(call cmd,make-caps)
security/apparmor/apparmor.h new file +265 -0
265 lines not on this page · raw message
security/apparmor/apparmorfs.c new file +252 -0
252 lines not on this page · raw message
security/apparmor/inline.h new file +211 -0
211 lines not on this page · raw message
security/apparmor/list.c new file +94 -0
94 lines not on this page · raw message
security/apparmor/locking.txt new file +68 -0
68 lines not on this page · raw message
security/apparmor/procattr.c new file +155 -0
155 lines not on this page · raw message
PATCH 41/44 Add AppArmor LSM to security/Makefile
In reply to [email protected]--- security/Kconfig | 1 + security/Makefile | 1 + security/apparmor/Kconfig | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-)
security/Kconfig +1 -0
@@ -94,6 +94,7 @@ config SECURITY_ROOTPLUG If you are unsure how to answer this question, answer N. source security/selinux/Kconfig +source security/apparmor/Kconfig endmenu
security/Makefile +1 -0
@@ -14,5 +14,6 @@ endif obj-$(CONFIG_SECURITY) += security.o dummy.o inode.o # Must precede capability.o in order to stack properly. obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o +obj-$(CONFIG_SECURITY_APPARMOR) += commoncap.o apparmor/ obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o
security/apparmor/Kconfig +2 -1
@@ -1,6 +1,7 @@ config SECURITY_APPARMOR tristate "AppArmor support" - depends on SECURITY!=n + depends on SECURITY + select AUDIT help This enables the AppArmor security module. Required userspace tools (if they are not included in your
PATCH 42/44 Switch to vfs_permission() in do_path_lookup()
In reply to [email protected]Switch from file_permission() to vfs_permission() in do_path_lookup():
this avoids calling permission() with a NULL nameidata here.
--- fs/namei.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
fs/namei.c +6 -7
@@ -1130,25 +1130,24 @@ static int fastcall do_path_lookup(int d nd->dentry =dget (fs->pwd);read_unlock (&fs->lock); }else { -struct dentry *dentry; - file =fget_light (dfd, &fput_needed); retval = -EBADF ;if (!file) goto out_fail; - dentry = file->f_path.dentry; + nd->dentry = file->f_path.dentry; + nd->mnt = file->f_path.mnt; retval = -ENOTDIR ; -if (!S_ISDIR (dentry->d_inode->i_mode)) +if (!S_ISDIR (nd->dentry->d_inode->i_mode)) goto fput_fail; - retval =file_permission (file,MAY_EXEC ); + retval =vfs_permission (nd,MAY_EXEC );if (retval) goto fput_fail; - nd->mnt =mntget (file->f_path.mnt); - nd->dentry =dget (dentry); +mntget (nd->mnt); +dget (nd->dentry);fput_light (file, fput_needed); }
Andrew Morton
maintainerQuoted 2 lines · On Tue, 26 Jun 2007 16:07:56 -0700 [email protected] wrote:
This post contains patches to include the AppArmor application security framework, with request for inclusion into -mm for wider testing.
Patches 24 and 31 didn't come through.
Rolled-up diffstat (excluding 24&31):
fs/attr.c | 7 fs/dcache.c | 181 ++- fs/ecryptfs/inode.c | 41 fs/exec.c | 3 fs/fat/file.c | 2 fs/hpfs/namei.c | 2 fs/namei.c | 115 +- fs/nfsd/nfs4recover.c | 7 fs/nfsd/nfs4xdr.c | 2 fs/nfsd/vfs.c | 89 + fs/ntfs/file.c | 2 fs/open.c | 50 fs/reiserfs/file.c | 2 fs/reiserfs/xattr.c | 8 fs/splice.c | 4 fs/stat.c | 2 fs/sysfs/file.c | 2 fs/utimes.c | 11 fs/xattr.c | 75 - fs/xfs/linux-2.6/xfs_lrw.c | 2 include/linux/audit.h | 12 include/linux/fs.h | 27 include/linux/nfsd/nfsd.h | 3 include/linux/security.h | 182 ++- include/linux/sysctl.h | 2 include/linux/xattr.h | 11 ipc/mqueue.c | 2 kernel/audit.c | 6 kernel/sysctl.c | 27 mm/filemap.c | 12 mm/filemap_xip.c | 2 mm/shmem.c | 2 mm/tiny-shmem.c | 2 net/unix/af_unix.c | 2 security/Kconfig | 1 security/Makefile | 1 security/apparmor/Kconfig | 10 security/apparmor/Makefile | 13 security/apparmor/apparmor.h | 265 +++++ security/apparmor/apparmorfs.c | 252 +++++ security/apparmor/inline.h | 211 ++++ security/apparmor/list.c | 94 + security/apparmor/locking.txt | 68 + security/apparmor/lsm.c | 817 ++++++++++++++++ security/apparmor/main.c | 1255 +++++++++++++++++++++++++ security/apparmor/match.c | 248 ++++ security/apparmor/match.h | 83 + security/apparmor/module_interface.c | 589 +++++++++++ security/apparmor/procattr.c | 155 +++ security/commoncap.c | 7 security/dummy.c | 43 security/selinux/hooks.c | 94 - 52 files changed, 4701 insertions(+), 404 deletions(-)
which seems OK.
so... where do we stand with this? Fundamental, irreconcilable differences over the use of pathname-based security?
Are there any other sticking points?
Quoted 8 lines · Andrew Morton
Quoted 2 lines · On Tue, 26 Jun 2007 16:07:56 -0700 [email protected] wrote:
This post contains patches to include the AppArmor application security framework, with request for inclusion into -mm for wider testing.
Patches 24 and 31 didn't come through.
yes, sorry about that I had a very odd failure authetication failure with those two mails and missed it.
They have been recent.
Quoted 4 lines
so... where do we stand with this? Fundamental, irreconcilable differences over the use of pathname-based security?
There certainly seems to be some differences of opinion over the use of pathname-based-security.
Quoted 3 lines
Are there any other sticking points?
The conditional passing of the vfsmnt mount in the vfs, as done in this patch series, has received a NAK. This problem results from NFS passing a NULL nameidata into the vfs. We have a second patch series that we have posted for discussion that addresses this by splitting the nameidata struct.
Message-Id: <[email protected]>
Subject: [RFD 0/4] AppArmor - Don't pass NULL nameidata to vfs_create/lookup/permission IOPs
other issues that have been raised are:
- AppArmor does not currently mediate IPC and network communications. Mediation of these is a wip
- the use of d_path to generate the pathname used for mediation when a file is opened.
- Generating the pathname using a reverse walk is considered ugly
- A buffer is alloced to store the generated path name.
- The buffer size has a configurable upper limit which will cause opens to fail if the pathname length exceeds this limit. This is a fail closed behavior.
- there have been some concerns expressed about the performance of this approach
We are evaluating our options on how best to address this issue.
Andrew Morton
maintainerQuoted 6 lines · On Tue, 26 Jun 2007 19:24:03 -0700 John Johansen <[email protected]> wrote:
Quoted 4 lines
so... where do we stand with this? Fundamental, irreconcilable differences over the use of pathname-based security?
There certainly seems to be some differences of opinion over the use of pathname-based-security.
I was refreshed to have not been cc'ed on a lkml thread for once. I guess it couldn't last.
Do you agree with the "irreconcilable" part? I think I do.
I suspect that we're at the stage of having to decide between
a) set aside the technical issues and grudgingly merge this stuff as a service to Suse and to their users (both of which entities are very important to us) and leave it all as an object lesson in how-not-to-develop-kernel-features.
Minimisation of the impact on the rest of the kernel is of course very important here.
versus
b) leave it out and require that Suse wear the permanent cost and quality impact of maintaining it out-of-tree. It will still be an object lesson in how-not-to-develop-kernel-features.
Sigh. Please don't put us in this position again. Get stuff upstream before shipping it to customers, OK? It ain't rocket science.
Quoted 12 lines
Quoted 3 lines
Are there any other sticking points?
The conditional passing of the vfsmnt mount in the vfs, as done in this patch series, has received a NAK. This problem results from NFS passing a NULL nameidata into the vfs. We have a second patch series that we have posted for discussion that addresses this by splitting the nameidata struct.
Message-Id: <[email protected]>
Subject: [RFD 0/4] AppArmor - Don't pass NULL nameidata to vfs_create/lookup/permission IOPs
Quoted 13 lines
other issues that have been raised are:
- AppArmor does not currently mediate IPC and network communications. Mediation of these is a wip
- the use ofd_pathto generate the pathname used for mediation when a file is opened.
- Generating the pathname using a reverse walk is considered ugly
- A buffer is alloced to store the generated path name.
- The buffer size has a configurable upper limit which will cause opens to fail if the pathname length exceeds this limit. This is a fail closed behavior.
- there have been some concerns expressed about the performance of this approach
We are evaluating our options on how best to address this issue.
OK, useful summary, thanks. I'd encourage you to proceed apace.
Quoted 12 lines · Andrew Morton
Quoted 6 lines · On Tue, 26 Jun 2007 19:24:03 -0700 John Johansen <[email protected]> wrote:
Quoted 4 lines
so... where do we stand with this? Fundamental, irreconcilable differences over the use of pathname-based security?
There certainly seems to be some differences of opinion over the use of pathname-based-security.
I was refreshed to have not been cc'ed on a lkml thread for once. I guess it couldn't last.
sorry about that
Quoted 2 lines
Do you agree with the "irreconcilable" part? I think I do.
I will concede that this may be the case for some. However I am still hopeful (perhaps naive) that this isn't the case in general.
Quoted 9 lines
I suspect that we're at the stage of having to decide between
a) set aside the technical issues and grudgingly merge this stuff as a service to Suse and to their users (both of which entities are very important to us) and leave it all as an object lesson in how-not-to-develop-kernel-features.
Minimisation of the impact on the rest of the kernel is of course very important here.
Agreed, and I hope any changes that are made are for the benefit of the kernel in general and will find uses in other parts.
Quoted 10 lines
versus
b) leave it out and require that Suse wear the permanent cost and quality impact of maintaining it out-of-tree. It will still be an object lesson in how-not-to-develop-kernel-features.
Sigh. Please don't put us in this position again. Get stuff upstream before shipping it to customers, OK? It ain't rocket science.
Indeed, I can only appologize for the past, and offer reassurances that we intend to do our best to do, it right going forward.
Quoted 26 lines
Quoted 12 lines
Quoted 3 lines
Are there any other sticking points?
The conditional passing of the vfsmnt mount in the vfs, as done in this patch series, has received a NAK. This problem results from NFS passing a NULL nameidata into the vfs. We have a second patch series that we have posted for discussion that addresses this by splitting the nameidata struct.
Message-Id: <[email protected]>
Subject: [RFD 0/4] AppArmor - Don't pass NULL nameidata to vfs_create/lookup/permission IOPsQuoted 13 lines
other issues that have been raised are:
- AppArmor does not currently mediate IPC and network communications. Mediation of these is a wip
- the use ofd_pathto generate the pathname used for mediation when a file is opened.
- Generating the pathname using a reverse walk is considered ugly
- A buffer is alloced to store the generated path name.
- The buffer size has a configurable upper limit which will cause opens to fail if the pathname length exceeds this limit. This is a fail closed behavior.
- there have been some concerns expressed about the performance of this approach
We are evaluating our options on how best to address this issue.
Quoted 1 line
OK, useful summary, thanks. I'd encourage you to proceed apace.
thankyou
Quoted 24 lines · Andrew Morton
Quoted 6 lines · On Tue, 26 Jun 2007 19:24:03 -0700 John Johansen <[email protected]> wrote:
Quoted 4 lines
so... where do we stand with this? Fundamental, irreconcilable differences over the use of pathname-based security?
There certainly seems to be some differences of opinion over the use of pathname-based-security.
I was refreshed to have not been cc'ed on a lkml thread for once. I guess it couldn't last.
Do you agree with the "irreconcilable" part? I think I do.
I suspect that we're at the stage of having to decide between
a) set aside the technical issues and grudgingly merge this stuff as a service to Suse and to their users (both of which entities are very important to us) and leave it all as an object lesson in how-not-to-develop-kernel-features.
Minimisation of the impact on the rest of the kernel is of course very important here.
Quoted 6 lines
versus
b) leave it out and require that Suse wear the permanent cost and quality impact of maintaining it out-of-tree. It will still be an object lesson in how-not-to-develop-kernel-features.
...
versus
c) if [1] AppArmor is considered to be something that wouldn't be merged if it wasn't already widely deployed by Suse: leave it out, work on an ideal solution [2], and let Suse wear the one-time cost of migrating their users to the ideal solution
One important point is that if AppArmor gets merged there will be much more distribution support for it, and many people on !Suse will start using it.
I'm not claiming to understand the technical details, but from both slightly reading over the previous discussions and the "What are the advantages of AppArmor over SELinux?" section in the AppArmor FAQ [3] my impression is that a main advantage of AppArmor are more user friendly userspace tools. Therefore, if [1] AppArmor is considered technically inferior to SELinux, it might still become more popular than SELinux simply because it's easier to use - and although it's technically inferior.
cu
Adrian
[1] note the "if"
[2] could be, but not necessarily, SELinux
[3] http://developer.novell.com/wiki/index.php/Apparmor_FAQ
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 3 lines · Adrian Bunk
Quoted 1 line · Andrew Morton
Do you agree with the "irreconcilable" part? I think I do.
I am hoping for a reconciliation where the people who don't like AppArmor live with it by not using it. AppArmor is not intended to replace SELinux, it is intended to address a different set of goals.
Quoted 16 lines
Quoted 10 lines
I suspect that we're at the stage of having to decide between
a) set aside the technical issues and grudgingly merge this stuff as a service to Suse and to their users (both of which entities are very important to us) and leave it all as an object lesson in how-not-to-develop-kernel-features.
Minimisation of the impact on the rest of the kernel is of course very important here.
Quoted 6 lines
versus
b) leave it out and require that Suse wear the permanent cost and quality impact of maintaining it out-of-tree. It will still be an object lesson in how-not-to-develop-kernel-features.
...
Quoted 7 lines
versus
c) if [1] AppArmor is considered to be something that wouldn't be merged if it wasn't already widely deployed by Suse: leave it out, work on an ideal solution [2], and let Suse wear the one-time cost of migrating their users to the ideal solution
We argue that the proposed patch is a viable solution for providing AppArmor functionality. We would be happy for specific suggestions on how to make it better.
Quoted 8 lines
I'm not claiming to understand the technical details, but from both slightly reading over the previous discussions and the "What are the advantages of AppArmor over SELinux?" section in the AppArmor FAQ [3] my impression is that a main advantage of AppArmor are more user friendly userspace tools. Therefore, if [1] AppArmor is considered technically inferior to SELinux, it might still become more popular than SELinux simply because it's easier to use - and although it's technically inferior.
AppArmor's advantages come from the model, not the tools. AppArmor is not inferior to SELinux, it is different than SELinux. Neither can replace the other without horrid kludges.
Crispin
Signature · 3 lines
Crispin Cowan, Ph.D. http://crispincowan.com/~crispin/ Director of Software Engineering http://novell.com AppArmor Chat: irc.oftc.net/#apparmor
Quoted 3 lines · On Wed, 27 Jun 2007 14:06:04 -0700 Crispin Cowan <[email protected]> wrote:
I am hoping for a reconciliation where the people who don't like AppArmor live with it by not using it. AppArmor is not intended to replace SELinux, it is intended to address a different set of goals.
You keep saying that. But for that to be true you'd have to believe
_everyone_ using Novell distributions has needs that align exactly with AppArmor. Otherwise, how to explain that you don't offer and support both SELinux and AppArmor to your users?
It seems as far as Novell is concerned, AppArmor _is_ meant to replace SELinux. Not that there is really anything wrong with that, but it's a little disingenuous to then argue that they're meant to coexist.
Sean
Quoted 12 lines · Sean
Quoted 4 lines · On Wed, 27 Jun 2007 14:06:04 -0700 Crispin Cowan <[email protected]> wrote:
I am hoping for a reconciliation where the people who don't like AppArmor live with it by not using it. AppArmor is not intended to replace SELinux, it is intended to address a different set of goals.
You keep saying that. But for that to be true you'd have to believe
_everyone_ using Novell distributions has needs that align exactly with AppArmor. Otherwise, how to explain that you don't offer and support both SELinux and AppArmor to your users?
They are meant to co-exist in the Linux kernel source tree.
It is a fact that there exist use cases where AppArmor is incapable of meeting the need and SELinux is just the right thing. It is Novell's business judgment that there are not enough of those situations in our customer base to be worth the additional expense at this time.
But we do not want to prevent other people from using SELinux if it suits them. Linux is about choice, and that is especially vital in security. As Linus himself observed when LSM was started, there are a lot of security models, they have various strengths and weaknesses, and often are not compatible with each other. That is why it is important that LSM persist, that SELinux not be the only in-tree user of LSM, and why we think AppArmor should be included upstream, so that non-SUSE users can also use AppArmor if it suits them.
Crispin
Signature · 3 lines
Crispin Cowan, Ph.D. http://crispincowan.com/~crispin/ Director of Software Engineering http://novell.com AppArmor Chat: irc.oftc.net/#apparmor
David Miller
maintainerFrom: Crispin Cowan <[email protected]>
Date: Wed, 27 Jun 2007 15:46:57 -0700
Quoted 8 lines
But we do not want to prevent other people from using SELinux if it suits them. Linux is about choice, and that is especially vital in security. As Linus himself observed when LSM was started, there are a lot of security models, they have various strengths and weaknesses, and often are not compatible with each other. That is why it is important that LSM persist, that SELinux not be the only in-tree user of LSM, and why we think AppArmor should be included upstream, so that non-SUSE users can also use AppArmor if it suits them.
Anyone can apply the apparmour patch to their tree, they get the choice that way. Nobody is currently prevented from using apparmour if they want to, any such suggestion is pure rubbish.
It is even more incredulious to imply that just by having apparmour in the upstream kernel all the userland bits will magically appear on every user's distribution.
Give me a break.
What you get by the code going into the upstream kernel tree is that it a) adds some pseudo legitimacy to AppArmour (which I don't personally think is warranted) and b) gets the work of keeping apparmour working with upstream largely off of your back and in the hands of the upstream community.
Neither of those are reasons why something should go into the tree.
Frankly I think AppArmour is a joke, and all of this integration with LSM business is just a face saving effort, nothing more. And saving face is not, and has never been, a reason for something to be put into the upstream tree.
Quoted 12 lines · --- David Miller
From: Crispin Cowan <[email protected]>
Date: Wed, 27 Jun 2007 15:46:57 -0700Quoted 8 lines
But we do not want to prevent other people from using SELinux if it suits them. Linux is about choice, and that is especially vital in security. As Linus himself observed when LSM was started, there are a lot of security models, they have various strengths and weaknesses, and often are not compatible with each other. That is why it is important that LSM persist, that SELinux not be the only in-tree user of LSM, and why we think AppArmor should be included upstream, so that non-SUSE users can also use AppArmor if it suits them.
Quoted 3 lines
Anyone can apply the apparmour patch to their tree, they get the choice that way. Nobody is currently prevented from using apparmour if they want to, any such suggestion is pure rubbish.
The exact same argument was made prior to SELinux going upstream. Look, if you can't be right, try at least to be original.
Quoted 3 lines
It is even more incredulious to imply that just by having apparmour in the upstream kernel all the userland bits will magically appear on every user's distribution.
Just like all the SELinux userland magically appeared in everyone's distribution? Nope, didn't happen.
Quoted 1 line
Give me a break.
No. You are out of line and spewing ignorance.
Quoted 5 lines
What you get by the code going into the upstream kernel tree is that it a) adds some pseudo legitimacy to AppArmour (which I don't personally think is warranted) and b) gets the work of keeping apparmour working with upstream largely off of your back and in the hands of the upstream community.
Duh. Those are pretty much the reasons anyone goes through the trouble of getting anything upstream.
Quoted 1 line
Neither of those are reasons why something should go into the tree.
They reflect the corporate reality of the open source community. If you're going to go down the "open source isn't for money" rathole please take it elsewhere. I've heard the arguments so many times I can sing them to the tune of "Lady Madonna".
Quoted 1 line
Frankly I think AppArmour is a joke,
"SELinux, AppArmor, and Hilary Clinton walk into a bar ..."
Quoted 4 lines
and all of this integration with
LSM business is just a face saving effort, nothing more. And saving face is not, and has never been, a reason for something to be put into the upstream tree.
Believe what you will. Crispin has been working with LSM from the inception those many years ago. He's been working on getting this module in for over a year. If you don't like his module go write your own and put him out of business.
Casey Schaufler
[email protected]
David Miller
maintainerFrom: Casey Schaufler <[email protected]>
Date: Wed, 27 Jun 2007 17:27:17 -0700 (PDT)
Quoted 8 lines
Quoted 1 line · --- David Miller
Neither of those are reasons why something should go into the tree.
They reflect the corporate reality of the open source community. If you're going to go down the "open source isn't for money" rathole please take it elsewhere. I've heard the arguments so many times I can sing them to the tune of "Lady Madonna".
That's a wonderful technical reason for apparmour to go into the tree. Thanks for sharing and making it even clearer what is really behind this submission.
Quoted 5 lines
Quoted 3 lines
Anyone can apply the apparmour patch to their tree, they get the choice that way. Nobody is currently prevented from using apparmour if they want to, any such suggestion is pure rubbish.
The exact same argument was made prior to SELinux going upstream.
Its made for every thing before it goes upstream. It shouldn't be going uptream until it works, is reliable and does something useful. Then if it ever makes that grade it can go and sit in -mm for a bit to shake down .
Quoted 3 lines
Quoted 1 line
Frankly I think AppArmour is a joke,
"SELinux, AppArmor, and Hilary Clinton walk into a bar ..."
SELinux orders a beer object
AppArmor order a /beer
Hilary says "You are both under 21 you can't"
SELinux orders a shandy object
AppArmor orders a /shandy
SELinux is refused because the shandy mixer opened a beer object and
shandy inherited beer typing
AppArmor gets drunk because /shandy and /beer are clearly different
On Wed, Jun 27, 2007 at 05:27:17PM -0700, Casey Schaufler wrote:
| | --- David Miller <[email protected]> wrote: | | > From: Crispin Cowan <[email protected]> | > Date: Wed, 27 Jun 2007 15:46:57 -0700 | > | > > But we do not want to prevent other people from using SELinux if it | > > suits them. Linux is about choice, and that is especially vital in | > > security. As Linus himself observed when LSM was started, there are a | > > lot of security models, they have various strengths and weaknesses, and | > > often are not compatible with each other. That is why it is important | > > that LSM persist, that SELinux not be the only in-tree user of LSM, and | > > why we think AppArmor should be included upstream, so that non-SUSE | > > users can also use AppArmor if it suits them. | > | > Anyone can apply the apparmour patch to their tree, they get the | > choice that way. Nobody is currently prevented from using apparmour | > if they want to, any such suggestion is pure rubbish. | | The exact same argument was made prior to SELinux going upstream. | Look, if you can't be right, try at least to be original. | | > It is even more incredulious to imply that just by having apparmour | > in the upstream kernel all the userland bits will magically appear | > on every user's distribution. | | Just like all the SELinux userland magically appeared in everyone's | distribution? Nope, didn't happen. | | > Give me a break. | | No. You are out of line and spewing ignorance.
Please.
I really wish this thread would stick to the technical matter and dispense with the infernile sniping on one hand and stroking of egos on the other. Sheesh - some of us are actually trying to glean something useful from all of this.
| | > What you get by the code going into the upstream kernel tree is that | > it a) adds some pseudo legitimacy to AppArmour (which I don't | > personally think is warranted) and b) gets the work of keeping | > apparmour working with upstream largely off of your back and in the | > hands of the upstream community. | | Duh. Those are pretty much the reasons anyone goes through the | trouble of getting anything upstream. | | > Neither of those are reasons why something should go into the tree. | | They reflect the corporate reality of the open source community. | If you're going to go down the "open source isn't for money" | rathole please take it elsewhere. I've heard the arguments so many | times I can sing them to the tune of "Lady Madonna". | | > Frankly I think AppArmour is a joke, | | "SELinux, AppArmor, and Hilary Clinton walk into a bar ..."
Yawn. Not funny. See above comment.
| > and all of this integration with | > LSM business is just a face saving effort, nothing more. And saving | > face is not, and has never been, a reason for something to be put into | > the upstream tree. | | Believe what you will. Crispin has been working with LSM from the | inception those many years ago. He's been working on getting this | module in for over a year. If you don't like his module go write | your own and put him out of business.
Now this is getting really boring. See above comment. Can't we just stay on point?
Signature · 3 lines
Bill O'Donnell SGI [email protected]
Quoted 7 lines · David Miller
What you get by the code going into the upstream kernel tree is that it a) adds some pseudo legitimacy to AppArmour (which I don't personally think is warranted) and b) gets the work of keeping apparmour working with upstream largely off of your back and in the hands of the upstream community.
Neither of those are reasons why something should go into the tree.
I beg to differ. b) is *the* reason cited again and again on LKML for submitting code for inclusion in the tree. Whenever anyone posts anything which is remotely related to out-of-tree code, whether it's a question on the usage of some standard in-tree function, a request for help with a coding or debugging problem, or out-of-tree repercussions of an in-tree change, he or she invariably has to put up with an answer along the lines of: "put your code into the tree and all your problems will be solved" - or its sarcastic variant: "I can't find your code anywhere in the current kernel sources".
You can't have it both ways. Either you go around bashing people for maintaining their code out-of-tree or you go around bashing people for trying to get their code into the tree.
Signature · 4 lines
Tilman Schmidt E-Mail: [email protected] Bonn, Germany Diese Nachricht besteht zu 100% aus wiederverwerteten Bits. Ungeöffnet mindestens haltbar bis: (siehe Rückseite)
Quoted 20 lines · Tilman Schmidt
Quoted 7 lines · David Miller
What you get by the code going into the upstream kernel tree is that it a) adds some pseudo legitimacy to AppArmour (which I don't personally think is warranted) and b) gets the work of keeping apparmour working with upstream largely off of your back and in the hands of the upstream community.
Neither of those are reasons why something should go into the tree.
I beg to differ. b) is *the* reason cited again and again on LKML for submitting code for inclusion in the tree. Whenever anyone posts anything which is remotely related to out-of-tree code, whether it's a question on the usage of some standard in-tree function, a request for help with a coding or debugging problem, or out-of-tree repercussions of an in-tree change, he or she invariably has to put up with an answer along the lines of: "put your code into the tree and all your problems will be solved" - or its sarcastic variant: "I can't find your code anywhere in the current kernel sources".
Quoted 3 lines
You can't have it both ways. Either you go around bashing people for maintaining their code out-of-tree or you go around bashing people for trying to get their code into the tree.
You have a point.
But:
Code in the kernel must fulfill some (not completely fixed) quality criteria. It wouldn't be good to blindly include every bit of GPL'ed kernel code available anywhere in the Internet.
As an example, it's highly unlikely that some external device driver will be accepted without the author/maintainer doing some changes for getting it included.
If [1] AppArmor is considered to be generally insecure or in all respects inferior to SELinux it doesn't belong into the kernel.
Being blessed with some of the holy penguin pee by being included in the kernel is considered by many users as a quality criteria.
Sure, this contradicts a bit the "get your code upstream" mantra, but these are two conflicting goals and there's therefore no ideal solution.
If [1] AppArmor is offering required functionality not available through SELinux and it's considered a correct and secure solution for these purposes it should go into the kernel. Otherwise, it should not go into the kernel.
cu
Adrian
[1] note the "if"
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedAny chance you can remove linux-fsdevel from the CC list? I don't think this has anything to do with filesystems.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Quoted 43 lines · Adrian Bunk
Quoted 24 lines · Andrew Morton
Quoted 6 lines · On Tue, 26 Jun 2007 19:24:03 -0700 John Johansen <[email protected]> wrote:
Quoted 4 lines
so... where do we stand with this? Fundamental, irreconcilable differences over the use of pathname-based security?
There certainly seems to be some differences of opinion over the use of pathname-based-security.
I was refreshed to have not been cc'ed on a lkml thread for once. I guess it couldn't last.
Do you agree with the "irreconcilable" part? I think I do.
I suspect that we're at the stage of having to decide between
a) set aside the technical issues and grudgingly merge this stuff as a service to Suse and to their users (both of which entities are very important to us) and leave it all as an object lesson in how-not-to-develop-kernel-features.
Minimisation of the impact on the rest of the kernel is of course very important here.
Quoted 6 lines
versus
b) leave it out and require that Suse wear the permanent cost and quality impact of maintaining it out-of-tree. It will still be an object lesson in how-not-to-develop-kernel-features.
...versus
c) if [1] AppArmor is considered to be something that wouldn't be merged if it wasn't already widely deployed by Suse: leave it out, work on an ideal solution [2], and let Suse wear the one-time cost of migrating their users to the ideal solution
One important point is that if AppArmor gets merged there will be much more distribution support for it, and many people on !Suse will start using it.
Quoted 8 lines
I'm not claiming to understand the technical details, but from both slightly reading over the previous discussions and the "What are the advantages of AppArmor over SELinux?" section in the AppArmor FAQ [3] my impression is that a main advantage of AppArmor are more user friendly userspace tools. Therefore, if [1] AppArmor is considered technically inferior to SELinux, it might still become more popular than SELinux simply because it's easier to use - and although it's technically inferior.
A couple of random thoughts to mix up this discussion.
Quoted 1 line
From what I have been able to observer the LSM is roughly firewalls
rules for in box operations. All it can do is increase the chances you will get -EPERM.
Not being able to take path names into consideration is a current deficiency of the LSM.
Being exported to modules is another deficiency of the current LSM as it seems no serious user of the LSM can exist simply as a kernel module.
Not being able to mix code from different projects is also a very serious limitation of the LSM. Currently I don't think we can build a kernel that supports selinux and any other LSM at the same time. Which horribly limits what we can do with the LSM.
So it seems clear that if we are aiming at an ideal solution. We first need to enhance the LSM. Then merge in the AppArmor functionality. Doing it all in one patch series looks to overwhelming for a decent code review.
That said is anyone interested in making the LSM more like iptables with a generic table based rules structure? That way we could fix the one true LSM problem and concentrate on simpler pieces that give specific bits of interesting functionality. Or at the very least be able to compile in multiple different bits of functionality into the kernel simultaneously.
I'm really not familiar with the security issues the LSM addresses but I do know, it encourages huge incompatible mega solutions, and it tends to break when I fix real security problems in the kernel. So at this point I am convinced that the LSM is deficient, has very limited usability, and seems to be a very fragile firewall structure to me.
Eric
Quoted 5 lines · --- "Eric W. Biederman
A couple of random thoughts to mix up this discussion.
From what I have been able to observer the LSM is roughly firewalls rules for in box operations. All it can do is increase the chances you will get
-EPERM.
More likely -EACCES, but otherwise not so terribly far off.
Quoted 2 lines
Not being able to take path names into consideration is a current deficiency of the LSM.
It's a deficiency of the file system semantics invented by Kernighan, Thompson, et. al. in the later 1970's, favoring speed and size of implementation over a pristine namespace. The LSM is reasonably faithfull in presenting both the good and the bad of the file system semantics.
Quoted 3 lines
Being exported to modules is another deficiency of the current LSM as it seems no serious user of the LSM can exist simply as a kernel module.
While that is true of SELinux and AppArmor I would suggest that is an artifact of the design goals of those two sophisticated security schemes, not an attribute of the LSM.
Quoted 4 lines
Not being able to mix code from different projects is also a very serious limitation of the LSM. Currently I don't think we can build a kernel that supports selinux and any other LSM at the same time. Which horribly limits what we can do with the LSM.
Weeeelllll ... Module stacking has been a contentious issue from day one of the LSM. Now that SELiunx is proposing to take over capability processing for it's own purposes it's easy to think that while other schemes may be up to stacking SELinux ain't gonna.
Quoted 2 lines
So it seems clear that if we are aiming at an ideal solution. We first need to enhance the LSM.
I don't think so. I see much greater social/political problems than I see technical ones.
Quoted 3 lines
Then merge in the AppArmor
functionality. Doing it all in one patch series looks to overwhelming for a decent code review.
It's true that the code review for AppArmor has proven difficult. That's going to be true of any change to the vfs layer, for any reason. Have someone who was there tell you about the original XFS proposals some time. Again, it's not LSM's fault.
Quoted 2 lines
That said is anyone interested in making the LSM more like iptables with a generic table based rules structure?
That's pretty close to what you get with SELinux, and one reason why that crowd has advocated that LSM be dumped in favor of SELinux as the sole interface.
Quoted 3 lines
That way we could fix
the one true LSM problem and concentrate on simpler pieces that give specific bits of interesting functionality.
Sort of. While the SELinux kernel code isn't much, less than 20k lines, the reference policy it requires is 200k lines, and the smallest policy I've ever heard anyone claim runs is 600. Yes, you get interesting functionality, but I don't recall there being many claims that policy development is simple of late.
Quoted 3 lines
Or at the very least
be able to compile in multiple different bits of functionality into the kernel simultaneously.
The LSM stacking problem, to my mind, is waiting on two modules that really want to work together and enough thick skin to get past those who don't want LSM to get better in hopes it will go away.
Quoted 1 line
I'm really not familiar with the security issues the LSM addresses
It addresses none, it is a tool put in place so that Linus doesn't have to listen to security people argue over which scheme is better.
Quoted 1 line
but I do know, it encourages huge incompatible mega solutions,
That's the security marketplace, not LSM.
Quoted 2 lines
and
it tends to break when I fix real security problems in the kernel.
Please, examples.
Quoted 3 lines
So at this point I am convinced that the LSM is deficient, has very limited usability, and seems to be a very fragile firewall structure to me.
The "additional" architecture of the LSM, as opposed to the originally proposed "authoritative" model is responsible for a good deal of the limited deficiency and uasability, but was considered necessary to prevent kernel "highjacking". If it's fragile, it's mostly due to the organic growth of security implementation in the kernel. It is under utilized, and there are a number of reasons for that, but recent events are encouraging.
Casey Schaufler
[email protected]
Quoted 4 lines · Casey Schaufler
It's true that the code review for AppArmor has proven difficult. That's going to be true of any change to the vfs layer, for any reason. Have someone who was there tell you about the original XFS proposals some time. Again, it's not LSM's fault.
Utterly wrong comparism. There haven't been any VFS changes for XFS. There has been some new functionality in the core kernel, but the more interesting bits where in the VM (e.g. vmap which is now widely used).
AA on the other hand just fucks up VFS layering to implement really dumb semantics.
A better comparism would be to some of the original reiser4 suggestions, although to be as bad you'd have to look at Hans' whitepapers and not actually existing code. And yes, there's a reason his pipedreams never got anywhere near merged.
Quoted 7 lines · --- Christoph Hellwig
Quoted 4 lines · Casey Schaufler
It's true that the code review for AppArmor has proven difficult. That's going to be true of any change to the vfs layer, for any reason. Have someone who was there tell you about the original XFS proposals some time. Again, it's not LSM's fault.
Utterly wrong comparism. There haven't been any VFS changes for XFS.
Ah, I suggested the original proposal, not what actually got in. Two very different things. The XFS developers listened to the initial feedback and, after picking themselves up off the floor, got up and adjusted their plans.
Quoted 11 lines
There has been some new functionality in the core kernel, but the more interesting bits where in the VM (e.g. vmap which is now widely used).
AA on the other hand just fucks up VFS layering to implement really dumb semantics.
A better comparism would be to some of the original reiser4 suggestions, although to be as bad you'd have to look at Hans' whitepapers and not actually existing code. And yes, there's a reason his pipedreams never got anywhere near merged.
Agreed that the further up you want to mess things the tougher the task you have ahead of you. That's what I was hoping to get across, but it looks as if you have better, more recent examples than what I offered.
Thank you.
Casey Schaufler
[email protected]
Quoted 1 line · Christoph Hellwig
AA on the other hand just fucks up VFS layering [...]
Oh come on, this claim clearly isn't justified. How on earth is passing vfsmounts down the lsm hooks supposed to break vfs layering? We are not proposing to pass additional information down to file systems. There is no barrier between the vfs and lsm hooks for vfsmounts even today -- only look at the inode_getattr hook; it already gets a vfsmount.
Without vfsmount we cannot tell where in the namespace we are, but that information is essential for any kind of pathname based mechanism, AA or not, and even for plain reporting.
LSM as a framework is supposed to allow different security mechanisms to be plugged in. It isn't flexible enough for us right now, and so we are proposing to extend it. What can be wrong about that?
Andreas
Quoted 7 lines · Andrew Morton
I suspect that we're at the stage of having to decide between
a) set aside the technical issues and grudgingly merge this stuff as a service to Suse and to their users (both of which entities are very important to us) and leave it all as an object lesson in how-not-to-develop-kernel-features.
Quoted 8 lines
Minimisation of the impact on the rest of the kernel is of course very important here.
versus
b) leave it out and require that Suse wear the permanent cost and quality impact of maintaining it out-of-tree. It will still be an object lesson in how-not-to-develop-kernel-features.
How is this different from Red Hat wearing the permanent cost of carrying Execshield or other vetoed-by-upstream features ?
Given the choice, I'd ship a kernel for Fedora with nothing added that isn't upstream, but we have something of a legacy from our dumber days. (Though we've managed to drop lots of the more invasive stuff over time thankfully.. 4g4g for eg).
Quoted 2 lines
Sigh. Please don't put us in this position again. Get stuff upstream before shipping it to customers, OK? It ain't rocket science.
Indeed. The idea of granting exceptions to our usual acceptance criteria just because "some distro shipped it" strikes me as wrong on so many levels, regardless of its technical flaws.
And this isn't just because this is a patch from a competitor, I'd expect the exact same criteria to be applied if I tried to ram execshield etc down everyones throats.
Dave
Signature · 1 line
http://www.codemonkey.org.uk
Hi!
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
so... where do we stand with this? Fundamental, irreconcilable differences over the use of pathname-based security?
There certainly seems to be some differences of opinion over the use of pathname-based-security.
I was refreshed to have not been cc'ed on a lkml thread for once. I guess it couldn't last.
Quoted 8 lines
Do you agree with the "irreconcilable" part? I think I do.
I suspect that we're at the stage of having to decide between
a) set aside the technical issues and grudgingly merge this stuff as a service to Suse and to their users (both of which entities are very important to us) and leave it all as an object lesson in how-not-to-develop-kernel-features.
If this is merged, suse is stuck with technically inferior solution forever. This may please parts of suse, but not our users.
If this is not merged, suse will [have to] work with selinux people to come up with friendlier userland tools/selinux improvements. (We already had discussions with vojtech about a way to add path-based aspects to selinux, and selinux people already offered to add 'new file label is function of directory label and new name' support, which addresses lots of reasons for AA).
Actually, there's a middle way. Merging only 'pass vfsmounts down' parts will make AA self contained enough that suse will not go crazy while trying to maintain it, but will have good enough incentive to work with selinux people on something better.
Pavel
(not speaking for suse, as usual).
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines · John Johansen
other issues that have been raised are:
- the use ofd_pathto generate the pathname used for mediation when a file is opened.
- Generating the pathname using a reverse walk is considered ugly
A little more than "ugly". In this basic concurrent rename() and path-lookup load:
mkdir -p /a/b/0
mkdir -p /a/b/2
mkdir -p /c
touch /a/b/0/1
cd /a/b
while true; mv 0/1 2/3; mv 2/3 0/1; done & cd /
while true; do mv a/b c/d; mv c/d a/b; done & while true; do cat a/b/0/1 & done while true; do cat a/b/2/3 & done while true; do cat c/d/0/1 & done while true; do cat c/d/2/3 & done
I seem to recall you could actually end up racing and building a path to the file in those directories as "a/d/0/3" or some other path at which it never even remotely existed. I'd love to be wrong, but I can't help but see this problem in any reverse-pathname-generation proposal which gets the locking right.
Cheers,
Kyle Moffett
Quoted 3 lines · Kyle Moffett
I seem to recall you could actually end up racing and building a path to the file in those directories as "a/d/0/3" or some other path at which it never even remotely existed. I'd love to be wrong,
Cheer up, you recall wrong.
Quoted 2 lines
but I can't help but see this problem in any reverse-pathname-generation proposal which gets the locking right.
Have a look at how __d_path() is implemented (with the fixes): It takes the dcache_lock, and the vfsmount_lock where necessary, and this ensures that the pathname can't change under it, neither because of a rename nor unlink nor remount. The pathname computed is *exactly* the name the file has at that specific point time.
A few more details about how pathnames work are explained in the tech doc at:
http://forge.novell.com/modules/xfcontent/downloads.php/apparmor/LKML_Submission-May_07
Andreas
PATCH 43/44 Switch to vfs_permission() in sys_fchdir()
In reply to [email protected]Switch from file_permission() to vfs_permission() in sys_fchdir(): this avoids calling permission() with a NULL nameidata here.
--- fs/open.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
fs/open.c +7 -9
@@ -440,10 +440,8 @@ out:asmlinkage long sys_fchdir (unsigned int fd) { +struct nameidata nd;struct file *file; -struct dentry *dentry; -struct inode *inode; -struct vfsmount *mnt;int error; error = -EBADF ;
@@ -451,17 +449,17 @@ asmlinkage long sys_fchdir(unsigned intif (!file) goto out; - dentry = file->f_path.dentry; - mnt = file->f_path.mnt; - inode = dentry->d_inode; + nd.dentry = file->f_path.dentry; + nd.mnt = file->f_path.mnt; + nd.flags =0 ; error = -ENOTDIR ; -if (!S_ISDIR (inode->i_mode)) +if (!S_ISDIR (nd.dentry->d_inode->i_mode)) goto out_putf; - error =file_permission (file,MAY_EXEC ); + error =vfs_permission (&nd,MAY_EXEC );if (!error) -set_fs_pwd (current->fs, mnt, dentry); +set_fs_pwd (current->fs, nd.mnt, nd.dentry); out_putf:fput (file); out:
PATCH 44/44 Fix file_permission()
In reply to [email protected]We cannot easily switch from file_permission() to vfs_permission() everywhere, so fix file_permission() to not use a NULL nameidata for the remaining users.
--- fs/namei.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/namei.c +7 -1
@@ -296,7 +296,13 @@ int vfs_permission(struct nameidata *nd,*/ int file_permission (struct file *file,int mask) { -return permission (file->f_path.dentry->d_inode, mask,NULL ); +struct nameidata nd; + + nd.dentry = file->f_path.dentry; + nd.mnt = file->f_path.mnt; + nd.flags =LOOKUP_ACCESS ; + +return permission (nd.dentry->d_inode, mask, &nd); }/*