selinux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH selinuxns 1/3] selinux: do not cache sblabel mount flag in superblock
@ 2025-11-18 15:46 Stephen Smalley
  2025-11-18 15:46 ` [RFC PATCH selinuxns 2/3] selinux: do not cache genfs xattr flag in superblock security blob Stephen Smalley
  2025-11-18 15:46 ` [RFC PATCH selinuxns 3/3] selinux: ignore invalid contexts in kernfs_init_security in child namespace Stephen Smalley
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Smalley @ 2025-11-18 15:46 UTC (permalink / raw)
  To: mertsas; +Cc: selinux, paul, omosnace, Stephen Smalley

Currently SELinux determines whether the superblock supports
security labeling at superblock creation time and caches it
as a SBLABEL_MNT flag in the superblock security blob. However,
with the introduciton of SELinux namespaces, this can change
within a child SELinux namespace due to a different value for
the cgroupseclabel policy capability in its policy. Stop
precomputing and caching this flag and instead check it on use.

Signed-off-by: Stephen Smalley <stephen.smalley.work@gmail.com>
---
 security/selinux/hooks.c            | 22 ++++++----------------
 security/selinux/include/security.h |  1 -
 2 files changed, 6 insertions(+), 17 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 7003a3f96ead..61171c45329f 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -581,16 +581,6 @@ static int sb_finish_set_opts(struct super_block *sb)
 
 	sbsec->flags |= SE_SBINITIALIZED;
 
-	/*
-	 * Explicitly set or clear SBLABEL_MNT.  It's not sufficient to simply
-	 * leave the flag untouched because sb_clone_mnt_opts might be handing
-	 * us a superblock that needs the flag to be cleared.
-	 */
-	if (selinux_is_sblabel_mnt(sb))
-		sbsec->flags |= SBLABEL_MNT;
-	else
-		sbsec->flags &= ~SBLABEL_MNT;
-
 	/* Initialize the root inode. */
 	rc = inode_doinit_with_dentry(root_inode, root);
 
@@ -1141,7 +1131,7 @@ static int selinux_sb_show_options(struct seq_file *m, struct super_block *sb)
 		if (rc)
 			return rc;
 	}
-	if (sbsec->flags & SBLABEL_MNT) {
+	if (selinux_is_sblabel_mnt(sb)) {
 		seq_putc(m, ',');
 		seq_puts(m, SECLABEL_STR);
 	}
@@ -1815,7 +1805,7 @@ selinux_determine_inode_label(const struct task_security_struct *tsec,
 	if ((sbsec->flags & SE_SBINITIALIZED) &&
 	    (sbsec->behavior == SECURITY_FS_USE_MNTPOINT)) {
 		*_new_isid = sbsec->mntpoint_sid;
-	} else if ((sbsec->flags & SBLABEL_MNT) &&
+	} else if (selinux_is_sblabel_mnt(dir->i_sb) &&
 		   tsec->create_sid) {
 		*_new_isid = tsec->create_sid;
 	} else {
@@ -3023,7 +3013,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
 	}
 
 	if (!selinux_initialized(current_selinux_state) ||
-	    !(sbsec->flags & SBLABEL_MNT))
+	    !selinux_is_sblabel_mnt(dir->i_sb))
 		return -EOPNOTSUPP;
 
 	if (xattr) {
@@ -3454,7 +3444,7 @@ static int selinux_inode_setxattr(struct mnt_idmap *idmap,
 		return (inode_owner_or_capable(idmap, inode) ? 0 : -EPERM);
 
 	sbsec = selinux_superblock(inode->i_sb);
-	if (!(sbsec->flags & SBLABEL_MNT))
+	if (!selinux_is_sblabel_mnt(inode->i_sb))
 		return -EOPNOTSUPP;
 
 	if (!inode_owner_or_capable(idmap, inode))
@@ -3730,7 +3720,7 @@ static int selinux_inode_setsecurity(struct inode *inode, const char *name,
 		return -EOPNOTSUPP;
 
 	sbsec = selinux_superblock(inode->i_sb);
-	if (!(sbsec->flags & SBLABEL_MNT))
+	if (!selinux_is_sblabel_mnt(inode->i_sb))
 		return -EOPNOTSUPP;
 
 	if (!value || !size)
@@ -7105,7 +7095,7 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
 {
 	int rc = selinux_inode_setsecurity(inode, XATTR_SELINUX_SUFFIX,
 					   ctx, ctxlen, 0);
-	/* Do not return error when suppressing label (SBLABEL_MNT not set). */
+	/* Do not return error when suppressing label. */
 	return rc == -EOPNOTSUPP ? 0 : rc;
 }
 
diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
index e3e0b1eb7575..c5df7a0b0069 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -63,7 +63,6 @@
 #define FSCONTEXT_MNT	0x02
 #define ROOTCONTEXT_MNT 0x04
 #define DEFCONTEXT_MNT	0x08
-#define SBLABEL_MNT	0x10
 /* Non-mount related flags */
 #define SE_SBINITIALIZED 0x0100
 #define SE_SBPROC	 0x0200
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-18 15:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-18 15:46 [RFC PATCH selinuxns 1/3] selinux: do not cache sblabel mount flag in superblock Stephen Smalley
2025-11-18 15:46 ` [RFC PATCH selinuxns 2/3] selinux: do not cache genfs xattr flag in superblock security blob Stephen Smalley
2025-11-18 15:46 ` [RFC PATCH selinuxns 3/3] selinux: ignore invalid contexts in kernfs_init_security in child namespace Stephen Smalley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).