syzbot


possible deadlock in sk_common_release

Status: fixed on 2023/02/24 13:50
Subsystems: net
[Documentation on labels]
Fix commit: af295e854a4e l2tp: Don't sleep and disable BH under writer-side sk_callback_lock
First crash: 746d, last: 735d

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
6.1.0-rc5-syzkaller-00320-gb6e7fdfd6f6a #0 Not tainted
------------------------------------------------------
syz-executor.3/18964 is trying to acquire lock:
ffff88802839c9b0 (k-sk_lock-AF_INET){+.+.}-{0:0}, at: sk_common_release+0x68/0x390 net/core/sock.c:3648

but task is already holding lock:
ffff88802839cc38 (k-clock-AF_INET){+++.}-{2:2}, at: l2tp_tunnel_register+0x126/0x1210 net/l2tp/l2tp_core.c:1477

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #1 (k-clock-AF_INET){+++.}-{2:2}:
       __raw_write_lock_bh include/linux/rwlock_api_smp.h:202 [inline]
       _raw_write_lock_bh+0x33/0x40 kernel/locking/spinlock.c:334
       sock_orphan include/net/sock.h:2090 [inline]
       dccp_close+0x4c8/0xd60 net/dccp/proto.c:1039
       inet_release+0x132/0x270 net/ipv4/af_inet.c:428
       __sock_release net/socket.c:650 [inline]
       sock_release+0x8b/0x1b0 net/socket.c:678
       inet_ctl_sock_destroy include/net/inet_common.h:71 [inline]
       dccp_v4_exit_net+0x15a/0x2c0 net/dccp/ipv4.c:1050
       ops_exit_list+0xb0/0x170 net/core/net_namespace.c:169
       cleanup_net+0x4ee/0xb00 net/core/net_namespace.c:601
       process_one_work+0x9bf/0x1710 kernel/workqueue.c:2289
       worker_thread+0x669/0x1090 kernel/workqueue.c:2436
       kthread+0x2e8/0x3a0 kernel/kthread.c:376
       ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

-> #0 (k-sk_lock-AF_INET){+.+.}-{0:0}:
       check_prev_add kernel/locking/lockdep.c:3097 [inline]
       check_prevs_add kernel/locking/lockdep.c:3216 [inline]
       validate_chain kernel/locking/lockdep.c:3831 [inline]
       __lock_acquire+0x2a43/0x56d0 kernel/locking/lockdep.c:5055
       lock_acquire kernel/locking/lockdep.c:5668 [inline]
       lock_acquire+0x1e3/0x630 kernel/locking/lockdep.c:5633
       lock_sock_fast include/net/sock.h:1753 [inline]
       udp_destroy_sock+0x34/0x250 net/ipv4/udp.c:2645
       sk_common_release+0x68/0x390 net/core/sock.c:3648
       inet_release+0x132/0x270 net/ipv4/af_inet.c:428
       __sock_release net/socket.c:650 [inline]
       sock_release+0x8b/0x1b0 net/socket.c:678
       l2tp_tunnel_register+0xc75/0x1210 net/l2tp/l2tp_core.c:1530
       l2tp_nl_cmd_tunnel_create+0x3d6/0x8b0 net/l2tp/l2tp_netlink.c:245
       genl_family_rcv_msg_doit+0x228/0x320 net/netlink/genetlink.c:756
       genl_family_rcv_msg net/netlink/genetlink.c:833 [inline]
       genl_rcv_msg+0x445/0x780 net/netlink/genetlink.c:850
       netlink_rcv_skb+0x157/0x430 net/netlink/af_netlink.c:2540
       genl_rcv+0x28/0x40 net/netlink/genetlink.c:861
       netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
       netlink_unicast+0x547/0x7f0 net/netlink/af_netlink.c:1345
       netlink_sendmsg+0x91b/0xe10 net/netlink/af_netlink.c:1921
       sock_sendmsg_nosec net/socket.c:714 [inline]
       sock_sendmsg+0xd3/0x120 net/socket.c:734
       ____sys_sendmsg+0x712/0x8c0 net/socket.c:2482
       ___sys_sendmsg+0x110/0x1b0 net/socket.c:2536
       __sys_sendmsg+0xf7/0x1c0 net/socket.c:2565
       do_syscall_x64 arch/x86/entry/common.c:50 [inline]
       do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
       entry_SYSCALL_64_after_hwframe+0x63/0xcd

other info that might help us debug this:

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(k-clock-AF_INET);
                               lock(k-sk_lock-AF_INET);
                               lock(k-clock-AF_INET);
  lock(k-sk_lock-AF_INET);

 *** DEADLOCK ***

3 locks held by syz-executor.3/18964:
 #0: ffffffff8df620f0 (cb_lock){++++}-{3:3}, at: genl_rcv+0x19/0x40 net/netlink/genetlink.c:860
 #1: ffffffff8df621a8 (genl_mutex){+.+.}-{3:3}, at: genl_lock net/netlink/genetlink.c:33 [inline]
 #1: ffffffff8df621a8 (genl_mutex){+.+.}-{3:3}, at: genl_rcv_msg+0x50d/0x780 net/netlink/genetlink.c:848
 #2: ffff88802839cc38 (k-clock-AF_INET){+++.}-{2:2}, at: l2tp_tunnel_register+0x126/0x1210 net/l2tp/l2tp_core.c:1477

stack backtrace:
CPU: 0 PID: 18964 Comm: syz-executor.3 Not tainted 6.1.0-rc5-syzkaller-00320-gb6e7fdfd6f6a #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd1/0x138 lib/dump_stack.c:106
 check_noncircular+0x25f/0x2e0 kernel/locking/lockdep.c:2177
 check_prev_add kernel/locking/lockdep.c:3097 [inline]
 check_prevs_add kernel/locking/lockdep.c:3216 [inline]
 validate_chain kernel/locking/lockdep.c:3831 [inline]
 __lock_acquire+0x2a43/0x56d0 kernel/locking/lockdep.c:5055
 lock_acquire kernel/locking/lockdep.c:5668 [inline]
 lock_acquire+0x1e3/0x630 kernel/locking/lockdep.c:5633
 lock_sock_fast include/net/sock.h:1753 [inline]
 udp_destroy_sock+0x34/0x250 net/ipv4/udp.c:2645
 sk_common_release+0x68/0x390 net/core/sock.c:3648
 inet_release+0x132/0x270 net/ipv4/af_inet.c:428
 __sock_release net/socket.c:650 [inline]
 sock_release+0x8b/0x1b0 net/socket.c:678
 l2tp_tunnel_register+0xc75/0x1210 net/l2tp/l2tp_core.c:1530
 l2tp_nl_cmd_tunnel_create+0x3d6/0x8b0 net/l2tp/l2tp_netlink.c:245
 genl_family_rcv_msg_doit+0x228/0x320 net/netlink/genetlink.c:756
 genl_family_rcv_msg net/netlink/genetlink.c:833 [inline]
 genl_rcv_msg+0x445/0x780 net/netlink/genetlink.c:850
 netlink_rcv_skb+0x157/0x430 net/netlink/af_netlink.c:2540
 genl_rcv+0x28/0x40 net/netlink/genetlink.c:861
 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
 netlink_unicast+0x547/0x7f0 net/netlink/af_netlink.c:1345
 netlink_sendmsg+0x91b/0xe10 net/netlink/af_netlink.c:1921
 sock_sendmsg_nosec net/socket.c:714 [inline]
 sock_sendmsg+0xd3/0x120 net/socket.c:734
 ____sys_sendmsg+0x712/0x8c0 net/socket.c:2482
 ___sys_sendmsg+0x110/0x1b0 net/socket.c:2536
 __sys_sendmsg+0xf7/0x1c0 net/socket.c:2565
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f2988c8b639
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f2989a4a168 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f2988dabf80 RCX: 00007f2988c8b639
RDX: 0000000000000000 RSI: 0000000020000240 RDI: 0000000000000003
RBP: 00007f2988ce6ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe260d6aff R14: 00007f2989a4a300 R15: 0000000000022000
 </TASK>
BUG: sleeping function called from invalid context at net/core/sock.c:3479
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 18964, name: syz-executor.3
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
INFO: lockdep is turned off.
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 0 PID: 18964 Comm: syz-executor.3 Not tainted 6.1.0-rc5-syzkaller-00320-gb6e7fdfd6f6a #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd1/0x138 lib/dump_stack.c:106
 __might_resched.cold+0x222/0x26b kernel/sched/core.c:9890
 __lock_sock_fast+0x25/0xe0 net/core/sock.c:3479
 lock_sock_fast include/net/sock.h:1755 [inline]
 udp_destroy_sock+0x3c/0x250 net/ipv4/udp.c:2645
 sk_common_release+0x68/0x390 net/core/sock.c:3648
 inet_release+0x132/0x270 net/ipv4/af_inet.c:428
 __sock_release net/socket.c:650 [inline]
 sock_release+0x8b/0x1b0 net/socket.c:678
 l2tp_tunnel_register+0xc75/0x1210 net/l2tp/l2tp_core.c:1530
 l2tp_nl_cmd_tunnel_create+0x3d6/0x8b0 net/l2tp/l2tp_netlink.c:245
 genl_family_rcv_msg_doit+0x228/0x320 net/netlink/genetlink.c:756
 genl_family_rcv_msg net/netlink/genetlink.c:833 [inline]
 genl_rcv_msg+0x445/0x780 net/netlink/genetlink.c:850
 netlink_rcv_skb+0x157/0x430 net/netlink/af_netlink.c:2540
 genl_rcv+0x28/0x40 net/netlink/genetlink.c:861
 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
 netlink_unicast+0x547/0x7f0 net/netlink/af_netlink.c:1345
 netlink_sendmsg+0x91b/0xe10 net/netlink/af_netlink.c:1921
 sock_sendmsg_nosec net/socket.c:714 [inline]
 sock_sendmsg+0xd3/0x120 net/socket.c:734
 ____sys_sendmsg+0x712/0x8c0 net/socket.c:2482
 ___sys_sendmsg+0x110/0x1b0 net/socket.c:2536
 __sys_sendmsg+0xf7/0x1c0 net/socket.c:2565
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f2988c8b639
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f2989a4a168 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007f2988dabf80 RCX: 00007f2988c8b639
RDX: 0000000000000000 RSI: 0000000020000240 RDI: 0000000000000003
RBP: 00007f2988ce6ae9 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe260d6aff R14: 00007f2989a4a300 R15: 0000000000022000
 </TASK>

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2022/11/20 11:24 upstream b6e7fdfd6f6a 5bb70014 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root possible deadlock in sk_common_release
2022/11/19 14:30 upstream fe24a97cf254 5bb70014 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in sk_common_release
2022/11/18 02:20 upstream 81ac25651a62 4ba8ab94 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-root possible deadlock in sk_common_release
2022/11/24 19:26 net-next-old 170d97739de4 62e26685 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-net-kasan-gce possible deadlock in sk_common_release
2022/11/29 03:41 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 6d464646530f ca9683b8 .config console log report info ci-upstream-gce-arm64 possible deadlock in sk_common_release
* Struck through repros no longer work on HEAD.