All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: selinux@vger.kernel.org
Subject: Re: [PATCH v2 6/7] Apparmor: hooks for secctx_to_lsmprop and update_lsmprop
Date: Wed, 02 Sep 2026 22:16:51 +0000	[thread overview]
Message-ID: <20260902221651.73BFC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260902220150.18586-7-casey@schaufler-ca.com>

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

New issues:
- [High] Memory leak of `aa_label` reference in `apparmor_secctx_to_lsmprop()`.

Pre-existing issues:
- [High] Memory leak of `aa_label` reference in `apparmor_secctx_to_secid()`.
--

commit 1e8503b950ea8fae325db00bc26a72d7c257c11e
Author: Casey Schaufler <casey@schaufler-ca.com>

Apparmor: hooks for secctx_to_lsmprop and update_lsmprop

Implement these hooks.

> diff --git a/security/apparmor/secid.c b/security/apparmor/secid.c
> index 28caf66b90335..d35fdbf074e05 100644
> --- a/security/apparmor/secid.c
> +++ b/security/apparmor/secid.c
> @@ -106,6 +106,27 @@ int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
>  	return 0;
>  }

[Severity: High]
This is a pre-existing issue, but does this function leak the reference
to the aa_label?

Looking at the body of the function:

int apparmor_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
{
	struct aa_label *label;

	label = aa_label_strn_parse(&root_ns->unconfined->label, secdata,
				    seclen, GFP_KERNEL, false, false);
	if (IS_ERR(label))
		return PTR_ERR(label);
	*secid = label->secid;

	return 0;
}

It looks like aa_label_strn_parse() returns an aa_label with an
incremented reference count, and apparmor_secctx_to_secid() extracts
label->secid and returns without dropping the reference.

This can be triggered by unprivileged users in a user and network namespace
by repeatedly adding secmark rules (via xt_SECMARK) with an existing
profile name. This allows an unprivileged user to leak references until
refcount_t saturation, triggering kernel warnings and potential crashes
under panic_on_warn.

>  
> +int apparmor_secctx_to_lsmprop(const char *secdata, u32 seclen,
> +			       struct lsm_prop *prop)
> +{
> +	struct aa_label *label;
> +
> +	label = aa_label_strn_parse(&root_ns->unconfined->label, secdata,
> +				    seclen, GFP_KERNEL, false, false);
> +	if (IS_ERR(label))
> +		return PTR_ERR(label);
> +	prop->apparmor.label = label;
> +
> +	return 0;
> +}

[Severity: High]
Does this code leak the aa_label reference?

Similar to apparmor_secctx_to_secid(), aa_label_strn_parse() returns an
aa_label with an incremented reference count. The label pointer is assigned
to prop->apparmor.label but returns without dropping the reference. Because
the lsm_prop struct acts as a simple value container and lacks any release
lifecycle hook across the LSM framework, this reference is permanently leaked.

An unprivileged user can trigger this whenever security_secctx_to_lsmprop()
is called, such as by nft_secmark_compute_secid() when adding a netfilter
secmark rule. By gaining CAP_NET_ADMIN in a user and network namespace, they
can repeatedly add netfilter rules and leak references to an existing AppArmor
profile until the refcount_t saturates.

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

  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
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 [this message]
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=20260902221651.73BFC1F000E9@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.