Skip to content

Commit 3253804

Browse files
stefanbergermimizohar
authored andcommitted
security: allow finer granularity in permitting copy-up of security xattrs
Copying up xattrs is solely based on the security xattr name. For finer granularity add a dentry parameter to the security_inode_copy_up_xattr hook definition, allowing decisions to be based on the xattr content as well. Co-developed-by: Mimi Zohar <[email protected]> Signed-off-by: Stefan Berger <[email protected]> Acked-by: Amir Goldstein <[email protected]> Acked-by: Paul Moore <[email protected]> (LSM,SELinux) Signed-off-by: Mimi Zohar <[email protected]>
1 parent c21632b commit 3253804

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

fs/overlayfs/copy_up.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de
114114
if (ovl_is_private_xattr(sb, name))
115115
continue;
116116

117-
error = security_inode_copy_up_xattr(name);
117+
error = security_inode_copy_up_xattr(old, name);
118118
if (error < 0 && error != -EOPNOTSUPP)
119119
break;
120120
if (error == 1) {

include/linux/lsm_hook_defs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char *buffer,
176176
size_t buffer_size)
177177
LSM_HOOK(void, LSM_RET_VOID, inode_getsecid, struct inode *inode, u32 *secid)
178178
LSM_HOOK(int, 0, inode_copy_up, struct dentry *src, struct cred **new)
179-
LSM_HOOK(int, -EOPNOTSUPP, inode_copy_up_xattr, const char *name)
179+
LSM_HOOK(int, -EOPNOTSUPP, inode_copy_up_xattr, struct dentry *src,
180+
const char *name)
180181
LSM_HOOK(int, 0, kernfs_init_security, struct kernfs_node *kn_dir,
181182
struct kernfs_node *kn)
182183
LSM_HOOK(int, 0, file_permission, struct file *file, int mask)

include/linux/security.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int security_inode_setsecurity(struct inode *inode, const char *name, const void
398398
int security_inode_listsecurity(struct inode *inode, char *buffer, size_t buffer_size);
399399
void security_inode_getsecid(struct inode *inode, u32 *secid);
400400
int security_inode_copy_up(struct dentry *src, struct cred **new);
401-
int security_inode_copy_up_xattr(const char *name);
401+
int security_inode_copy_up_xattr(struct dentry *src, const char *name);
402402
int security_kernfs_init_security(struct kernfs_node *kn_dir,
403403
struct kernfs_node *kn);
404404
int security_file_permission(struct file *file, int mask);
@@ -1016,7 +1016,7 @@ static inline int security_kernfs_init_security(struct kernfs_node *kn_dir,
10161016
return 0;
10171017
}
10181018

1019-
static inline int security_inode_copy_up_xattr(const char *name)
1019+
static inline int security_inode_copy_up_xattr(struct dentry *src, const char *name)
10201020
{
10211021
return -EOPNOTSUPP;
10221022
}

security/integrity/evm/evm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ static void evm_inode_post_setattr(struct mnt_idmap *idmap,
946946
evm_update_evmxattr(dentry, NULL, NULL, 0);
947947
}
948948

949-
static int evm_inode_copy_up_xattr(const char *name)
949+
static int evm_inode_copy_up_xattr(struct dentry *src, const char *name)
950950
{
951951
if (strcmp(name, XATTR_NAME_EVM) == 0)
952952
return 1; /* Discard */

security/security.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,7 @@ EXPORT_SYMBOL(security_inode_copy_up);
26282628

26292629
/**
26302630
* security_inode_copy_up_xattr() - Filter xattrs in an overlayfs copy-up op
2631+
* @src: union dentry of copy-up file
26312632
* @name: xattr name
26322633
*
26332634
* Filter the xattrs being copied up when a unioned file is copied up from a
@@ -2638,7 +2639,7 @@ EXPORT_SYMBOL(security_inode_copy_up);
26382639
* if the security module does not know about attribute, or a negative
26392640
* error code to abort the copy up.
26402641
*/
2641-
int security_inode_copy_up_xattr(const char *name)
2642+
int security_inode_copy_up_xattr(struct dentry *src, const char *name)
26422643
{
26432644
int rc;
26442645

@@ -2647,7 +2648,7 @@ int security_inode_copy_up_xattr(const char *name)
26472648
* xattr), -EOPNOTSUPP if it does not know anything about the xattr or
26482649
* any other error code in case of an error.
26492650
*/
2650-
rc = call_int_hook(inode_copy_up_xattr, name);
2651+
rc = call_int_hook(inode_copy_up_xattr, src, name);
26512652
if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr))
26522653
return rc;
26532654

security/selinux/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,7 @@ static int selinux_inode_copy_up(struct dentry *src, struct cred **new)
35303530
return 0;
35313531
}
35323532

3533-
static int selinux_inode_copy_up_xattr(const char *name)
3533+
static int selinux_inode_copy_up_xattr(struct dentry *dentry, const char *name)
35343534
{
35353535
/* The copy_up hook above sets the initial context on an inode, but we
35363536
* don't then want to overwrite it by blindly copying all the lower

security/smack/smack_lsm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4885,7 +4885,7 @@ static int smack_inode_copy_up(struct dentry *dentry, struct cred **new)
48854885
return 0;
48864886
}
48874887

4888-
static int smack_inode_copy_up_xattr(const char *name)
4888+
static int smack_inode_copy_up_xattr(struct dentry *src, const char *name)
48894889
{
48904890
/*
48914891
* Return 1 if this is the smack access Smack attribute.

0 commit comments

Comments
 (0)