Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Qihang <q.h.hack.winter@gmail.com>
To: john.johansen@canonical.com, georgia.garcia@canonical.com
Cc: apparmor@lists.ubuntu.com, stable@vger.kernel.org,
	Qihang <q.h.hack.winter@gmail.com>
Subject: [PATCH v2] apparmor: make unpacked rename and attach strings owned copies
Date: Thu,  5 Nov 2026 15:41:09 +0800	[thread overview]
Message-ID: <20261105074109.95617-1-q.h.hack.winter@gmail.com> (raw)

unpack_profile() stores the optional rename and attach strings using
aa_unpack_str(), which returns pointers into the policy blob.
profile->rename is later freed with kfree_sensitive(), causing an
invalid free of an interior pointer on the failed-unpack path.
profile->attach.xmatch_str can instead become a dangling pointer when
the original policy blob is freed after compressed binary policy export.

The dangling xmatch_str is read by seq_profile_attach_show() through
the world-readable per-profile "attach" file, giving an unprivileged
slab-use-after-free read. ent->new->rename is also passed to
__lookup_replace() in the same load syscall, and the rawdata dedup skip
path frees the profile again, double freeing the interior rename
pointer.

Use aa_unpack_strdup() for both strings and free xmatch_str with the
attachment.

Fixes: 736ec752d95e9 ("AppArmor: policy routines for loading and unpacking policy")
Fixes: 63c16c3a76085 ("apparmor: Initial implementation of raw policy blob compression")
Cc: stable@vger.kernel.org
Signed-off-by: Qihang <q.h.hack.winter@gmail.com>
---
 security/apparmor/policy.c        | 1 +
 security/apparmor/policy_unpack.c | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
index 397f9ff78aeb1..695bea2a70820 100644
--- a/security/apparmor/policy.c
+++ b/security/apparmor/policy.c
@@ -282,6 +282,7 @@ static void free_attachment(struct aa_attachment *attach)
 	for (i = 0; i < attach->xattr_count; i++)
 		kfree_sensitive(attach->xattrs[i]);
 	kfree_sensitive(attach->xattrs);
+	kfree_sensitive(attach->xmatch_str);
 	aa_put_pdb(attach->xmatch);
 }
 
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
index f1fc48e72d0e1..6da4579bbd8ed 100644
--- a/security/apparmor/policy_unpack.c
+++ b/security/apparmor/policy_unpack.c
@@ -1121,6 +1121,7 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
 	size_t ns_len;
 	struct rhashtable_params params = { 0 };
 	char *key = NULL, *disconnected = NULL;
+	char *rename = NULL, *attach_str = NULL;
 	struct aa_data *data;
 	int error = -EPROTO;
 	kernel_cap_t tmpcap;
@@ -1160,10 +1161,12 @@ static struct aa_profile *unpack_profile(struct aa_ext *e, char **ns_name)
 	rules = profile->label.rules[0];
 
 	/* profile renaming is optional */
-	(void) aa_unpack_str(e, &profile->rename, "rename");
+	(void) aa_unpack_strdup(e, &rename, "rename");
+	profile->rename = rename;
 
 	/* attachment string is optional */
-	(void) aa_unpack_str(e, &profile->attach.xmatch_str, "attach");
+	(void) aa_unpack_strdup(e, &attach_str, "attach");
+	profile->attach.xmatch_str = attach_str;
 
 	/* xmatch is optional and may be NULL */
 	error = unpack_pdb(e, &profile->attach.xmatch, false, false, &info);
-- 
2.54.0 (Apple Git-157)


                 reply	other threads:[~2026-11-05  7:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261105074109.95617-1-q.h.hack.winter@gmail.com \
    --to=q.h.hack.winter@gmail.com \
    --cc=apparmor@lists.ubuntu.com \
    --cc=georgia.garcia@canonical.com \
    --cc=john.johansen@canonical.com \
    --cc=stable@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