summaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorOndrej Mosnacek <omosnace@redhat.com>2019-04-03 03:29:41 -0400
committerPaul Moore <paul@paul-moore.com>2019-04-04 09:00:27 -0400
commit1537ad15c9c59ce852748578eb5633139053e86b (patch)
treea5ac0a90e8e376d1442fbc83a1d18e713717d551 /security
parent593854c05210fccf92a5883ab8a8505837b82199 (diff)
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 <rong.a.chen@intel.com> Fixes: b230d5aba2d1 ("LSM: add new hook for kernfs node initialization") Fixes: ec882da5cda9 ("selinux: implement the kernfs_init_security hook") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'security')
-rw-r--r--security/selinux/hooks.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index b6e61524d68d..d5fdcb0d26fe 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3394,7 +3394,7 @@ static int selinux_kernfs_init_security(struct kernfs_node *kn_dir,
3394 int rc; 3394 int rc;
3395 char *context; 3395 char *context;
3396 3396
3397 rc = kernfs_security_xattr_get(kn_dir, XATTR_SELINUX_SUFFIX, NULL, 0); 3397 rc = kernfs_xattr_get(kn_dir, XATTR_NAME_SELINUX, NULL, 0);
3398 if (rc == -ENODATA) 3398 if (rc == -ENODATA)
3399 return 0; 3399 return 0;
3400 else if (rc < 0) 3400 else if (rc < 0)
@@ -3405,8 +3405,7 @@ static int selinux_kernfs_init_security(struct kernfs_node *kn_dir,
3405 if (!context) 3405 if (!context)
3406 return -ENOMEM; 3406 return -ENOMEM;
3407 3407
3408 rc = kernfs_security_xattr_get(kn_dir, XATTR_SELINUX_SUFFIX, context, 3408 rc = kernfs_xattr_get(kn_dir, XATTR_NAME_SELINUX, context, clen);
3409 clen);
3410 if (rc < 0) { 3409 if (rc < 0) {
3411 kfree(context); 3410 kfree(context);
3412 return rc; 3411 return rc;
@@ -3439,8 +3438,8 @@ static int selinux_kernfs_init_security(struct kernfs_node *kn_dir,
3439 if (rc) 3438 if (rc)
3440 return rc; 3439 return rc;
3441 3440
3442 rc = kernfs_security_xattr_set(kn, XATTR_SELINUX_SUFFIX, context, clen, 3441 rc = kernfs_xattr_set(kn, XATTR_NAME_SELINUX, context, clen,
3443 XATTR_CREATE); 3442 XATTR_CREATE);
3444 kfree(context); 3443 kfree(context);
3445 return rc; 3444 return rc;
3446} 3445}