From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: John Johansen <john.johansen@canonical.com>,
Georgia Garcia <georgia.garcia@canonical.com>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10.y] apparmor: fix refcount leak in aa_get_newest_profile()
Date: Tue, 10 Nov 2026 21:11:52 -0500 [thread overview]
Message-ID: <20261111021132.584038-1-sashal@kernel.org> (raw)
In-Reply-To: <20261107063050-failed-5.10-33ed50716251@kernel.org>
From: John Johansen <john.johansen@canonical.com>
[ Upstream commit 33ed50716251d5b2875706c40d0c8082d46be0b1 ]
The labels_profile() macro is evaluating its argument twice
#define labels_profile(X) ((X)->vec[(X)->size - 1])
unfortunately aa_get_newest_profile() passes
aa_get_newest_label(&p->label)
so every call to aa_get_newest_profile results in 2 refcounts
being taken with one being leaked.
There is no need for labels_profile() to be a macro. Convert it to
an inline fn, which ensures all uses are passing the correct struct
and removes the double evaluation.
Fixes: 637f688dc3dc ("apparmor: switch from profiles to using labels on contexts")
Cc: stable@vger.kernel.org
Reported-by: Georgia Garcia <georgia.garcia@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
[ sashal: adjusted context around labels_profile() for differences in surrounding macros and declarations ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
security/apparmor/include/label.h | 6 +++++-
security/apparmor/label.c | 1 -
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/security/apparmor/include/label.h b/security/apparmor/include/label.h
index a987bd117d88d..e7e0f3e0435fc 100644
--- a/security/apparmor/include/label.h
+++ b/security/apparmor/include/label.h
@@ -148,7 +148,11 @@ do { \
#define __label_make_stale(X) ((X)->flags |= FLAG_STALE)
#define labels_ns(X) (vec_ns(&((X)->vec[0]), (X)->size))
#define labels_set(X) (&labels_ns(X)->labels)
-#define labels_profile(X) ((X)->vec[(X)->size - 1])
+
+static inline struct aa_profile *labels_profile(const struct aa_label *label)
+{
+ return label->vec[label->size - 1];
+}
int aa_label_next_confined(struct aa_label *l, int i);
diff --git a/security/apparmor/label.c b/security/apparmor/label.c
index c675a11d8a551..f14802e2c2264 100644
--- a/security/apparmor/label.c
+++ b/security/apparmor/label.c
@@ -377,7 +377,6 @@ void aa_label_kref(struct kref *kref)
label_free_switch(label);
return;
}
- /* TODO: update labels_profile macro so it works here */
AA_BUG(label_isprofile(label) &&
on_list_rcu(&label->vec[0]->base.profiles));
AA_BUG(label_isprofile(label) &&
--
2.53.0
prev parent reply other threads:[~2026-11-11 2:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 11:30 FAILED: patch "[PATCH] apparmor: fix refcount leak in aa_get_newest_profile()" failed to apply to 5.10-stable tree Sasha Levin
2026-11-11 2:11 ` Sasha Levin [this message]
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=20261111021132.584038-1-sashal@kernel.org \
--to=sashal@kernel.org \
--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