[PATCH RFC v3 17/44] securityfs: use fc_init_pseudo()
Paul Moore
paul at paul-moore.com
Tue Nov 17 23:34:38 UTC 2026
On Nov 16, 2026 sashiko-bot at kernel.org wrote:
>
> Initialize securityfs as a pseudo filesystem. This raises SB_I_PSEUDO
> and SB_I_NOEXEC. securityfs never holds executables.
>
> But securityfs needs device nodes. AppArmor puts a .null device node
> into securityfs. On exec it replaces file descriptors the new profile
> isn't allowed to use with that node and opens it via dentry_open() which
> doesn't care about SB_I_NODEV. Such a file descriptor can still be
> reopened through /proc/<pid>/fd/<nr> though and that's what opening
> /dev/stderr does. The node itself can also be opened by path as
> /sys/kernel/security/apparmor/.null. Both go through may_open_dev()
> which refuses device nodes with SB_I_NODEV raised. So clear SB_I_NODEV
> again in securityfs_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>
> ---
> security/inode.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/security/inode.c b/security/inode.c
> index 0804023676741..edaebf0f1972d 100644
> --- a/security/inode.c
> +++ b/security/inode.c
> @@ -14,6 +14,7 @@
> #include <linux/kobject.h>
> #include <linux/fs.h>
> #include <linux/fs_context.h>
> +#include <linux/pseudo_fs.h>
> #include <linux/mount.h>
> #include <linux/pagemap.h>
> #include <linux/init.h>
> @@ -49,6 +50,8 @@ static int securityfs_fill_super(struct super_block *sb, struct fs_context *fc)
> return error;
>
> sb->s_op = &securityfs_super_operations;
> + /* Userspace may open AppArmor's .null device node by path. */
> + sb->s_iflags &= ~SB_I_NODEV;
AppArmor itself does a dentry_open() on its null device to effectively
block inheritence of open files if not permitted by policy. SELinux
basically does the same thing, in fact AppArmor's aa_inherit_files()
is based on SELinux's flush_unauthorized_files() according to the
comments.
Anyway, I'd suggest changing your comment to something like the
following, but it's not critical.
/* Allow for LSM specific null device nodes */
Acked-by: Paul Moore <paul at paul-moore.com>
> return 0;
> }
> @@ -64,6 +67,7 @@ static const struct fs_context_operations securityfs_context_ops = {
>
> static int securityfs_init_fs_context(struct fs_context *fc)
> {
> + fc_init_pseudo(fc);
> fc->ops = &securityfs_context_ops;
> return 0;
> }
>
> --
> 2.53.0
--
paul-moore.com
More information about the Linux-security-module-archive
mailing list