Skip to content

Commit da3496e

Browse files
committed
af_unix: Suppress false-positive lockdep splat for spin_lock() in __unix_gc().
jira LE-2015 Rebuild_History Non-Buildable kernel-5.14.0-427.42.1.el9_4 commit-author Kuniyuki Iwashima <[email protected]> commit 1971d13 Empty-Commit: Cherry-Pick Conflicts during history rebuild. Will be included in final tarball splat. Ref for failed cherry-pick at: ciq/ciq_backports/kernel-5.14.0-427.42.1.el9_4/1971d13f.failed syzbot reported a lockdep splat regarding unix_gc_lock and unix_state_lock(). One is called from recvmsg() for a connected socket, and another is called from GC for TCP_LISTEN socket. So, the splat is false-positive. Let's add a dedicated lock class for the latter to suppress the splat. Note that this change is not necessary for net-next.git as the issue is only applied to the old GC impl. [0]: WARNING: possible circular locking dependency detected 6.9.0-rc5-syzkaller-00007-g4d2008430ce8 #0 Not tainted ----------------------------------------------------- kworker/u8:1/11 is trying to acquire lock: ffff88807cea4e70 (&u->lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline] ffff88807cea4e70 (&u->lock){+.+.}-{2:2}, at: __unix_gc+0x40e/0xf70 net/unix/garbage.c:302 but task is already holding lock: ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline] ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: __unix_gc+0x117/0xf70 net/unix/garbage.c:261 which lock already depends on the new lock. the existing dependency chain (in reverse order) is: -> #1 (unix_gc_lock){+.+.}-{2:2}: lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754 __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline] _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154 spin_lock include/linux/spinlock.h:351 [inline] unix_notinflight+0x13d/0x390 net/unix/garbage.c:140 unix_detach_fds net/unix/af_unix.c:1819 [inline] unix_destruct_scm+0x221/0x350 net/unix/af_unix.c:1876 skb_release_head_state+0x100/0x250 net/core/skbuff.c:1188 skb_release_all net/core/skbuff.c:1200 [inline] __kfree_skb net/core/skbuff.c:1216 [inline] kfree_skb_reason+0x16d/0x3b0 net/core/skbuff.c:1252 kfree_skb include/linux/skbuff.h:1262 [inline] manage_oob net/unix/af_unix.c:2672 [inline] unix_stream_read_generic+0x1125/0x2700 net/unix/af_unix.c:2749 unix_stream_splice_read+0x239/0x320 net/unix/af_unix.c:2981 do_splice_read fs/splice.c:985 [inline] splice_file_to_pipe+0x299/0x500 fs/splice.c:1295 do_splice+0xf2d/0x1880 fs/splice.c:1379 __do_splice fs/splice.c:1436 [inline] __do_sys_splice fs/splice.c:1652 [inline] __se_sys_splice+0x331/0x4a0 fs/splice.c:1634 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f -> #0 (&u->lock){+.+.}-{2:2}: check_prev_add kernel/locking/lockdep.c:3134 [inline] check_prevs_add kernel/locking/lockdep.c:3253 [inline] validate_chain+0x18cb/0x58e0 kernel/locking/lockdep.c:3869 __lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137 lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754 __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline] _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154 spin_lock include/linux/spinlock.h:351 [inline] __unix_gc+0x40e/0xf70 net/unix/garbage.c:302 process_one_work kernel/workqueue.c:3254 [inline] process_scheduled_works+0xa10/0x17c0 kernel/workqueue.c:3335 worker_thread+0x86d/0xd70 kernel/workqueue.c:3416 kthread+0x2f0/0x390 kernel/kthread.c:388 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 other info that might help us debug this: Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(unix_gc_lock); lock(&u->lock); lock(unix_gc_lock); lock(&u->lock); *** DEADLOCK *** 3 locks held by kworker/u8:1/11: #0: ffff888015089148 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3229 [inline] #0: ffff888015089148 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_scheduled_works+0x8e0/0x17c0 kernel/workqueue.c:3335 #1: ffffc90000107d00 (unix_gc_work){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3230 [inline] #1: ffffc90000107d00 (unix_gc_work){+.+.}-{0:0}, at: process_scheduled_works+0x91b/0x17c0 kernel/workqueue.c:3335 #2: ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline] #2: ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: __unix_gc+0x117/0xf70 net/unix/garbage.c:261 stack backtrace: CPU: 0 PID: 11 Comm: kworker/u8:1 Not tainted 6.9.0-rc5-syzkaller-00007-g4d2008430ce8 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 Workqueue: events_unbound __unix_gc Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114 check_noncircular+0x36a/0x4a0 kernel/locking/lockdep.c:2187 check_prev_add kernel/locking/lockdep.c:3134 [inline] check_prevs_add kernel/locking/lockdep.c:3253 [inline] validate_chain+0x18cb/0x58e0 kernel/locking/lockdep.c:3869 __lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137 lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754 __raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline] _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154 spin_lock include/linux/spinlock.h:351 [inline] __unix_gc+0x40e/0xf70 net/unix/garbage.c:302 process_one_work kernel/workqueue.c:3254 [inline] process_scheduled_works+0xa10/0x17c0 kernel/workqueue.c:3335 worker_thread+0x86d/0xd70 kernel/workqueue.c:3416 kthread+0x2f0/0x390 kernel/kthread.c:388 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 </TASK> Fixes: 47d8ac0 ("af_unix: Fix garbage collector racing against connect()") Reported-and-tested-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=fa379358c28cc87cc307 Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit 1971d13) Signed-off-by: Jonathan Maple <[email protected]> # Conflicts: # net/unix/garbage.c
1 parent d61ce93 commit da3496e

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
af_unix: Suppress false-positive lockdep splat for spin_lock() in __unix_gc().
2+
3+
jira LE-2015
4+
Rebuild_History Non-Buildable kernel-5.14.0-427.42.1.el9_4
5+
commit-author Kuniyuki Iwashima <[email protected]>
6+
commit 1971d13ffa84a551d29a81fdf5b5ec5be166ac83
7+
Empty-Commit: Cherry-Pick Conflicts during history rebuild.
8+
Will be included in final tarball splat. Ref for failed cherry-pick at:
9+
ciq/ciq_backports/kernel-5.14.0-427.42.1.el9_4/1971d13f.failed
10+
11+
syzbot reported a lockdep splat regarding unix_gc_lock and
12+
unix_state_lock().
13+
14+
One is called from recvmsg() for a connected socket, and another
15+
is called from GC for TCP_LISTEN socket.
16+
17+
So, the splat is false-positive.
18+
19+
Let's add a dedicated lock class for the latter to suppress the splat.
20+
21+
Note that this change is not necessary for net-next.git as the issue
22+
is only applied to the old GC impl.
23+
24+
[0]:
25+
WARNING: possible circular locking dependency detected
26+
6.9.0-rc5-syzkaller-00007-g4d2008430ce8 #0 Not tainted
27+
-----------------------------------------------------
28+
kworker/u8:1/11 is trying to acquire lock:
29+
ffff88807cea4e70 (&u->lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
30+
ffff88807cea4e70 (&u->lock){+.+.}-{2:2}, at: __unix_gc+0x40e/0xf70 net/unix/garbage.c:302
31+
32+
but task is already holding lock:
33+
ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
34+
ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: __unix_gc+0x117/0xf70 net/unix/garbage.c:261
35+
36+
which lock already depends on the new lock.
37+
38+
the existing dependency chain (in reverse order) is:
39+
40+
-> #1 (unix_gc_lock){+.+.}-{2:2}:
41+
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754
42+
__raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
43+
_raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154
44+
spin_lock include/linux/spinlock.h:351 [inline]
45+
unix_notinflight+0x13d/0x390 net/unix/garbage.c:140
46+
unix_detach_fds net/unix/af_unix.c:1819 [inline]
47+
unix_destruct_scm+0x221/0x350 net/unix/af_unix.c:1876
48+
skb_release_head_state+0x100/0x250 net/core/skbuff.c:1188
49+
skb_release_all net/core/skbuff.c:1200 [inline]
50+
__kfree_skb net/core/skbuff.c:1216 [inline]
51+
kfree_skb_reason+0x16d/0x3b0 net/core/skbuff.c:1252
52+
kfree_skb include/linux/skbuff.h:1262 [inline]
53+
manage_oob net/unix/af_unix.c:2672 [inline]
54+
unix_stream_read_generic+0x1125/0x2700 net/unix/af_unix.c:2749
55+
unix_stream_splice_read+0x239/0x320 net/unix/af_unix.c:2981
56+
do_splice_read fs/splice.c:985 [inline]
57+
splice_file_to_pipe+0x299/0x500 fs/splice.c:1295
58+
do_splice+0xf2d/0x1880 fs/splice.c:1379
59+
__do_splice fs/splice.c:1436 [inline]
60+
__do_sys_splice fs/splice.c:1652 [inline]
61+
__se_sys_splice+0x331/0x4a0 fs/splice.c:1634
62+
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
63+
do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83
64+
entry_SYSCALL_64_after_hwframe+0x77/0x7f
65+
66+
-> #0 (&u->lock){+.+.}-{2:2}:
67+
check_prev_add kernel/locking/lockdep.c:3134 [inline]
68+
check_prevs_add kernel/locking/lockdep.c:3253 [inline]
69+
validate_chain+0x18cb/0x58e0 kernel/locking/lockdep.c:3869
70+
__lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137
71+
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754
72+
__raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
73+
_raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154
74+
spin_lock include/linux/spinlock.h:351 [inline]
75+
__unix_gc+0x40e/0xf70 net/unix/garbage.c:302
76+
process_one_work kernel/workqueue.c:3254 [inline]
77+
process_scheduled_works+0xa10/0x17c0 kernel/workqueue.c:3335
78+
worker_thread+0x86d/0xd70 kernel/workqueue.c:3416
79+
kthread+0x2f0/0x390 kernel/kthread.c:388
80+
ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
81+
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
82+
83+
other info that might help us debug this:
84+
85+
Possible unsafe locking scenario:
86+
87+
CPU0 CPU1
88+
---- ----
89+
lock(unix_gc_lock);
90+
lock(&u->lock);
91+
lock(unix_gc_lock);
92+
lock(&u->lock);
93+
94+
*** DEADLOCK ***
95+
96+
3 locks held by kworker/u8:1/11:
97+
#0: ffff888015089148 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3229 [inline]
98+
#0: ffff888015089148 ((wq_completion)events_unbound){+.+.}-{0:0}, at: process_scheduled_works+0x8e0/0x17c0 kernel/workqueue.c:3335
99+
#1: ffffc90000107d00 (unix_gc_work){+.+.}-{0:0}, at: process_one_work kernel/workqueue.c:3230 [inline]
100+
#1: ffffc90000107d00 (unix_gc_work){+.+.}-{0:0}, at: process_scheduled_works+0x91b/0x17c0 kernel/workqueue.c:3335
101+
#2: ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
102+
#2: ffffffff8f6ab638 (unix_gc_lock){+.+.}-{2:2}, at: __unix_gc+0x117/0xf70 net/unix/garbage.c:261
103+
104+
stack backtrace:
105+
CPU: 0 PID: 11 Comm: kworker/u8:1 Not tainted 6.9.0-rc5-syzkaller-00007-g4d2008430ce8 #0
106+
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024
107+
Workqueue: events_unbound __unix_gc
108+
Call Trace:
109+
<TASK>
110+
__dump_stack lib/dump_stack.c:88 [inline]
111+
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114
112+
check_noncircular+0x36a/0x4a0 kernel/locking/lockdep.c:2187
113+
check_prev_add kernel/locking/lockdep.c:3134 [inline]
114+
check_prevs_add kernel/locking/lockdep.c:3253 [inline]
115+
validate_chain+0x18cb/0x58e0 kernel/locking/lockdep.c:3869
116+
__lock_acquire+0x1346/0x1fd0 kernel/locking/lockdep.c:5137
117+
lock_acquire+0x1ed/0x550 kernel/locking/lockdep.c:5754
118+
__raw_spin_lock include/linux/spinlock_api_smp.h:133 [inline]
119+
_raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:154
120+
spin_lock include/linux/spinlock.h:351 [inline]
121+
__unix_gc+0x40e/0xf70 net/unix/garbage.c:302
122+
process_one_work kernel/workqueue.c:3254 [inline]
123+
process_scheduled_works+0xa10/0x17c0 kernel/workqueue.c:3335
124+
worker_thread+0x86d/0xd70 kernel/workqueue.c:3416
125+
kthread+0x2f0/0x390 kernel/kthread.c:388
126+
ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
127+
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
128+
</TASK>
129+
130+
Fixes: 47d8ac011fe1 ("af_unix: Fix garbage collector racing against connect()")
131+
Reported-and-tested-by: [email protected]
132+
Closes: https://syzkaller.appspot.com/bug?extid=fa379358c28cc87cc307
133+
Signed-off-by: Kuniyuki Iwashima <[email protected]>
134+
Link: https://lore.kernel.org/r/[email protected]
135+
Signed-off-by: Jakub Kicinski <[email protected]>
136+
(cherry picked from commit 1971d13ffa84a551d29a81fdf5b5ec5be166ac83)
137+
Signed-off-by: Jonathan Maple <[email protected]>
138+
139+
# Conflicts:
140+
# net/unix/garbage.c
141+
diff --cc net/unix/garbage.c
142+
index 2405f0f9af31,0104be9d4704..000000000000
143+
--- a/net/unix/garbage.c
144+
+++ b/net/unix/garbage.c
145+
@@@ -248,6 -297,11 +248,14 @@@ void unix_gc(void
146+
list_move_tail(&u->link, &gc_candidates);
147+
__set_bit(UNIX_GC_CANDIDATE, &u->gc_flags);
148+
__set_bit(UNIX_GC_MAYBE_CYCLE, &u->gc_flags);
149+
++<<<<<<< HEAD
150+
++=======
151+
+
152+
+ if (sk->sk_state == TCP_LISTEN) {
153+
+ unix_state_lock_nested(sk, U_LOCK_GC_LISTENER);
154+
+ unix_state_unlock(sk);
155+
+ }
156+
++>>>>>>> 1971d13ffa84 (af_unix: Suppress false-positive lockdep splat for spin_lock() in __unix_gc().)
157+
}
158+
}
159+
160+
diff --git a/include/net/af_unix.h b/include/net/af_unix.h
161+
index 8b0dd4b52c1b..3697799f3b0c 100644
162+
--- a/include/net/af_unix.h
163+
+++ b/include/net/af_unix.h
164+
@@ -77,6 +77,9 @@ enum unix_socket_lock_class {
165+
U_LOCK_NORMAL,
166+
U_LOCK_SECOND, /* for double locking, see unix_state_double_lock(). */
167+
U_LOCK_DIAG, /* used while dumping icons, see sk_diag_dump_icons(). */
168+
+ U_LOCK_GC_LISTENER, /* used for listening socket while determining gc
169+
+ * candidates to close a small race window.
170+
+ */
171+
};
172+
173+
static inline void unix_state_lock_nested(struct sock *sk,
174+
* Unmerged path net/unix/garbage.c

0 commit comments

Comments
 (0)