From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH v2 2/7] LSM: Implement x array functions for secmarks
Date: Wed, 02 Sep 2026 22:21:03 +0000 [thread overview]
Message-ID: <20260902222103.919821F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902220150.18586-3-casey@schaufler-ca.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Using `memcmp()` to compare `struct lsm_prop` fails to match identical properties due to uninitialized padding bytes.
- [High] Time-Of-Check to Time-Of-Use (TOCTOU) race condition in `secxa_from_lsmprop` allows duplicate XArray entries and memory leaks.
--
commit 9623dfb3d9ce13325263af52c93bc771e66bc688
Author: Casey Schaufler <casey@schaufler-ca.com>
LSM: Implement x array functions for secmarks
This commit implements the functions required to map lsm_prop structures to
xarray indexes for use in secmarks. It introduces secxa_get_lsmprop() and
secxa_from_lsmprop() to manage the mapping.
> diff --git a/security/lsm_secxa.c b/security/lsm_secxa.c
> new file mode 100644
> index 0000000000000..ccbe78095d703
> --- /dev/null
> +++ b/security/lsm_secxa.c
[ ... ]
> +/**
> + * secxa_from_lsmprop - get the secxa associated with a lsm_prop
> + * @prop: lsm_prop pointer
> + * @secxa: result
> + *
> + * Find the secxa associated with @prop. If there is none, create it.
> + *
> + * Returns 0, or an error if the mapping cannot be created
> + */
> +int secxa_from_lsmprop(struct lsm_prop *prop, u32 *secxa)
> +{
> + struct lsm_prop *lp;
> + unsigned long il;
> + u32 index = 0;
> + int rc;
> +
> + xa_for_each(&secxa_xa, il, lp) {
> + if (!memcmp(prop, lp, sizeof(*prop))) {
[Severity: Critical]
Will this memcmp() check fail to match identical properties due to uninitialized
padding bytes?
If struct lsm_prop is ever allocated on the stack without zeroing the entire
structure, the padding bytes or inactive fields could contain uninitialized
stack garbage.
This might cause logically identical properties to fail the memcmp() comparison,
resulting in continuous duplicate allocations and rapid exhaustion of the 31-bit
ID space.
> + *secxa = il;
> + return 0;
> + }
> + }
> +
> + lp = kzalloc(sizeof(*lp), GFP_ATOMIC);
> + if (!lp)
> + return -ENOMEM;
> + *lp = *prop;
> +
> + rc = xa_alloc_bh(&secxa_xa, &index, lp, xa_limit_31b, GFP_ATOMIC);
[Severity: High]
Is there a time-of-check to time-of-use race condition when inserting new
entries into the xarray?
The xa_for_each() loop above performs a lockless search for an existing entry.
If multiple threads execute secxa_from_lsmprop() concurrently and simultaneously
fail to find a match, they will all proceed to allocate memory and call
xa_alloc_bh().
Since xa_alloc_bh() simply acquires the lock to assign a new ID and does not
re-verify if an identical lsm_prop was just inserted by another thread, could
this result in duplicate entries and memory leaks over time?
> + if (rc) {
> + kfree(lp);
> + return -EINVAL;
> + }
> +
> + *secxa = index;
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260902220150.18586-1-casey@schaufler-ca.com?part=2
next prev parent reply other threads:[~2026-09-02 22:21 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260902220150.18586-1-casey.ref@schaufler-ca.com>
2026-09-02 22:01 ` [PATCH v2 0/7] Change skb secmarks to x-array indexes Casey Schaufler
2026-09-02 22:01 ` [PATCH v2 1/7] net, smack: Create a function to set secmarks Casey Schaufler
2026-09-02 22:13 ` sashiko-bot
2026-09-03 5:35 ` John Johansen
2026-09-02 22:01 ` [PATCH v2 2/7] LSM: Implement x array functions for secmarks Casey Schaufler
2026-09-02 22:21 ` sashiko-bot [this message]
2026-09-03 5:36 ` John Johansen
2026-09-02 22:01 ` [PATCH v2 3/7] LSM: Two hooks for manipulating struct lsm_prop Casey Schaufler
2026-09-02 22:16 ` sashiko-bot
2026-09-03 9:40 ` John Johansen
2026-09-02 22:01 ` [PATCH v2 4/7] SELinux: hooks for secctx_to_lsmprop and update_lsmprop Casey Schaufler
2026-09-02 22:10 ` sashiko-bot
2026-09-03 6:10 ` John Johansen
2026-09-02 22:01 ` [PATCH v2 5/7] Smack: " Casey Schaufler
2026-09-02 22:17 ` sashiko-bot
2026-09-03 6:15 ` John Johansen
2026-09-02 22:01 ` [PATCH v2 6/7] Apparmor: " Casey Schaufler
2026-09-02 22:16 ` sashiko-bot
2026-09-03 9:39 ` John Johansen
2026-09-02 22:01 ` [PATCH v2 7/7] net, lsm: Change skb secmarks to x-array indexes Casey Schaufler
2026-09-02 22:15 ` sashiko-bot
2026-09-03 7:31 ` John Johansen
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=20260902222103.919821F000E9@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.