]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
apparmor: fix refcount leak when updating the sk_ctx
authorJohn Johansen <john.johansen@canonical.com>
Fri, 24 Oct 2025 19:59:51 +0000 (12:59 -0700)
committerJohn Johansen <john.johansen@canonical.com>
Sun, 14 Jun 2026 03:14:06 +0000 (20:14 -0700)
Currently update_sk_ctx() transfers the plabel reference, unfortunately
it is also unconditionally put in the caller. Ideally we would make
the caller conditionally put the reference based on whether it was
transferred but for now just fix the bug by getting a reference.

Fixes: 88fec3526e841 ("apparmor: make sure unix socket labeling is correctly updated.")
Signed-off-by: John Johansen <john.johansen@canonical.com>
security/apparmor/af_unix.c

index 23753cb2096e53e2ea07f18578f32da2ac3edf8d..834a3b1c2f0af49484fa5c6d864faa08548e2d48 100644 (file)
@@ -674,9 +674,11 @@ static void update_sk_ctx(struct sock *sk, struct aa_label *label,
                old = rcu_dereference_protected(ctx->peer, lockdep_is_held(&unix_sk(sk)->lock));
 
                if (old == plabel) {
-                       rcu_assign_pointer(ctx->peer_lastupdate, plabel);
+                       rcu_assign_pointer(ctx->peer_lastupdate,
+                                          aa_get_label(plabel));
                } else if (aa_label_is_subset(plabel, old)) {
-                       rcu_assign_pointer(ctx->peer_lastupdate, plabel);
+                       rcu_assign_pointer(ctx->peer_lastupdate,
+                                          aa_get_label(plabel));
                        rcu_assign_pointer(ctx->peer, aa_get_label(plabel));
                        aa_put_label(old);
                } /* else race or a subset - don't update */