All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH 4/4] selinux: require every boolean value to be defined
Date: Fri, 31 Jul 2026 18:01:27 +0000	[thread overview]
Message-ID: <20260731180127.D92F21F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260731-b4-disp-d32e997b-v1-4-0341d038ee47@proton.me>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing validation for sparse types and users in `policydb_context_isvalid()` allows a crafted SELinux policy to trigger kernel panics.
--

--- Patch [4]: [PATCH 4/4] selinux: require every boolean value to be defined ---
commit 44c8d8193cd1a1c62c2bebd114870d7131ceb5ab
Author: Bryam Vargas <hexlabsecurity@proton.me>

selinux: require every boolean value to be defined

This commit adds validation during SELinux policy loading to ensure every
declared boolean is defined. This prevents NULL pointer dereferences when
consumers iterate over the bool_val_to_struct array.

Cc: stable@vger.kernel.org

> diff --git a/security/selinux/ss/policydb.c b/security/selinux/ss/policydb.c
> index d358200817bd9..d88713201be92 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c

[ ... ]

> @@ -769,6 +770,24 @@ static int policydb_index(struct policydb *p)
>  		if (rc)
>  			goto out;
>  	}
> +
> +	/*
> +	 * A sparse class value is absorbed by policydb_class_isvalid() and
> +	 * its siblings, but no such predicate exists for booleans: every
> +	 * user of bool_val_to_struct[] walks it by index and dereferences
> +	 * each entry -- cond_evaluate_expr(), the two getters and
> +	 * security_set_bools() -- so an unclaimed one has no consumer that
> +	 * can tolerate it.
> +	 */
> +	for (v = 0; v < p->p_bools.nprim; v++) {
> +		if (!p->bool_val_to_struct[v]) {
> +			pr_err("SELinux:  boolean %u is declared but not defined\n",
> +			       v + 1);
> +			rc = -EINVAL;
> +			goto out;
> +		}
> +	}
> +

[Severity: High]
This is a pre-existing issue, but since this patch adds validation for
sparse booleans, is it necessary to add similar validation for sparse types
and users?

Context validation skips checking if the type is actually defined when
c->role == OBJECT_R_VAL:

security/selinux/ss/policydb.c:policydb_context_isvalid() {
    ...
    if (!c->type || c->type > p->p_types.nprim)
        return false;

    if (c->role != OBJECT_R_VAL) {
    ...
}

If a crafted policy assigns a sparse type to an object context, it is
accepted. Later, when the context is evaluated, does this trigger a kernel
panic when fetching the NULL struct?

security/selinux/ss/services.c:type_attribute_bounds_av() {
    ...
    target = policydb->type_val_to_struct[tcontext->type - 1];
    BUG_ON(!target);
    ...
}

It also looks like this could cause a NULL pointer dereference during string
conversion (such as in audit logs) because sym_name() returns NULL:

security/selinux/ss/services.c:context_struct_to_string() {
    ...
    *scontext_len += strlen(sym_name(p, SYM_TYPES, context->type - 1)) + 1;
    ...
}

Could a malicious container policy exploit this missing type validation to
crash the host system?

>  	rc = 0;
>  out:
>  	return rc;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260731-b4-disp-d32e997b-v1-0-0341d038ee47@proton.me?part=4

      reply	other threads:[~2026-07-31 18:01 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
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 [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=20260731180127.D92F21F00AC4@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.