aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2011-02-01 11:05:39 -0500
committerEric Paris <eparis@redhat.com>2011-02-01 11:12:29 -0500
commit2a7dba391e5628ad665ce84ef9a6648da541ebab (patch)
treeba0722bd74d2c883dbda7ff721850bab411cac04 /fs/btrfs
parent821404434f3324bf23f545050ff64055a149766e (diff)
fs/vfs/security: pass last path component to LSM on inode creation
SELinux would like to implement a new labeling behavior of newly created inodes. We currently label new inodes based on the parent and the creating process. This new behavior would also take into account the name of the new object when deciding the new label. This is not the (supposed) full path, just the last component of the path. This is very useful because creating /etc/shadow is different than creating /etc/passwd but the kernel hooks are unable to differentiate these operations. We currently require that userspace realize it is doing some difficult operation like that and than userspace jumps through SELinux hoops to get things set up correctly. This patch does not implement new behavior, that is obviously contained in a seperate SELinux patch, but it does pass the needed name down to the correct LSM hook. If no such name exists it is fine to pass NULL. Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/inode.c13
-rw-r--r--fs/btrfs/xattr.c6
-rw-r--r--fs/btrfs/xattr.h3
3 files changed, 13 insertions, 9 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index a0ff46a47895..49c04bec6a9d 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -90,13 +90,14 @@ static noinline int cow_file_range(struct inode *inode,
90 unsigned long *nr_written, int unlock); 90 unsigned long *nr_written, int unlock);
91 91
92static int btrfs_init_inode_security(struct btrfs_trans_handle *trans, 92static int btrfs_init_inode_security(struct btrfs_trans_handle *trans,
93 struct inode *inode, struct inode *dir) 93 struct inode *inode, struct inode *dir,
94 const struct qstr *qstr)
94{ 95{
95 int err; 96 int err;
96 97
97 err = btrfs_init_acl(trans, inode, dir); 98 err = btrfs_init_acl(trans, inode, dir);
98 if (!err) 99 if (!err)
99 err = btrfs_xattr_security_init(trans, inode, dir); 100 err = btrfs_xattr_security_init(trans, inode, dir, qstr);
100 return err; 101 return err;
101} 102}
102 103
@@ -4675,7 +4676,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
4675 if (IS_ERR(inode)) 4676 if (IS_ERR(inode))
4676 goto out_unlock; 4677 goto out_unlock;
4677 4678
4678 err = btrfs_init_inode_security(trans, inode, dir); 4679 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
4679 if (err) { 4680 if (err) {
4680 drop_inode = 1; 4681 drop_inode = 1;
4681 goto out_unlock; 4682 goto out_unlock;
@@ -4736,7 +4737,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
4736 if (IS_ERR(inode)) 4737 if (IS_ERR(inode))
4737 goto out_unlock; 4738 goto out_unlock;
4738 4739
4739 err = btrfs_init_inode_security(trans, inode, dir); 4740 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
4740 if (err) { 4741 if (err) {
4741 drop_inode = 1; 4742 drop_inode = 1;
4742 goto out_unlock; 4743 goto out_unlock;
@@ -4864,7 +4865,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
4864 4865
4865 drop_on_err = 1; 4866 drop_on_err = 1;
4866 4867
4867 err = btrfs_init_inode_security(trans, inode, dir); 4868 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
4868 if (err) 4869 if (err)
4869 goto out_fail; 4870 goto out_fail;
4870 4871
@@ -6946,7 +6947,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
6946 if (IS_ERR(inode)) 6947 if (IS_ERR(inode))
6947 goto out_unlock; 6948 goto out_unlock;
6948 6949
6949 err = btrfs_init_inode_security(trans, inode, dir); 6950 err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name);
6950 if (err) { 6951 if (err) {
6951 drop_inode = 1; 6952 drop_inode = 1;
6952 goto out_unlock; 6953 goto out_unlock;
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index 698fdd2c739c..3338a7e61d25 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -352,7 +352,8 @@ int btrfs_removexattr(struct dentry *dentry, const char *name)
352} 352}
353 353
354int btrfs_xattr_security_init(struct btrfs_trans_handle *trans, 354int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
355 struct inode *inode, struct inode *dir) 355 struct inode *inode, struct inode *dir,
356 const struct qstr *qstr)
356{ 357{
357 int err; 358 int err;
358 size_t len; 359 size_t len;
@@ -360,7 +361,8 @@ int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
360 char *suffix; 361 char *suffix;
361 char *name; 362 char *name;
362 363
363 err = security_inode_init_security(inode, dir, &suffix, &value, &len); 364 err = security_inode_init_security(inode, dir, qstr, &suffix, &value,
365 &len);
364 if (err) { 366 if (err) {
365 if (err == -EOPNOTSUPP) 367 if (err == -EOPNOTSUPP)
366 return 0; 368 return 0;
diff --git a/fs/btrfs/xattr.h b/fs/btrfs/xattr.h
index 7a43fd640bbb..b3cc8039134b 100644
--- a/fs/btrfs/xattr.h
+++ b/fs/btrfs/xattr.h
@@ -37,6 +37,7 @@ extern int btrfs_setxattr(struct dentry *dentry, const char *name,
37extern int btrfs_removexattr(struct dentry *dentry, const char *name); 37extern int btrfs_removexattr(struct dentry *dentry, const char *name);
38 38
39extern int btrfs_xattr_security_init(struct btrfs_trans_handle *trans, 39extern int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
40 struct inode *inode, struct inode *dir); 40 struct inode *inode, struct inode *dir,
41 const struct qstr *qstr);
41 42
42#endif /* __XATTR__ */ 43#endif /* __XATTR__ */