SELinux Security Module development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH 5/7] Smack: hooks for secctx_to_lsmprop and update_lsmprop
Date: Mon, 31 Aug 2026 23:01:37 +0000	[thread overview]
Message-ID: <20260831230137.A62AF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831223748.4304-6-casey@schaufler-ca.com>

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

New issues:
- [High] `smack_secctx_to_lsmprop` sets `prop->smack.skp` to NULL for unknown contexts but returns success, leading to a later NULL pointer dereference in `smack_lsmprop_to_secctx`.

Pre-existing issues:
- [High] The `smack_secctx_to_lsmprop` function ignores the `seclen` parameter and passes a potentially non-NUL-terminated buffer to `smk_find_entry()`, resulting in an out-of-bounds read.
--

commit 7c2ef4130b3b7eeea3057be8cb9283a398ff6cf7
Author: Casey Schaufler <casey@schaufler-ca.com>

Smack: hooks for secctx_to_lsmprop and update_lsmprop

This commit implements the secctx_to_lsmprop and update_lsmprop hooks for
the Smack LSM module. These hooks provide conversions and updates between
security contexts and lsm_prop structures.

> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index ff115068c5c06..fcfadd5d99941 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
[ ... ]
> @@ -4909,6 +4909,37 @@ static int smack_lsmprop_to_secctx(struct lsm_prop *prop,
>  	return smack_to_secctx(prop->smack.skp, cp);
>  }
>  
> +/**
> + * smack_secctx_to_lsmprop - add the smack label to an lsmprop
> + * @secdata: smack label
> + * @seclen: how long label is
> + * @prop: where to put the result
> + *
> + * Exists for audit and networking code.
> + */
> +static int smack_secctx_to_lsmprop(const char *secdata, u32 seclen,
> +				   struct lsm_prop *prop)
> +{
> +	prop->smack.skp = smk_find_entry(secdata);

[Severity: High]
This isn't a bug introduced by this patch, but does this ignore the seclen
parameter and pass a potentially non-NUL-terminated buffer to
smk_find_entry()?

If secdata comes from a netlink NLA_BINARY attribute and isn't inherently
NUL-terminated, passing it directly to smk_find_entry() will trigger an
out-of-bounds read, because smk_find_entry() in security/smack/smack_access.c
unconditionally calls strlen() on the string. This seems to duplicate a
pre-existing flaw from smack_secctx_to_secid, but re-establishes it in this
new API contract.

> +
> +	return 0;

[Severity: High]
Can smk_find_entry() return NULL for an unknown context, and if so, is it
safe to return 0 (success) here?

If an unknown context is passed in, prop->smack.skp becomes NULL. Because
this returns 0, the caller (such as SECMARK via iptables) might assume the
property is fully populated. Later, if the system tries to convert this
property back to a security context string via smack_lsmprop_to_secctx(), it
passes the NULL pointer to smack_to_secctx():

security/smack/smack_lsm.c:smack_lsmprop_to_secctx() {
    return smack_to_secctx(prop->smack.skp, cp);
}

security/smack/smack_lsm.c:smack_to_secctx() {
    int len = strlen(skp->smk_known);
    ...
}

Will this cause a NULL pointer dereference and kernel panic when skp is NULL?

> +}
[ ... ]

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

  reply	other threads:[~2026-08-31 23:01 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260831223748.4304-1-casey.ref@schaufler-ca.com>
2026-08-31 22:37 ` [PATCH 0/7] Change skb secmarks to x-array indexes Casey Schaufler
2026-08-31 22:37   ` [PATCH 1/7] net, smack: Create a function to set secmarks Casey Schaufler
2026-08-31 22:57     ` sashiko-bot
2026-08-31 22:37   ` [PATCH 2/7] LSM: Implement x array functions for secmarks Casey Schaufler
2026-08-31 22:59     ` sashiko-bot
2026-08-31 22:37   ` [PATCH 3/7] LSM: Two hooks for manipulating struct lsm_prop Casey Schaufler
2026-08-31 23:03     ` sashiko-bot
2026-08-31 22:37   ` [PATCH 4/7] SELinux: hooks for secctx_to_lsmprop and update_lsmprop Casey Schaufler
2026-08-31 22:55     ` sashiko-bot
2026-08-31 22:37   ` [PATCH 5/7] Smack: " Casey Schaufler
2026-08-31 23:01     ` sashiko-bot [this message]
2026-08-31 22:37   ` [PATCH 6/7] Apparmor: " Casey Schaufler
2026-08-31 23:00     ` sashiko-bot
2026-08-31 22:37   ` [PATCH 7/7] net, lsm: Change skb secmarks to x-array indexes Casey Schaufler
2026-08-31 23:07     ` sashiko-bot
2026-08-13 20:48 [PATCH 0/7] " Casey Schaufler
2026-08-13 20:48 ` [PATCH 5/7] Smack: hooks for secctx_to_lsmprop and update_lsmprop Casey Schaufler
2026-08-14  2:08   ` 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=20260831230137.A62AF1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox