Skip to content

Commit 924e19c

Browse files
Xu Kuohaipcmoore
authored andcommitted
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 <[email protected]> Reviewed-by: Casey Schaufler <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent be72a57 commit 924e19c

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

fs/overlayfs/copy_up.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de
115115
continue;
116116

117117
error = security_inode_copy_up_xattr(old, name);
118-
if (error < 0 && error != -EOPNOTSUPP)
119-
break;
120-
if (error == 1) {
118+
if (error == -ECANCELED) {
121119
error = 0;
122120
continue; /* Discard */
123121
}
122+
if (error < 0 && error != -EOPNOTSUPP)
123+
break;
124124

125125
if (is_posix_acl_xattr(name)) {
126126
error = ovl_copy_acl(OVL_FS(sb), oldpath, new, name);

security/integrity/evm/evm_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ static int evm_inode_copy_up_xattr(struct dentry *src, const char *name)
10001000
case EVM_XATTR_HMAC:
10011001
case EVM_IMA_XATTR_DIGSIG:
10021002
default:
1003-
rc = 1; /* discard */
1003+
rc = -ECANCELED; /* discard */
10041004
}
10051005

10061006
kfree(xattr_data);

security/security.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,19 +2674,14 @@ EXPORT_SYMBOL(security_inode_copy_up);
26742674
* lower layer to the union/overlay layer. The caller is responsible for
26752675
* reading and writing the xattrs, this hook is merely a filter.
26762676
*
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.
26802680
*/
26812681
int security_inode_copy_up_xattr(struct dentry *src, const char *name)
26822682
{
26832683
int rc;
26842684

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-
*/
26902685
rc = call_int_hook(inode_copy_up_xattr, src, name);
26912686
if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr))
26922687
return rc;

security/selinux/hooks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,8 +3531,8 @@ static int selinux_inode_copy_up_xattr(struct dentry *dentry, const char *name)
35313531
* xattrs up. Instead, filter out SELinux-related xattrs following
35323532
* policy load.
35333533
*/
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 */
35363536
/*
35373537
* Any other attribute apart from SELINUX is not claimed, supported
35383538
* by selinux.

security/smack/smack_lsm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4910,10 +4910,10 @@ static int smack_inode_copy_up(struct dentry *dentry, struct cred **new)
49104910
static int smack_inode_copy_up_xattr(struct dentry *src, const char *name)
49114911
{
49124912
/*
4913-
* Return 1 if this is the smack access Smack attribute.
4913+
* Return -ECANCELED if this is the smack access Smack attribute.
49144914
*/
4915-
if (strcmp(name, XATTR_NAME_SMACK) == 0)
4916-
return 1;
4915+
if (!strcmp(name, XATTR_NAME_SMACK))
4916+
return -ECANCELED;
49174917

49184918
return -EOPNOTSUPP;
49194919
}

0 commit comments

Comments
 (0)