All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH v2 3/7] LSM: Two hooks for manipulating struct lsm_prop
Date: Wed, 02 Sep 2026 22:16:35 +0000	[thread overview]
Message-ID: <20260902221635.D3C9E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902220150.18586-4-casey@schaufler-ca.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The wrapper security_secctx_to_lsmprop() fails to zero-initialize the output struct lsm_prop, risking uninitialized memory usage.
- [Medium] Inconsistent default return value for unsupported security_secctx_to_lsmprop operation (-EINVAL vs -EOPNOTSUPP).
- [Low] The `update_lsmprop` hook leaks framework routing details by requiring `lsmid` as a parameter, forcing LSM implementations to duplicate dispatch filtering instead of handling it centrally in the LSM framework.
--

commit 945240d1e544dee2c2c0632c7b84efeac1548fde
Author: Casey Schaufler <casey@schaufler-ca.com>

LSM: Two hooks for manipulating struct lsm_prop

This commit introduces two new hooks, update_lsmprop and secctx_to_lsmprop,
which allow updating the properties of a specified LSM and setting the 
lsm_prop field based on a passed security context.

> diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
> index 65c9609ec2077..679c40a8e1275 100644
> --- a/include/linux/lsm_hook_defs.h
> +++ b/include/linux/lsm_hook_defs.h
[ ... ]
> @@ -305,7 +305,11 @@ LSM_HOOK(int, 0, ismaclabel, const char *name)
>  LSM_HOOK(int, -EOPNOTSUPP, secid_to_secctx, u32 secid, struct lsm_context *cp)
>  LSM_HOOK(int, -EOPNOTSUPP, lsmprop_to_secctx, struct lsm_prop *prop,
>  	 struct lsm_context *cp)
> +LSM_HOOK(void, LSM_RET_VOID, update_lsmprop, struct lsm_prop *dest,
> +	 struct lsm_prop *src, int lsmid)

[Severity: Low]
Does exposing lsmid directly to the update_lsmprop hook break the
encapsulation of the LSM routing mechanism? In the LSM framework, targeted
hooks usually handle lsmid filtering centrally in security.c using an
explicit loop (e.g., lsmprop_to_secctx). By broadcasting with call_void_hook
and passing lsmid, individual LSMs are forced to implement duplicate
filtering rather than having it handled by the framework.

>  LSM_HOOK(int, 0, secctx_to_secid, const char *secdata, u32 seclen, u32 *secid)
> +LSM_HOOK(int, -EINVAL, secctx_to_lsmprop, const char *secdata, u32 seclen,
> +	 struct lsm_prop *prop)

[Severity: Medium]
Is -EINVAL the correct default return value here? The inline stub for
CONFIG_SECURITY=n in security.h returns -EOPNOTSUPP. Returning -EINVAL when
no LSM handles the hook might incorrectly imply a parsing error rather than
a lack of support, potentially altering user-space visible error codes
(e.g., returning -EINVAL instead of -ENOENT or -EOPNOTSUPP from
xtables/nftables).

>  LSM_HOOK(void, LSM_RET_VOID, release_secctx, struct lsm_context *cp)
>  LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode)
>  LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen)
> diff --git a/security/security.c b/security/security.c
> index 71aea8fdf0142..1dec0037370ba 100644
> --- a/security/security.c
> +++ b/security/security.c
[ ... ]
> @@ -3982,6 +3989,31 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
>  }
>  EXPORT_SYMBOL(security_secctx_to_secid);
>  
> +/**
> + * security_secctx_to_lsmprop() - Convert a secctx to a lsmprop
> + * @secdata: secctx
> + * @seclen: length of secctx
> + * @prop: prop
> + * @lsmid: which LSM the context is appropriate to.
> + *
> + * Convert security context to an lsmprop.
> + *
> + * Return: Returns 0 on success, error on failure.
> + */
> +int security_secctx_to_lsmprop(const char *secdata, u32 seclen,
> +			       struct lsm_prop *prop, int lsmid)
> +{
> +	struct lsm_static_call *scall;
> +
> +	lsm_for_each_hook(scall, secctx_to_lsmprop) {

[Severity: High]
Should this function zero-initialize the output struct lsm_prop (perhaps
via lsmprop_init) before calling the hooks?

Callers typically allocate struct lsm_prop on the stack without
initialization, and the active LSM hook only populates its own specific
field. This leaves the rest of the struct as uninitialized stack garbage.

If callers pass this partially initialized structure to secxa_from_lsmprop(),
the memcmp() and kmemdup() operations on the entire struct will evaluate the
stack garbage. This could leak kernel stack memory into the secxa_xa xarray
heap object and cause identical contexts to mismatch, potentially leading to
unbounded memory allocation and a denial of service.

> +		if (lsmid != LSM_ID_UNDEF && lsmid != scall->hl->lsmid->id)
> +			continue;
> +		return scall->hl->hook.secctx_to_lsmprop(secdata, seclen, prop);
> +	}
> +	return LSM_RET_DEFAULT(secctx_to_lsmprop);
> +}
> +EXPORT_SYMBOL(security_secctx_to_lsmprop);
> +

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902220150.18586-1-casey@schaufler-ca.com?part=3

  reply	other threads:[~2026-09-02 22:16 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
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 [this message]
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=20260902221635.D3C9E1F000E9@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.