From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH 3/4] selinux: reject an unclaimed class value in security_get_classes()
Date: Fri, 31 Jul 2026 18:03:31 +0000 [thread overview]
Message-ID: <20260731180332.20FF81F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260731-b4-disp-d32e997b-v1-3-0341d038ee47@proton.me>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The boolean symbol table can be sparse, leading to unconditional NULL pointer dereferences in `security_get_bools()`, `security_set_bools()`, and `cond_evaluate_expr()`.
--
--- Patch [3]: [PATCH 3/4] selinux: reject an unclaimed class value in security_get_classes() ---
commit 8c3d50aa472cc225281a590fe76e7aab43766da5
Author: Bryam Vargas <hexlabsecurity@proton.me>
selinux: reject an unclaimed class value in security_get_classes()
This commit updates security_get_classes() to fail the lookup if a class
value went unclaimed. This prevents a NULL pointer dereference in
sel_make_classes() when the policy defines a sparse class symbol table.
> diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> index 90e81186cb2ee..7afce975436e9 100644
> --- a/security/selinux/ss/services.c
> +++ b/security/selinux/ss/services.c
[ ... ]
> @@ -3316,16 +3317,29 @@ int security_get_classes(struct selinux_policy *policy,
>
> rc = hashtab_map(&policydb->p_classes.table, get_classes_callback,
> *classes);
> - if (rc) {
> - u32 i;
> + if (rc)
> + goto err;
>
> - for (i = 0; i < *nclasses; i++)
> - kfree((*classes)[i]);
> - kfree(*classes);
> + /*
> + * The class symtab may be sparse, which policydb_class_isvalid() exists
> + * to absorb; the callback fills this array by value, so an unclaimed
> + * one leaves a NULL that sel_make_classes() hands to sel_make_dir().
> + */
> + for (i = 0; i < *nclasses; i++) {
> + if (!(*classes)[i]) {
> + rc = -EINVAL;
> + goto err;
> + }
> }
[Severity: High]
This is a pre-existing issue, but since this patch handles sparse class
symbol tables, does the boolean symbol table have a similar vulnerability?
In security/selinux/ss/services.c:security_get_bools(), there is an
unconditional dereference of bool_val_to_struct:
security_get_bools() {
...
(*values)[i] = policydb->bool_val_to_struct[i]->state;
...
}
Similarly in security/selinux/ss/services.c:security_set_bools():
security_set_bools() {
...
int old_state = newpolicy->policydb.bool_val_to_struct[i]->state;
...
}
And in security/selinux/ss/conditional.c:cond_evaluate_expr():
cond_evaluate_expr() {
...
s[sp] = p->bool_val_to_struct[node->boolean - 1]->state;
...
}
Can a malformed policy with a sparse boolean symbol table cause a NULL
pointer dereference in these locations?
> out:
> return rc;
> +
> +err:
> + for (i = 0; i < *nclasses; i++)
> + kfree((*classes)[i]);
> + kfree(*classes);
> + return rc;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260731-b4-disp-d32e997b-v1-0-0341d038ee47@proton.me?part=3
next prev parent reply other threads:[~2026-07-31 18:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 17:44 [PATCH 0/4] selinux: make declared counts account for the values Bryam Vargas via B4 Relay
2026-07-31 17:44 ` Bryam Vargas
2026-07-31 17:44 ` [PATCH 1/4] selinux: do not cancel a policy conversion that never started Bryam Vargas via B4 Relay
2026-07-31 17:44 ` Bryam Vargas
2026-07-31 17:58 ` sashiko-bot
2026-07-31 19:40 ` Stephen Smalley
2026-07-31 17:44 ` [PATCH 2/4] selinux: require a class's permission values to cover its permission count Bryam Vargas via B4 Relay
2026-07-31 17:44 ` Bryam Vargas
2026-07-31 17:50 ` sashiko-bot
2026-07-31 19:44 ` Stephen Smalley
2026-07-31 17:44 ` [PATCH 3/4] selinux: reject an unclaimed class value in security_get_classes() Bryam Vargas via B4 Relay
2026-07-31 17:44 ` Bryam Vargas
2026-07-31 18:03 ` sashiko-bot [this message]
2026-07-31 19:46 ` Stephen Smalley
2026-07-31 17:44 ` [PATCH 4/4] selinux: require every boolean value to be defined Bryam Vargas via B4 Relay
2026-07-31 17:44 ` Bryam Vargas
2026-07-31 18:01 ` sashiko-bot
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=20260731180332.20FF81F00AC4@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.