kernfs: fix xattr name handling in LSM helpers
authorOndrej Mosnacek <omosnace@redhat.com>
Wed, 3 Apr 2019 07:29:41 +0000 (09:29 +0200)
committerPaul Moore <paul@paul-moore.com>
Thu, 4 Apr 2019 13:00:27 +0000 (09:00 -0400)
commit1537ad15c9c59ce852748578eb5633139053e86b
treea5ac0a90e8e376d1442fbc83a1d18e713717d551
parent593854c05210fccf92a5883ab8a8505837b82199
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>
fs/kernfs/inode.c
include/linux/kernfs.h
security/selinux/hooks.c