[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250520120000.25501-5-stephen.smalley.work@gmail.com>
Date: Tue, 20 May 2025 07:59:01 -0400
From: Stephen Smalley <stephen.smalley.work@...il.com>
To: selinux@...r.kernel.org
Cc: paul@...l-moore.com,
omosnace@...hat.com,
netdev@...r.kernel.org,
Stephen Smalley <stephen.smalley.work@...il.com>
Subject: [PATCH v3 03/42] selinux: support multiple selinuxfs instances
Support multiple selinuxfs instances, one per selinux namespace.
The expected usage would be to unshare the SELinux namespace and
the mount namespace, and then mount a new selinuxfs instance. The
new instance would then provide an interface for viewing and manipulating
the state of the new SELinux namespace and would not affect the parent
namespace in any manner.
This change by itself should have no effect on SELinux behavior or
APIs (userspace or LSM).
Signed-off-by: Stephen Smalley <stephen.smalley.work@...il.com>
---
security/selinux/selinuxfs.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 3a1217b6e322..aa59a93be5a5 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -2152,9 +2152,33 @@ static int sel_fill_super(struct super_block *sb, struct fs_context *fc)
return ret;
}
+static int selinuxfs_compare(struct super_block *sb, struct fs_context *fc)
+{
+ struct selinux_fs_info *fsi = sb->s_fs_info;
+
+ return (current_selinux_state == fsi->state);
+}
+
static int sel_get_tree(struct fs_context *fc)
{
- return get_tree_single(fc, sel_fill_super);
+ struct super_block *sb;
+ int err;
+
+ sb = sget_fc(fc, selinuxfs_compare, set_anon_super_fc);
+ if (IS_ERR(sb))
+ return PTR_ERR(sb);
+
+ if (!sb->s_root) {
+ err = sel_fill_super(sb, fc);
+ if (err) {
+ deactivate_locked_super(sb);
+ return err;
+ }
+ sb->s_flags |= SB_ACTIVE;
+ }
+
+ fc->root = dget(sb->s_root);
+ return 0;
}
static const struct fs_context_operations sel_context_ops = {
--
2.49.0
Powered by blists - more mailing lists