Linux Security Modules development
 help / color / mirror / Atom feed
* [PATCH] apparmor: fix race on NULL ctx->peer in update_sk_ctx()
@ 2026-10-29 14:06 Emanuele Rocca
  2026-10-29 14:26 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Emanuele Rocca @ 2026-10-29 14:06 UTC (permalink / raw)
  To: John Johansen, Georgia Garcia
  Cc: apparmor, linux-security-module, Maxime Bélair,
	Aurelien Jarno, stable

The unlocked check in update_sk_ctx() can see peer_lastupdate set before
peer is initialized, passing NULL to aa_label_is_subset().

The earlier NULL checks only cover accesses under the socket lock.
Check for NULL and refresh the cache instead.

Fixes: 88fec3526e84 ("apparmor: make sure unix socket labeling is correctly updated.")
Link: https://lore.kernel.org/all/20260824155822.9214-1-maxime.belair@canonical.com/
Cc: stable@vger.kernel.org
Signed-off-by: Emanuele Rocca <emanuele.rocca@arm.com>
---
 security/apparmor/af_unix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/security/apparmor/af_unix.c b/security/apparmor/af_unix.c
index d04d9cd268aa..b95959806303 100644
--- a/security/apparmor/af_unix.c
+++ b/security/apparmor/af_unix.c
@@ -657,9 +657,10 @@ static void update_sk_ctx(struct sock *sk, struct aa_label *label,
 	bool update_sk;
 
 	rcu_read_lock();
+	old = rcu_dereference(ctx->peer);
 	update_sk = (plabel &&
 		     (plabel != rcu_access_pointer(ctx->peer_lastupdate) ||
-		      !aa_label_is_subset(plabel, rcu_dereference(ctx->peer)))) ||
+		      !old || !aa_label_is_subset(plabel, old))) ||
 	  !__aa_subj_label_is_cached(label, rcu_dereference(ctx->label));
 	rcu_read_unlock();
 	if (!update_sk)
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-29 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29 14:06 [PATCH] apparmor: fix race on NULL ctx->peer in update_sk_ctx() Emanuele Rocca
2026-10-29 14:26 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox