From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH v5] selinux: validate primary symbol count when loading policy
Date: Sun, 06 Dec 2026 05:01:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-252154@kernel.org> (raw)
In-Reply-To: <179643369147.1996725.5532974391711154788@skku.edu>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] selinux: unbounded SYM_ROLES nprim allows 4 GiB vmalloc in
policydb_index()
--
commit 6e9bd0ca3cd7432aa4d0db65b40d675a7a002abe
Author: Kyuwon Cho <kyuwon.cho@skku.edu>
selinux: validate primary symbol count when loading policy
This commit bounds primary symbol table counts against the remaining
policy size (with exemptions for roles and pre-v20 types), caps the
class count at U16_MAX, and switches policy index array allocations to
kvzalloc with __GFP_NOWARN.
> diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
> index b75c977c6673d..db302805ca7b9 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c
> @@ -758,23 +758,27 @@ static int policydb_index(struct policydb *p)
[ ... ]
> - p->role_val_to_struct = kzalloc_objs(*p->role_val_to_struct,
> - p->p_roles.nprim);
> + p->role_val_to_struct = kvzalloc_objs(*p->role_val_to_struct,
> + p->p_roles.nprim,
> + GFP_KERNEL | __GFP_NOWARN);
> if (!p->role_val_to_struct)
> return -ENOMEM;
[ ... ]
> @@ -2904,6 +2909,22 @@ 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_CLASSES && nprim > U16_MAX) {
> + pr_err("SELinux: class table has an invalid primary symbol count %u\n",
> + nprim);
> + rc = -EINVAL;
> + goto bad;
> + }
> + if (i != SYM_ROLES &&
> + (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]
Can switching p->role_val_to_struct to kvzalloc_objs() while leaving
SYM_ROLES unbounded let a tiny policy allocate up to ~4 GiB of vmalloc
memory in policydb_index()?
Before this patch, kzalloc_objs() rejected p->p_roles.nprim once the
array exceeded KMALLOC_MAX_SIZE (4 MiB on x86_64), failing fast before
reaching kvcalloc() for p->sym_val_to_name[SYM_ROLES].
With kvzalloc_objs(), __kvmalloc_node_noprof() falls back to vmalloc up
to INT_MAX (2 GiB). A malformed policy with SYM_ROLES nprim set to
0x0fffffff now allocates and zeroes nearly 2 GiB for role_val_to_struct
and another 2 GiB for sym_val_to_name[SYM_ROLES].
Because sel_write_load() runs policydb_read() under
selinux_state.policy_mutex, this stalls concurrent policy and boolean
operations and can pin the memory since sparse role tables are accepted.
Would capping SYM_ROLES nprim avoid this regression?
--
Sashiko AI review · https://sashiko.dev/#/patchset/179643369147.1996725.5532974391711154788@skku.edu?part=1
prev parent reply other threads:[~2026-12-06 5:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 4:47 [PATCH v5] selinux: validate primary symbol count when loading policy Kyuwon Cho
2026-12-06 5:01 ` sashiko-bot [this message]
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-252154@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.