FAILED: patch "[PATCH] apparmor: fix refcount leak in aa_get_newest_profile()" failed to apply to 5.15-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 33ed50716251d5b2875706c40d0c8082d46be0b1
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 33ed50716251d5b2875706c40d0c8082d46be0b1 Mon Sep 17 00:00:00 2001
From: John Johansen <[email protected]>
Date: Tue, 20 Oct 2026 16:00:30 -0700
Subject: [PATCH] apparmor: fix refcount leak in aa_get_newest_profile()
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.
--- security/apparmor/include/label.h | 6 +++++- security/apparmor/label.c | 1 - 2 files changed, 5 insertions(+), 2 deletions(-)
security/apparmor/include/label.h +5 -1
@@ -162,7 +162,11 @@ do { \#define labels_ns (X ) (vec_ns(&((X)->vec[0]), (X)->size))#define labels_set (X ) (&labels_ns(X)->labels)#define labels_view (X ) labels_ns(X) -#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 (const struct aa_label *l,int i);
security/apparmor/label.c +0 -1
@@ -387,7 +387,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) &&
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 apparmor: fix refcount leak in aa_get_newest_profile()
From: John Johansen <[email protected]>
[ 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.
--- security/apparmor/include/label.h | 6 +++++- security/apparmor/label.c | 1 - 2 files changed, 5 insertions(+), 2 deletions(-)
security/apparmor/include/label.h +5 -1
@@ -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);
security/apparmor/label.c +0 -1
@@ -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) &&
Signature · 1 line
2.53.0