All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selinux: Free MLS range category bitmaps on load failure
@ 2026-12-04  5:04 Haoxiang Li
  2026-12-04  5:09 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Haoxiang Li @ 2026-12-04  5:04 UTC (permalink / raw)
  To: paul, stephen.smalley.work, omosnacek, cgzones, hexlabsecurity,
	jmorris
  Cc: selinux, Haoxiang Li

After mls_read_range_helper() successfully initializes an MLS range,
range validation or hash table insertion may fail. The error paths
free the range structure without destroying its category bitmaps,
leaking the allocated bitmap nodes.

Destroy both category bitmaps before freeing the range if validation
or insertion fails.

Fixes: 2f3e82d694d3 ("selinux: convert range transition list to a hashtab")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 security/selinux/ss/policydb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index fe0c0792583f..d2ebe53222c7 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -2276,18 +2276,23 @@ static int range_read(struct policydb *p, struct policy_file *fp)
 		rc = -EINVAL;
 		if (!mls_range_isvalid(p, r)) {
 			pr_warn("SELinux:  rangetrans:  invalid range\n");
-			goto out;
+			goto out_destroy;
 		}
 
 		rc = hashtab_insert(&p->range_tr, rt, r, rangetr_key_params);
 		if (rc)
-			goto out;
+			goto out_destroy;
 
 		rt = NULL;
 		r = NULL;
 	}
 	hash_eval(&p->range_tr, "rangetr", NULL);
-	rc = 0;
+
+	return 0;
+
+out_destroy:
+	ebitmap_destroy(&r->level[0].cat);
+	ebitmap_destroy(&r->level[1].cat);
 out:
 	kfree(rt);
 	kfree(r);
-- 
2.25.1


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

end of thread, other threads:[~2026-12-04 17:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  5:04 [PATCH] selinux: Free MLS range category bitmaps on load failure Haoxiang Li
2026-12-04  5:09 ` sashiko-bot
2026-12-04 13:41 ` Stephen Smalley
2026-12-04 17:29 ` Paul Moore

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.