From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH] selinux: validate primary symbol count when loading policy
Date: Thu, 03 Dec 2026 17:28:05 +0000 [thread overview]
Message-ID: <sashiko-outbox-248262@kernel.org> (raw)
In-Reply-To: <179621430413.2669974.16944159499886043558@skku.edu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selinux: policydb_read() rejects valid pre-v24 policies where
nprim > nel
--
commit 7c587f0526cf279c4d9f66db4544173a329147fa
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
selinux: validate primary symbol count when loading policy
This commit adds a check in policydb_read() to reject symbol tables whose
primary symbol count (nprim) exceeds the entry count (nel) with -EINVAL.
> diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
> index b75c977c6673d..5eb17378483b6 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c
> @@ -2904,6 +2904,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]);
> + if (nprim > nel) {
> + pr_err("SELinux: symbol table %u has %u primary names but only %u entries\n",
> + i, nprim, nel);
> + rc = -EINVAL;
> + goto bad;
> + }
[Severity: Medium]
Does rejecting nprim > nel break loading valid policies older than
POLICYDB_VERSION_BOUNDARY (versions 15 through 23)?
Before POLICYDB_VERSION_BOUNDARY, type_read() has no attribute flag, so
valid policies omit type attributes from serialized SYM_TYPES entries
(nel) while still counting their IDs in p->p_types.nprim.
Any pre-v24 policy with more type attributes than type aliases therefore
has nprim > nel and will now fail to load with -EINVAL.
Top-level symbol tables can also be sparse, and roles_init()
pre-populates OBJECT_R into SYM_ROLES, so a policy omitting object_r
would hit the same rejection.
Guarding this check for pre-POLICYDB_VERSION_BOUNDARY SYM_TYPES (or
bounding nprim against the remaining policy image size) would avoid
rejecting valid legacy policies.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179621430413.2669974.16944159499886043558@skku.edu?part=1
next prev parent reply other threads:[~2026-12-03 17:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 16:41 [PATCH] selinux: validate primary symbol count when loading policy Kyuwon Cho
2026-12-03 17:28 ` sashiko-bot [this message]
2026-12-03 17:37 ` Stephen Smalley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-248262@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.