Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lsm: Refactor return value of LSM hook inode_copy_up_xattr

To be consistent with most LSM hooks, convert the return value of
hook inode_copy_up_xattr to 0 or a negative error code.

Before:
- Hook inode_copy_up_xattr returns 0 when accepting xattr, 1 when
discarding xattr, -EOPNOTSUPP if it does not know xattr, or any
other negative error code otherwise.

After:
- Hook inode_copy_up_xattr returns 0 when accepting xattr, *-ECANCELED*
when discarding xattr, -EOPNOTSUPP if it does not know xattr, or
any other negative error code otherwise.

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Reviewed-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Xu Kuohai and committed by
Paul Moore
924e19c3 be72a575

+12 -17
+3 -3
fs/overlayfs/copy_up.c
··· 115 115 continue; 116 116 117 117 error = security_inode_copy_up_xattr(old, name); 118 - if (error < 0 && error != -EOPNOTSUPP) 119 - break; 120 - if (error == 1) { 118 + if (error == -ECANCELED) { 121 119 error = 0; 122 120 continue; /* Discard */ 123 121 } 122 + if (error < 0 && error != -EOPNOTSUPP) 123 + break; 124 124 125 125 if (is_posix_acl_xattr(name)) { 126 126 error = ovl_copy_acl(OVL_FS(sb), oldpath, new, name);
+1 -1
security/integrity/evm/evm_main.c
··· 1000 1000 case EVM_XATTR_HMAC: 1001 1001 case EVM_IMA_XATTR_DIGSIG: 1002 1002 default: 1003 - rc = 1; /* discard */ 1003 + rc = -ECANCELED; /* discard */ 1004 1004 } 1005 1005 1006 1006 kfree(xattr_data);
+3 -8
security/security.c
··· 2674 2674 * lower layer to the union/overlay layer. The caller is responsible for 2675 2675 * reading and writing the xattrs, this hook is merely a filter. 2676 2676 * 2677 - * Return: Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP 2678 - * if the security module does not know about attribute, or a negative 2679 - * error code to abort the copy up. 2677 + * Return: Returns 0 to accept the xattr, -ECANCELED to discard the xattr, 2678 + * -EOPNOTSUPP if the security module does not know about attribute, 2679 + * or a negative error code to abort the copy up. 2680 2680 */ 2681 2681 int security_inode_copy_up_xattr(struct dentry *src, const char *name) 2682 2682 { 2683 2683 int rc; 2684 2684 2685 - /* 2686 - * The implementation can return 0 (accept the xattr), 1 (discard the 2687 - * xattr), -EOPNOTSUPP if it does not know anything about the xattr or 2688 - * any other error code in case of an error. 2689 - */ 2690 2685 rc = call_int_hook(inode_copy_up_xattr, src, name); 2691 2686 if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr)) 2692 2687 return rc;
+2 -2
security/selinux/hooks.c
··· 3531 3531 * xattrs up. Instead, filter out SELinux-related xattrs following 3532 3532 * policy load. 3533 3533 */ 3534 - if (selinux_initialized() && strcmp(name, XATTR_NAME_SELINUX) == 0) 3535 - return 1; /* Discard */ 3534 + if (selinux_initialized() && !strcmp(name, XATTR_NAME_SELINUX)) 3535 + return -ECANCELED; /* Discard */ 3536 3536 /* 3537 3537 * Any other attribute apart from SELINUX is not claimed, supported 3538 3538 * by selinux.
+3 -3
security/smack/smack_lsm.c
··· 4910 4910 static int smack_inode_copy_up_xattr(struct dentry *src, const char *name) 4911 4911 { 4912 4912 /* 4913 - * Return 1 if this is the smack access Smack attribute. 4913 + * Return -ECANCELED if this is the smack access Smack attribute. 4914 4914 */ 4915 - if (strcmp(name, XATTR_NAME_SMACK) == 0) 4916 - return 1; 4915 + if (!strcmp(name, XATTR_NAME_SMACK)) 4916 + return -ECANCELED; 4917 4917 4918 4918 return -EOPNOTSUPP; 4919 4919 }