From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH v3] selinux: validate primary symbol count when loading policy
Date: Fri, 04 Dec 2026 05:21:33 +0000 [thread overview]
Message-ID: <sashiko-outbox-249131@kernel.org> (raw)
In-Reply-To: <179633283854.20472.2166041983398323812@skku.edu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selinux: oversized p_classes.nprim warns in
security_get_classes()
--
commit d4902f40a6a7734f5f4e7db2f7f69f69e560e87e
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
selinux: validate primary symbol count when loading policy
This commit bounds each symbol table's primary count by the remaining
policy size in policydb_read() and switches policy index array
allocations to kvzalloc/kvcalloc with __GFP_NOWARN.
> diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
> index b75c977c6673d..92dbb43fafbae 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c
[ ... ]
> @@ -2904,6 +2909,14 @@ 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 (i != SYM_TYPES || p->policyvers >= POLICYDB_VERSION_AVTAB) {
> + 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;
> + }
> + }
[Severity: Medium]
Should SYM_CLASSES also be capped at U16_MAX here, or does an oversized
p_classes.nprim still trigger an allocator warning in
security_get_classes()?
Now that policydb_index() uses kvzalloc_objs() for class_val_to_struct,
a ~2.1 MiB padded policy with p_classes.nprim > 524288 passes
size_check() and succeeds in security_load_policy().
sel_write_load() then calls sel_make_policy_nodes() ->
sel_make_classes() -> security_get_classes():
security/selinux/ss/services.c:security_get_classes() {
...
*nclasses = policydb->p_classes.nprim;
*classes = kcalloc(*nclasses, sizeof(**classes), GFP_ATOMIC);
if (!*classes)
goto out;
...
}
On 64-bit 4 KiB-page kernels, that kcalloc() exceeds KMALLOC_MAX_SIZE
without __GFP_NOWARN and triggers the order > MAX_PAGE_ORDER warning in
alloc_order_allowed(). Since class_read() already rejects class values
above U16_MAX, capping SYM_CLASSES nprim at U16_MAX would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/179633283854.20472.2166041983398323812@skku.edu?part=1
next prev parent reply other threads:[~2026-12-04 5:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 5:06 [PATCH v3] selinux: validate primary symbol count when loading policy Kyuwon Cho
2026-12-04 5:21 ` sashiko-bot [this message]
2026-12-04 13:48 ` Stephen Smalley
2026-12-04 13:53 ` Stephen Smalley
2026-12-04 18:19 ` 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-249131@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.