selinux: fix inconsistency between inode_getxattr and inode_listsecurity
Subsystems (4)
PATCH 1/1 selinux: fix inconsistency between inode_getxattr and inode_listsecurity
When inode has no listxattr op of its own (e.g. squashfs) vfs_listxattr calls the LSM inode_listsecurity hooks to list the xattrs that LSMs will intercept in inode_getxattr hooks.
When selinux LSM is installed but not initialized, it will list the security.selinux xattr in inode_listsecurity, but will not intercept it in inode_getxattr. This results in -ENODATA for a getxattr call for an xattr returned by listxattr.
This situation was manifested as overlayfs failure to copy up lower files from squashfs when selinux is built-in but not initialized, because ovl_copy_xattr() iterates the lower inode xattrs by vfs_listxattr() and vfs_getxattr().
Match the logic of inode_listsecurity to that of inode_getxattr and do not list the security.selinux xattr if selinux is not initialized.
--- security/selinux/hooks.c | 4 ++++ 1 file changed, 4 insertions(+)
security/selinux/hooks.c +4 -0
@@ -3406,6 +3406,10 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,static int selinux_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size) {const int len =sizeof (XATTR_NAME_SELINUX ); + +if (!selinux_initialized (&selinux_state)) +return 0 ; +if (buffer && len <= buffer_size)memcpy (buffer,XATTR_NAME_SELINUX , len);return len;
Signature · 1 line
2.25.1
Quoted 43 lines · Amir Goldstein
When inode has no listxattr op of its own (e.g. squashfs)
vfs_listxattrcalls the LSMinode_listsecurityhooks to list the xattrs that LSMs will intercept ininode_getxattrhooks.When selinux LSM is installed but not initialized, it will list the security.selinux xattr in
inode_listsecurity, but will not intercept it ininode_getxattr. This results in-ENODATAfor a getxattr call for an xattr returned by listxattr.This situation was manifested as overlayfs failure to copy up lower files from squashfs when selinux is built-in but not initialized, because
ovl_copy_xattr()iterates the lower inode xattrs byvfs_listxattr()andvfs_getxattr().Match the logic of
inode_listsecurityto that ofinode_getxattrand do not list the security.selinux xattr if selinux is not initialized.Reported-by Michael Labriola <[email protected]>Tested-by Michael Labriola <[email protected]>Fixes c8e222616c7e ("selinux: allow reading labels before policy is loaded")Cc [email protected]#v5.9+Signed-off-by Amir Goldstein <[email protected]>--- security/selinux/hooks.c | 4 ++++ 1 file changed, 4 insertions(+)security/selinux/hooks.c +4
-1@@ -3406,6 +3406,10 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,static int selinux_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size) {const int len =sizeof (XATTR_NAME_SELINUX ); + +if (!selinux_initialized (&selinux_state)) +return 0 ; +if (buffer && len <= buffer_size)memcpy (buffer,XATTR_NAME_SELINUX , len);return len; --
Quoted 1 line
2.25.1
Looked at the logic in vfs_listxattr() and this looks reasonable.
Thank you for the patch!
Signature · 3 lines
Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.
Paul Moore
maintainerQuoted 39 lines · Ondrej Mosnacek
Quoted 38 lines · Amir Goldstein
When inode has no listxattr op of its own (e.g. squashfs)
vfs_listxattrcalls the LSMinode_listsecurityhooks to list the xattrs that LSMs will intercept ininode_getxattrhooks.When selinux LSM is installed but not initialized, it will list the security.selinux xattr in
inode_listsecurity, but will not intercept it ininode_getxattr. This results in-ENODATAfor a getxattr call for an xattr returned by listxattr.This situation was manifested as overlayfs failure to copy up lower files from squashfs when selinux is built-in but not initialized, because
ovl_copy_xattr()iterates the lower inode xattrs byvfs_listxattr()andvfs_getxattr().Match the logic of
inode_listsecurityto that ofinode_getxattrand do not list the security.selinux xattr if selinux is not initialized.Reported-by Michael Labriola <[email protected]>Tested-by Michael Labriola <[email protected]>Fixes c8e222616c7e ("selinux: allow reading labels before policy is loaded")Cc [email protected]#v5.9+Signed-off-by Amir Goldstein <[email protected]>--- security/selinux/hooks.c | 4 ++++ 1 file changed, 4 insertions(+)security/selinux/hooks.c +3
-0@@ -3406,6 +3406,10 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,static int selinux_inode_listsecurity (struct inode *inode,char *buffer,size_t buffer_size) {const int len =sizeof (XATTR_NAME_SELINUX ); + +if (!selinux_initialized (&selinux_state)) +return 0 ;
Quoted 8 lines
Quoted 6 lines
security/selinux/hooks.c +1
-1+if (buffer && len <= buffer_size)memcpy (buffer,XATTR_NAME_SELINUX , len);return len; --2.25.1
Looked at the logic in
vfs_listxattr()and this looks reasonable.
Agreed, this looks good to me too; I'll merge it into selinux/next. Thanks everyone!
Signature · 2 lines
paul moore www.paul-moore.com