All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] selinux: validate primary symbol count when loading policy
@ 2026-12-03 19:51 Kyuwon Cho
  2026-12-03 20:11 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-03 19:51 UTC (permalink / raw)
  To: Paul Moore, Stephen Smalley
  Cc: Ondrej Mosnáček, sashiko-reviews, selinux

policydb_index() sizes multiple arrays from each symbol table primary
count. A malformed policy can provide a count large enough to trigger an
allocator warning while containing almost no symbol data.

The primary count can legitimately exceed the serialized entry count,
particularly for type attributes in policy versions before 24. Bound the
count by the remaining policy image instead of assuming a dense symbol
table. This rejects the malformed input without excluding valid legacy
policies.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
Changes in v2:
- Bound nprim by the remaining policy image instead of comparing it with
  nel, as suggested by the Sashiko review.
- Loaded versions 15, 20, 23, 24, 30, and 35 generated by both checkpolicy
  and secilc, as requested by Stephen Smalley.

v1: https://lore.kernel.org/all/179621430413.2669974.16944159499886043558@skku.edu/

The issue was found by an LLM-guided test generator that we are
developing as a research prototype.

A reproducer is available on request.

 security/selinux/ss/policydb.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
index fe0c0792583f..9e96d8e69474 100644
--- a/security/selinux/ss/policydb.c
+++ b/security/selinux/ss/policydb.c
@@ -3015,6 +3015,12 @@ int policydb_read(struct policydb *p, struct policy_file *fp)
 			goto bad;
 		nprim = le32_to_cpu(buf[0]);
 		nel = le32_to_cpu(buf[1]);
+		rc = size_check(sizeof(u32), nprim, fp);
+		if (rc) {
+			pr_err("SELinux:  symbol table %u has an invalid primary symbol count %u\n",
+			       i, nprim);
+			goto bad;
+		}
 
 		/* every read_f() implementation reads at least 128 bytes
 		 * for any valid entry
-- 
2.43.0


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

end of thread, other threads:[~2026-12-03 20:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 19:51 [PATCH v2] selinux: validate primary symbol count when loading policy Kyuwon Cho
2026-12-03 20:11 ` sashiko-bot

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.