* [PATCH] selinux: fix inconsistency between inode_getxattr and inode_listsecurity
@ 2020-12-19 10:05 Amir Goldstein
2021-01-04 9:39 ` Ondrej Mosnacek
0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2020-12-19 10:05 UTC (permalink / raw)
To: Paul Moore
Cc: Michael Labriola, Jonathan Lebon, Stephen Smalley,
Miklos Szeredi, selinux, linux-security-module, linux-unionfs,
linux-fsdevel, stable
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.
Reported-by: Michael Labriola <michael.d.labriola@gmail.com>
Tested-by: Michael Labriola <michael.d.labriola@gmail.com>
Link: https://lore.kernel.org/linux-unionfs/2nv9d47zt7.fsf@aldarion.sourceruckus.org/
Fixes: c8e222616c7e ("selinux: allow reading labels before policy is loaded")
Cc: stable@vger.kernel.org#v5.9+
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
security/selinux/hooks.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 6b1826fc3658..e132e082a5af 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -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;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selinux: fix inconsistency between inode_getxattr and inode_listsecurity
2020-12-19 10:05 [PATCH] selinux: fix inconsistency between inode_getxattr and inode_listsecurity Amir Goldstein
@ 2021-01-04 9:39 ` Ondrej Mosnacek
2021-01-05 1:46 ` Paul Moore
0 siblings, 1 reply; 3+ messages in thread
From: Ondrej Mosnacek @ 2021-01-04 9:39 UTC (permalink / raw)
To: Amir Goldstein
Cc: Paul Moore, Michael Labriola, Jonathan Lebon, Stephen Smalley,
Miklos Szeredi, SElinux list, Linux Security Module list,
linux-unionfs, linux-fsdevel, Linux Stable maillist
On Sat, Dec 19, 2020 at 11:07 AM Amir Goldstein <amir73il@gmail.com> wrote:
> 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.
>
> Reported-by: Michael Labriola <michael.d.labriola@gmail.com>
> Tested-by: Michael Labriola <michael.d.labriola@gmail.com>
> Link: https://lore.kernel.org/linux-unionfs/2nv9d47zt7.fsf@aldarion.sourceruckus.org/
> Fixes: c8e222616c7e ("selinux: allow reading labels before policy is loaded")
> Cc: stable@vger.kernel.org#v5.9+
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> security/selinux/hooks.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 6b1826fc3658..e132e082a5af 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -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;
> --
> 2.25.1
Looked at the logic in vfs_listxattr() and this looks reasonable.
Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com>
Thank you for the patch!
--
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel
Red Hat, Inc.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selinux: fix inconsistency between inode_getxattr and inode_listsecurity
2021-01-04 9:39 ` Ondrej Mosnacek
@ 2021-01-05 1:46 ` Paul Moore
0 siblings, 0 replies; 3+ messages in thread
From: Paul Moore @ 2021-01-05 1:46 UTC (permalink / raw)
To: Ondrej Mosnacek
Cc: Amir Goldstein, Michael Labriola, Jonathan Lebon,
Stephen Smalley, Miklos Szeredi, SElinux list,
Linux Security Module list, linux-unionfs, linux-fsdevel,
Linux Stable maillist
On Mon, Jan 4, 2021 at 4:39 AM Ondrej Mosnacek <omosnace@redhat.com> wrote:
> On Sat, Dec 19, 2020 at 11:07 AM Amir Goldstein <amir73il@gmail.com> wrote:
> > 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.
> >
> > Reported-by: Michael Labriola <michael.d.labriola@gmail.com>
> > Tested-by: Michael Labriola <michael.d.labriola@gmail.com>
> > Link: https://lore.kernel.org/linux-unionfs/2nv9d47zt7.fsf@aldarion.sourceruckus.org/
> > Fixes: c8e222616c7e ("selinux: allow reading labels before policy is loaded")
> > Cc: stable@vger.kernel.org#v5.9+
> > Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> > ---
> > security/selinux/hooks.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 6b1826fc3658..e132e082a5af 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -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;
> > --
> > 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!
--
paul moore
www.paul-moore.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-05 1:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-19 10:05 [PATCH] selinux: fix inconsistency between inode_getxattr and inode_listsecurity Amir Goldstein
2021-01-04 9:39 ` Ondrej Mosnacek
2021-01-05 1:46 ` Paul Moore
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).