From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH] selinux: reject a permission value exceeding the class permission count
Date: Fri, 24 Jul 2026 15:18:22 +0000 [thread overview]
Message-ID: <20260724151822.BB8661F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260724-b4-disp-ec8ac9f6-v1-1-d76d51a69b9d@proton.me>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch prevents an out-of-bounds write for class-specific permissions but fails to address the identical vulnerability when a class inherits permissions from a common. If a malicious policy declares a common with a large `nprim` and a class that inherits it but specifies a small `nprim`, the common permissions will bypass the patch's check and map to out-of-bounds indices in `security_get_permissions()`.
- [High] NULL pointer dereference in selinuxfs when a policy contains gaps in permission or class values. If a policy defines a sparse set of values (e.g., `nprim` is 3, but only values 1 and 3 are populated), `security_get_permissions()` leaves gaps in its allocated string array as NULL pointers. When `sel_make_perm_files()` iterates through these arrays, it passes the NULL pointers to `sel_attach_file()`, causing a kernel panic.
--
--- Patch [1]: [PATCH] selinux: reject a permission value exceeding the class permission count ---
commit eb44c136ba9338c4aa49d6ec88bea5f639bd151b
Author: Bryam Vargas <hexlabsecurity@proton.me>
selinux: reject a permission value exceeding the class permission count
This commit adds a bounds check in perm_read() to ensure a permission value
does not exceed the nprim value of its owning class or common. It attempts
to prevent an out-of-bounds heap write when security_get_permissions()
allocates an array sized by nprim and populates it.
> diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
> index ead504a639e36..6973b68d9782a 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c
> @@ -1175,6 +1175,9 @@ static int perm_read(struct policydb *p, struct symtab *s, struct policy_file *f
> rc = -EINVAL;
> if (perdatum->value < 1 || perdatum->value > SEL_VEC_MAX)
> goto bad;
> + /* the value indexes an nprim-sized array in security_get_permissions() */
> + if (perdatum->value > s->nprim)
> + goto bad;
[Severity: High]
This is a pre-existing issue, but does this patch fully prevent the
out-of-bounds write if a class inherits permissions from a common?
While this check bounds the permission value against its immediate
symbol table's nprim, it seems a malicious policy could declare a
common with a large nprim and a class that inherits it with a small
nprim.
The parser sets the class's nprim without validating it against the
inherited common:
security/selinux/ss/policydb.c:class_read() {
...
cladatum->permissions.nprim = le32_to_cpu(buf[3]);
...
}
Then security_get_permissions() allocates an array based solely on the
class's nprim:
security/selinux/ss/services.c:security_get_permissions() {
...
*nperms = match->permissions.nprim;
*perms = kcalloc(*nperms, sizeof(**perms), GFP_ATOMIC);
...
if (match->comdatum) {
rc = hashtab_map(&match->comdatum->permissions.table,
get_permissions_callback, *perms);
...
}
Since the common permissions bypass this patch's symtab-specific bounds
check and are mapped into the undersized perms array, could this still
lead to a slab-out-of-bounds write in get_permissions_callback()?
[Severity: High]
This is a pre-existing issue, but could this sparse array allocation
lead to a null pointer dereference later on?
If a policy defines a sparse set of values (for instance, if nprim is 3
but only values 1 and 3 are populated), get_permissions_callback() maps
the present permissions:
security/selinux/ss/services.c:get_permissions_callback() {
...
perms[value] = kstrdup(name, GFP_ATOMIC);
...
}
This leaves intermediate unpopulated indices as NULL in the array. When
sel_make_perm_files() iterates through this array:
security/selinux/selinuxfs.c:sel_make_perm_files() {
...
for (i = 0; i < nperms; i++) {
rc = sel_attach_file(dir, perms[i], inode);
...
}
It passes the NULL pointer to sel_attach_file(), which passes it to
d_alloc_name(), which requires a valid string for hashlen_string().
Can this cause a kernel panic when a process loads such a crafted policy?
>
> rc = str_read(&key, GFP_KERNEL, fp, len);
> if (rc)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724-b4-disp-ec8ac9f6-v1-1-d76d51a69b9d@proton.me?part=1
next prev parent reply other threads:[~2026-07-24 15:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 14:47 [PATCH] selinux: reject a permission value exceeding the class permission count Bryam Vargas via B4 Relay
2026-07-24 14:47 ` Bryam Vargas
2026-07-24 15:18 ` sashiko-bot [this message]
2026-07-24 15:23 ` Stephen Smalley
2026-07-24 15:48 ` Stephen Smalley
2026-07-24 15:56 ` Stephen Smalley
2026-07-24 17:07 ` Bryam Vargas
2026-07-24 17:11 ` 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=20260724151822.BB8661F000E9@smtp.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.