[PATCH,net-next,v2] af_unix: Fix wrong socket tested in the symmetric half of unix_state_lock_cmp_fn().
From: lirongqing
Date: Mon Nov 09 2026 - 04:27:17 EST
From: Li RongQing <lirongqing@xxxxxxxxx>
The second half of unix_state_lock_cmp_fn() mirrors the first with a and b
swapped, but it tests b->sk.sk_state again. Since b is already known to be
TCP_LISTEN, the switch only hits default and always returns 0 ("no order
known") instead of 1. Test a's state instead, as the first half does.
This code is only built with CONFIG_PROVE_LOCKING, so the impact is limited
to lockdep failing to validate this unix_state_lock() nesting order.
Found by AI.
Signed-off-by: Li RongQing <lirongqing@xxxxxxxxx>
---
Diff with v1: target to net-next, and drop fix tag
net/unix/af_unix.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index e7a0582..501e693 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -163,7 +163,7 @@ static int unix_state_lock_cmp_fn(const struct lockdep_map *_a,
/* Should never happen. Just to be symmetric. */
if (b->sk.sk_state == TCP_LISTEN) {
- switch (b->sk.sk_state) {
+ switch (a->sk.sk_state) {
case TCP_CLOSE:
case TCP_ESTABLISHED:
return 1;
--
2.9.4