All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH v4] selinux: validate primary symbol count when loading policy
Date: Fri, 04 Dec 2026 20:07:31 +0000	[thread overview]
Message-ID: <sashiko-outbox-250600@kernel.org> (raw)
In-Reply-To: <179641334208.1696188.13639506462697032325@skku.edu>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] selinux: policydb_read() returns 0 on oversized SYM_CLASSES
  nprim
--

commit f5b341ba25ff924a6cef1b9b61666631c03a9a2d
Author: Kyuwon Cho <kyuwon.cho@skku.edu>

selinux: validate primary symbol count when loading policy

This commit validates primary symbol counts against the remaining policy
size (and U16_MAX for classes) in policydb_read(), 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..633508855e165 100644
> --- a/security/selinux/ss/policydb.c
> +++ b/security/selinux/ss/policydb.c

[ ... ]

> @@ -2904,6 +2909,21 @@ 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);
> +			goto bad;
> +		}

[Severity: High]
Does this jump to bad return 0 because rc is still 0 from next_entry()?

At the bad label, policydb_read() calls policydb_destroy(p) and returns rc.
Seeing rc == 0, security_load_policy() continues using the destroyed
policydb instead of aborting the load.

If selinux_set_mapping() then fails (for example with REJECT_UNKNOWN set),
security_load_policy() calls policydb_destroy() a second time.  Because
hashtab_destroy() clears h->htable without resetting h->size, hashtab_map()
triggers a NULL pointer dereference on SYM_COMMONS.

Setting rc = -EINVAL before goto bad fixes this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/179641334208.1696188.13639506462697032325@skku.edu?part=1

      reply	other threads:[~2026-12-04 20:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 19:50 [PATCH v4] selinux: validate primary symbol count when loading policy Kyuwon Cho
2026-12-04 20:07 ` 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-250600@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.