Commit 924e19c3 authored by Xu Kuohai's avatar Xu Kuohai Committed by Paul Moore

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: default avatarXu Kuohai <xukuohai@huawei.com>
Reviewed-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent be72a575
...@@ -115,12 +115,12 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de ...@@ -115,12 +115,12 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de
continue; continue;
error = security_inode_copy_up_xattr(old, name); error = security_inode_copy_up_xattr(old, name);
if (error < 0 && error != -EOPNOTSUPP) if (error == -ECANCELED) {
break;
if (error == 1) {
error = 0; error = 0;
continue; /* Discard */ continue; /* Discard */
} }
if (error < 0 && error != -EOPNOTSUPP)
break;
if (is_posix_acl_xattr(name)) { if (is_posix_acl_xattr(name)) {
error = ovl_copy_acl(OVL_FS(sb), oldpath, new, name); error = ovl_copy_acl(OVL_FS(sb), oldpath, new, name);
......
...@@ -1000,7 +1000,7 @@ static int evm_inode_copy_up_xattr(struct dentry *src, const char *name) ...@@ -1000,7 +1000,7 @@ static int evm_inode_copy_up_xattr(struct dentry *src, const char *name)
case EVM_XATTR_HMAC: case EVM_XATTR_HMAC:
case EVM_IMA_XATTR_DIGSIG: case EVM_IMA_XATTR_DIGSIG:
default: default:
rc = 1; /* discard */ rc = -ECANCELED; /* discard */
} }
kfree(xattr_data); kfree(xattr_data);
......
...@@ -2674,19 +2674,14 @@ EXPORT_SYMBOL(security_inode_copy_up); ...@@ -2674,19 +2674,14 @@ EXPORT_SYMBOL(security_inode_copy_up);
* lower layer to the union/overlay layer. The caller is responsible for * lower layer to the union/overlay layer. The caller is responsible for
* reading and writing the xattrs, this hook is merely a filter. * reading and writing the xattrs, this hook is merely a filter.
* *
* Return: Returns 0 to accept the xattr, 1 to discard the xattr, -EOPNOTSUPP * Return: Returns 0 to accept the xattr, -ECANCELED to discard the xattr,
* if the security module does not know about attribute, or a negative * -EOPNOTSUPP if the security module does not know about attribute,
* error code to abort the copy up. * or a negative error code to abort the copy up.
*/ */
int security_inode_copy_up_xattr(struct dentry *src, const char *name) int security_inode_copy_up_xattr(struct dentry *src, const char *name)
{ {
int rc; int rc;
/*
* The implementation can return 0 (accept the xattr), 1 (discard the
* xattr), -EOPNOTSUPP if it does not know anything about the xattr or
* any other error code in case of an error.
*/
rc = call_int_hook(inode_copy_up_xattr, src, name); rc = call_int_hook(inode_copy_up_xattr, src, name);
if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr)) if (rc != LSM_RET_DEFAULT(inode_copy_up_xattr))
return rc; return rc;
......
...@@ -3531,8 +3531,8 @@ static int selinux_inode_copy_up_xattr(struct dentry *dentry, const char *name) ...@@ -3531,8 +3531,8 @@ static int selinux_inode_copy_up_xattr(struct dentry *dentry, const char *name)
* xattrs up. Instead, filter out SELinux-related xattrs following * xattrs up. Instead, filter out SELinux-related xattrs following
* policy load. * policy load.
*/ */
if (selinux_initialized() && strcmp(name, XATTR_NAME_SELINUX) == 0) if (selinux_initialized() && !strcmp(name, XATTR_NAME_SELINUX))
return 1; /* Discard */ return -ECANCELED; /* Discard */
/* /*
* Any other attribute apart from SELINUX is not claimed, supported * Any other attribute apart from SELINUX is not claimed, supported
* by selinux. * by selinux.
......
...@@ -4910,10 +4910,10 @@ static int smack_inode_copy_up(struct dentry *dentry, struct cred **new) ...@@ -4910,10 +4910,10 @@ static int smack_inode_copy_up(struct dentry *dentry, struct cred **new)
static int smack_inode_copy_up_xattr(struct dentry *src, const char *name) static int smack_inode_copy_up_xattr(struct dentry *src, const char *name)
{ {
/* /*
* Return 1 if this is the smack access Smack attribute. * Return -ECANCELED if this is the smack access Smack attribute.
*/ */
if (strcmp(name, XATTR_NAME_SMACK) == 0) if (!strcmp(name, XATTR_NAME_SMACK))
return 1; return -ECANCELED;
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment