Re: [PATCH v2] selinux: bpf: check SBLABEL_MNT before isec init

Stephen Smalley <[email protected]> Fri, 31 Jul 2026 08:35:11 -0400
Newsgroups org.kernel.vger.selinux,org.kernel.vger.bpf,org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <CAEjxPJ5PPyM+fkMnLj+FATHtoyYg4TK+tthGpudWnq52GSF6MA@mail.gmail.com>
On Thu, Jul 30, 2026 at 6:15=E2=80=AFPM Carlos Llamas <[email protected]>=
 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: [email protected]
> Closes: https://lore.kernel.org/all/[email protected]/
> Fixes: 9722955b5430 ("bpf: Add simple xattr support to bpffs")
> Acked-by: Stephen Smalley <[email protected]>
> Signed-off-by: Carlos Llamas <[email protected]>

Just re-affirming my Ack since the patch did change slightly.

Acked-by: Stephen Smalley <[email protected]>

> ---
> v2:
>   - Move the check further at the top per Paul's feedback.
>   - Collect Stephen's Ack.
>
> v1:
>   https://lore.kernel.org/all/[email protected]=
m/
>
>  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..18dd28b2bb13 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -2974,6 +2974,10 @@ static int selinux_inode_init_security(struct inod=
e *inode, struct inode *dir,
>
>         sbsec =3D selinux_superblock(dir->i_sb);
>
> +       if (!selinux_initialized() ||
> +           !(sbsec->flags & SBLABEL_MNT))
> +               return -EOPNOTSUPP;
> +
>         newsid =3D crsec->create_sid;
>         newsclass =3D inode_mode_to_security_class(inode->i_mode);
>         rc =3D selinux_determine_inode_label(crsec, dir, qstr, newsclass,=
 &newsid);
> @@ -2988,10 +2992,6 @@ static int selinux_inode_init_security(struct inod=
e *inode, struct inode *dir,
>                 isec->initialized =3D LABEL_INITIALIZED;
>         }
>
> -       if (!selinux_initialized() ||
> -           !(sbsec->flags & SBLABEL_MNT))
> -               return -EOPNOTSUPP;
> -
>         xattr =3D lsm_get_xattr_slot(xattrs, xattr_count);
>         if (xattr) {
>                 rc =3D security_sid_to_context_force(newsid,
> --
> 2.55.0.508.g3f0d502094-goog
>