mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 11:41:38 -04:00
kernfs: fix xattr name handling in LSM helpers
The implementation of kernfs_security_xattr_*() helpers reuses the kernfs_node_xattr_*() functions, which take the suffix of the xattr name and extract full xattr name from it using xattr_full_name(). However, this function relies on the fact that the suffix passed to xattr handlers from VFS is always constructed from the full name by just incerementing the pointer. This doesn't necessarily hold for the callers of kernfs_security_xattr_*(), so their usage will easily lead to out-of-bounds access. Fix this by moving the xattr name reconstruction to the VFS xattr handlers and replacing the kernfs_security_xattr_*() helpers with more general kernfs_xattr_*() helpers that take full xattr name and allow accessing all kernfs node's xattrs. Reported-by: kernel test robot <[email protected]> Fixes:b230d5aba2("LSM: add new hook for kernfs node initialization") Fixes:ec882da5cd("selinux: implement the kernfs_init_security hook") Signed-off-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Paul Moore <[email protected]>
This commit is contained in:
parent
593854c052
commit
1537ad15c9
3 changed files with 33 additions and 56 deletions
|
|
@ -3394,7 +3394,7 @@ static int selinux_kernfs_init_security(struct kernfs_node *kn_dir,
|
|||
int rc;
|
||||
char *context;
|
||||
|
||||
rc = kernfs_security_xattr_get(kn_dir, XATTR_SELINUX_SUFFIX, NULL, 0);
|
||||
rc = kernfs_xattr_get(kn_dir, XATTR_NAME_SELINUX, NULL, 0);
|
||||
if (rc == -ENODATA)
|
||||
return 0;
|
||||
else if (rc < 0)
|
||||
|
|
@ -3405,8 +3405,7 @@ static int selinux_kernfs_init_security(struct kernfs_node *kn_dir,
|
|||
if (!context)
|
||||
return -ENOMEM;
|
||||
|
||||
rc = kernfs_security_xattr_get(kn_dir, XATTR_SELINUX_SUFFIX, context,
|
||||
clen);
|
||||
rc = kernfs_xattr_get(kn_dir, XATTR_NAME_SELINUX, context, clen);
|
||||
if (rc < 0) {
|
||||
kfree(context);
|
||||
return rc;
|
||||
|
|
@ -3439,8 +3438,8 @@ static int selinux_kernfs_init_security(struct kernfs_node *kn_dir,
|
|||
if (rc)
|
||||
return rc;
|
||||
|
||||
rc = kernfs_security_xattr_set(kn, XATTR_SELINUX_SUFFIX, context, clen,
|
||||
XATTR_CREATE);
|
||||
rc = kernfs_xattr_set(kn, XATTR_NAME_SELINUX, context, clen,
|
||||
XATTR_CREATE);
|
||||
kfree(context);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue