Re: [PATCH] selinux: bpf: check SBLABEL_MNT before isec init
From: Carlos Llamas
Date: Thu Jul 30 2026 - 18:13:56 EST
On Thu, Jul 30, 2026 at 05:10:00PM -0400, Paul Moore wrote:
> On Jul 30, 2026 Carlos Llamas <cmllamas@xxxxxxxxxx> wrote:
> >
> > selinux_inode_init_security() marks the isec as initialized before
> > checking if mount labeling is supported (SBLABEL_MNT). This was fine
> > until commit 9722955b5430 ("bpf: Add simple xattr support to bpffs"),
> > where genfscon bpffs mounts fail the SBLABEL_MNT check as expected (no
> > xattrs) and yet leave the isec->initialized. This breaks subsequent
> > calls to inode_doinit_with_dentry().
> >
> > Do the SBLABEL_MNT check before the inode security is initialized.
> >
> > Cc: stable@xxxxxxxxxxxxxxx
> > Closes: https://lore.kernel.org/all/akWdcp6P0FkNDzBk@xxxxxxxxxx/
> > Fixes: 9722955b5430 ("bpf: Add simple xattr support to bpffs")
> > Signed-off-by: Carlos Llamas <cmllamas@xxxxxxxxxx>
> > Acked-by: Stephen Smalley <stephen.smalley.work@xxxxxxxxx>
> > ---
> > security/selinux/hooks.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> > index 8d6945edae7a..09a12eb8652c 100644
> > --- a/security/selinux/hooks.c
> > +++ b/security/selinux/hooks.c
> > @@ -2980,6 +2980,10 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
> > if (rc)
> > return rc;
> >
> > + if (!selinux_initialized() ||
> > + !(sbsec->flags & SBLABEL_MNT))
> > + return -EOPNOTSUPP;
>
> If we're moving this check, we should probably just move it to right
> after we assign 'sbsec' at the top of the function. The calls to
> inode_mode_to_security() and selinux_determine_inode_label() aren't
> doing anything useful in either the !selinux_initialized() or !SBLABEL_MNT
> cases so let's avoid the unnecessary work.
Ha! That is a really good point. Let me move the check further up then.