[PATCH RFC v3 18/44] selinux: use fc_init_pseudo() for selinuxfs

Paul Moore paul at paul-moore.com
Tue Nov 17 23:34:41 UTC 2026


On Nov 16, 2026 sashiko-bot at kernel.org wrote:
> 
> Initialize selinuxfs as a pseudo filesystem. This raises SB_I_PSEUDO and
> SB_I_NOEXEC. selinuxfs never holds executables. SB_I_NOEXEC also
> refuses PROT_EXEC mappings but the status and policy files are only
> ever mapped for reading.
> 
> But selinuxfs needs device nodes. The kernel replaces file descriptors
> with /sys/fs/selinux/null on exec via dentry_open() which doesn't care
> about SB_I_NODEV. Android init however opens /sys/fs/selinux/null by
> path as /dev/null doesn't exist yet at that point. So clear SB_I_NODEV
> again in sel_fill_super().
> 
> Reviewed-by: Alexander Mikhalitsyn <alex at amutable.com>
> Reviewed-by: Chris Down <chris at chrisdown.name>
> Signed-off-by: Christian Brauner (Amutable) <brauner at kernel.org>
> Tested-by: Chris Down <chris at chrisdown.name>
> ---
>  security/selinux/selinuxfs.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
> index 310e19efff1d0..d7ae853b6d685 100644
> --- a/security/selinux/selinuxfs.c
> +++ b/security/selinux/selinuxfs.c
> @@ -18,6 +18,7 @@
>  #include <linux/vmalloc.h>
>  #include <linux/fs.h>
>  #include <linux/fs_context.h>
> +#include <linux/pseudo_fs.h>
>  #include <linux/hex.h>
>  #include <linux/mount.h>
>  #include <linux/mutex.h>
> @@ -1852,6 +1853,9 @@ static int sel_fill_super(struct super_block *sb, struct fs_context *fc)
>  		/* last one */ {"", NULL, 0}
>  	};
>  
> +	/* Android init opens the null device below by path. */
> +	sb->s_iflags &= ~SB_I_NODEV;

See my comment in patch 17/44, this is also used internally in the
flush_unauthorized_files() function.  Once again I would prefer the
comment to be changed to the following:

  /* allow for the /sys/fs/selinux/null device node */

Acked-by: Paul Moore <paul at paul-moore.com>

>  	ret = selinux_fs_info_create(sb);
>  	if (ret)
>  		goto err;
> @@ -1955,6 +1959,7 @@ static const struct fs_context_operations sel_context_ops = {
>  
>  static int sel_init_fs_context(struct fs_context *fc)
>  {
> +	fc_init_pseudo(fc);
>  	fc->ops = &sel_context_ops;
>  	return 0;
>  }
> 
> -- 
> 2.53.0

--
paul-moore.com



More information about the Linux-security-module-archive mailing list