Linux kernel -stable discussions
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] selinux: require a class's permission values to cover its" failed to apply to 6.18-stable tree
@ 2026-08-20 10:41 gregkh
  2026-08-24 22:00 ` [PATCH 6.18.y 1/3] selinux: use u16 for security classes Sasha Levin
  0 siblings, 1 reply; 37+ messages in thread
From: gregkh @ 2026-08-20 10:41 UTC (permalink / raw)
  To: hexlabsecurity, paul, stephen.smalley.work; +Cc: stable


The patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x b98a8ac50775540f3804397ed08f61ef9910bcab
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026082020-deputize-mosaic-579e@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From b98a8ac50775540f3804397ed08f61ef9910bcab Mon Sep 17 00:00:00 2001
From: Bryam Vargas <hexlabsecurity@proton.me>
Date: Fri, 31 Jul 2026 12:44:10 -0500
Subject: [PATCH] selinux: require a class's permission values to cover its
 permission count

security_get_permissions() sizes an array by the class's permissions.nprim
and fills it at value - 1, from the inherited common's permission table and
then the class's own. A value no permission defines leaves a NULL that
sel_make_perm_files() passes to d_alloc_name(), an oops inside
sel_write_load() that strands selinux_state.policy_mutex and leaves every
later load in uninterruptible sleep; two permissions sharing a value
overwrite the first kstrdup(). Bounding each value by nprim catches
neither, and neither would a count: the symbol table is keyed on the
permission name, so duplicates pass.

Track the values each permission table claims and require them to cover
exactly what its count declares, rejecting a count no value can reach.
Conforming policies are unaffected.

Cc: stable@vger.kernel.org
Fixes: 55fcf09b3fe4 ("selinux: add support for querying object classes and permissions from the running policy")
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index 69777e885ae7..d358200817bd 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -1154,7 +1154,18 @@ int str_read(char **strp, gfp_t flags, struct policy_file *fp, u32 len)
 	return 0;
 }
 
-static int perm_read(struct policydb *p, struct symtab *s, struct policy_file *fp)
+/*
+ * Bitmap of the permission values a symtab has claimed.  Values are 1-based
+ * and bounded by SEL_VEC_MAX, the width of an access vector, so the whole set
+ * fits in a u32 and the callers reject an nprim past that width.
+ */
+static u32 perm_claimed_mask(u32 nprim)
+{
+	return nprim ? U32_MAX >> (SEL_VEC_MAX - nprim) : 0;
+}
+
+static int perm_read(struct policydb *p, struct symtab *s,
+		     struct policy_file *fp, u32 *claimed)
 {
 	char *key = NULL;
 	struct perm_datum *perdatum;
@@ -1178,6 +1189,10 @@ static int perm_read(struct policydb *p, struct symtab *s, struct policy_file *f
 	/* indexes an nprim-sized array in security_get_permissions() */
 	if (perdatum->value > s->nprim)
 		goto bad;
+	/* two permissions cannot share one slot of that array */
+	if (*claimed & (1U << (perdatum->value - 1)))
+		goto bad;
+	*claimed |= 1U << (perdatum->value - 1);
 
 	rc = str_read(&key, GFP_KERNEL, fp, len);
 	if (rc)
@@ -1198,7 +1213,7 @@ static int common_read(struct policydb *p, struct symtab *s, struct policy_file
 	char *key = NULL;
 	struct common_datum *comdatum;
 	__le32 buf[4];
-	u32 i, len, nel;
+	u32 i, len, nel, claimed = 0;
 	int rc;
 
 	comdatum = kzalloc_obj(*comdatum);
@@ -1225,17 +1240,28 @@ static int common_read(struct policydb *p, struct symtab *s, struct policy_file
 	if (rc)
 		goto bad;
 	comdatum->permissions.nprim = le32_to_cpu(buf[2]);
+	/* no permission value can reach a slot past SEL_VEC_MAX */
+	rc = -EINVAL;
+	if (comdatum->permissions.nprim > SEL_VEC_MAX)
+		goto bad;
 
 	rc = str_read(&key, GFP_KERNEL, fp, len);
 	if (rc)
 		goto bad;
 
 	for (i = 0; i < nel; i++) {
-		rc = perm_read(p, &comdatum->permissions, fp);
+		rc = perm_read(p, &comdatum->permissions, fp, &claimed);
 		if (rc)
 			goto bad;
 	}
 
+	rc = -EINVAL;
+	if (claimed != perm_claimed_mask(comdatum->permissions.nprim)) {
+		pr_err("SELinux:  common %s does not define every permission it declares\n",
+		       key);
+		goto bad;
+	}
+
 	hash_eval(&comdatum->permissions.table, "common_permissions", key);
 
 	rc = symtab_insert(s, key, comdatum);
@@ -1369,7 +1395,7 @@ static int class_read(struct policydb *p, struct symtab *s, struct policy_file *
 	char *key = NULL;
 	struct class_datum *cladatum;
 	__le32 buf[6];
-	u32 i, len, len2, ncons, nel, val;
+	u32 i, len, len2, ncons, nel, val, claimed = 0, inherited = 0;
 	int rc;
 
 	cladatum = kzalloc_obj(*cladatum);
@@ -1402,6 +1428,10 @@ static int class_read(struct policydb *p, struct symtab *s, struct policy_file *
 	if (rc)
 		goto bad;
 	cladatum->permissions.nprim = le32_to_cpu(buf[3]);
+	/* no permission value can reach a slot past SEL_VEC_MAX */
+	rc = -EINVAL;
+	if (cladatum->permissions.nprim > SEL_VEC_MAX)
+		goto bad;
 
 	ncons = le32_to_cpu(buf[5]);
 
@@ -1436,11 +1466,22 @@ static int class_read(struct policydb *p, struct symtab *s, struct policy_file *
 		}
 	}
 	for (i = 0; i < nel; i++) {
-		rc = perm_read(p, &cladatum->permissions, fp);
+		rc = perm_read(p, &cladatum->permissions, fp, &claimed);
 		if (rc)
 			goto bad;
 	}
 
+	/* the class's own permissions must claim the slots the common leaves */
+	if (cladatum->comdatum)
+		inherited = cladatum->comdatum->permissions.nprim;
+	rc = -EINVAL;
+	if (claimed != (perm_claimed_mask(cladatum->permissions.nprim) &
+			~perm_claimed_mask(inherited))) {
+		pr_err("SELinux:  class %s does not define every permission it declares\n",
+		       key);
+		goto bad;
+	}
+
 	hash_eval(&cladatum->permissions.table, "class_permissions", key);
 
 	rc = read_cons_helper(p, &cladatum->constraints, ncons, 0, fp);


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

end of thread, other threads:[~2026-08-27 10:37 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20 10:41 FAILED: patch "[PATCH] selinux: require a class's permission values to cover its" failed to apply to 6.18-stable tree gregkh
2026-08-24 22:00 ` [PATCH 6.18.y 1/3] selinux: use u16 for security classes Sasha Levin
2026-08-24 22:00   ` [PATCH 6.18.y 2/3] selinux: more strict policy parsing Sasha Levin
2026-08-24 22:00   ` [PATCH 6.18.y 3/3] selinux: require a class's permission values to cover its permission count Sasha Levin
2026-08-25 10:02     ` Wentao Guan
2026-08-25 10:03     ` [PATCH 6.18.y 1/7] Revert "selinux: reject a permission value exceeding the class permission count" Wentao Guan
2026-08-27  5:17       ` Sasha Levin
2026-08-27  5:47         ` [PATCH 7.1.y 1/5] selinux: use u16 for security classes Wentao Guan
2026-08-27  5:47         ` [PATCH 7.1.y 2/5] selinux: more strict policy parsing Wentao Guan
2026-08-27  5:47         ` [PATCH 7.1.y 3/5] selinux: reject a permission value exceeding the class permission count Wentao Guan
2026-08-27  5:47         ` [PATCH 7.1.y 4/5] selinux: reject a class permission count below its inherited common Wentao Guan
2026-08-27  5:47         ` [PATCH 7.1.y 5/5] selinux: require a class's permission values to cover its permission count Wentao Guan
2026-08-27  8:37         ` [PATCH 6.18.47-rc1 01/10] Revert "selinux: require a class's permission values to cover its permission count" Wentao Guan
2026-08-27  8:59           ` Greg KH
2026-08-27  9:06             ` [PATCH 6.6 00/87] 6.6.154-rc1 review Wentao Guan
2026-08-27  9:07             ` [PATCH 6.18.47-rc1 01/10] Revert "selinux: require a class's permission values to cover its permission count" Wentao Guan
2026-08-27  9:23               ` Greg KH
2026-08-27  9:32                 ` Wentao Guan
2026-08-27 10:32                   ` Greg KH
2026-08-27 10:37                     ` Wentao Guan
2026-08-27  8:37         ` [PATCH 6.18.47-rc1 02/10] Revert "selinux: more strict policy parsing" Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.47-rc1 03/10] Revert "selinux: use u16 for security classes" Wentao Guan
2026-08-27  8:58           ` Greg KH
2026-08-27  9:17             ` Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.y 04/10] Revert "selinux: reject a permission value exceeding the class permission count" Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.y 05/10] Revert "selinux: reject a class permission count below its inherited common" Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.y 06/10] selinux: use u16 for security classes Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.y 07/10] selinux: more strict policy parsing Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.y 08/10] selinux: reject a permission value exceeding the class permission count Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.y 09/10] selinux: reject a class permission count below its inherited common Wentao Guan
2026-08-27  8:38         ` [PATCH 6.18.y 10/10] selinux: require a class's permission values to cover its permission count Wentao Guan
2026-08-25 10:03     ` [PATCH 6.18.y 2/7] Revert "selinux: reject a class permission count below its inherited common" Wentao Guan
2026-08-25 10:03     ` [PATCH 6.18.y 3/7] selinux: use u16 for security classes Wentao Guan
2026-08-25 10:03     ` [PATCH 6.18.y 4/7] selinux: more strict policy parsing Wentao Guan
2026-08-25 10:03     ` [PATCH 6.18.y 5/7] selinux: reject a permission value exceeding the class permission count Wentao Guan
2026-08-25 10:03     ` [PATCH 6.18.y 6/7] selinux: reject a class permission count below its inherited common Wentao Guan
2026-08-25 10:03     ` [PATCH 6.18.y 7/7] selinux: require a class's permission values to cover its permission count Wentao Guan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox