syzbot


possible deadlock in wg_set_device

Status: fixed on 2020/03/11 20:34
Reported-by: syzbot+42d05aefd7fce69f968f@syzkaller.appspotmail.com
Fix commit: ec31c2676a10 wireguard: noise: reject peers with low order public keys
First crash: 1542d, last: 1534d
Cause bisection: introduced by (bisect log) :
commit e7096c131e5161fa3b8e52a650d7719d2857adfd
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date: Sun Dec 8 23:27:34 2019 +0000

  net: WireGuard secure network tunnel

Crash: possible deadlock in wg_set_device (log)
Repro: C syz .config
  
Discussions (1)
Title Replies (including bot) Last reply
possible deadlock in wg_set_device 1 (2) 2020/02/03 22:13

Sample crash report:
batman_adv: batadv0: Interface activated: batadv_slave_1
======================================================
WARNING: possible circular locking dependency detected
5.5.0-syzkaller #0 Not tainted
------------------------------------------------------
syz-executor103/9743 is trying to acquire lock:
ffff8880996c1128 ((wq_completion)wg-kex-wireguard0){+.+.}, at: flush_workqueue+0xf7/0x14c0 kernel/workqueue.c:2772

but task is already holding lock:
ffff88809ead8e80 (&wg->static_identity.lock){++++}, at: wg_set_device+0xe8b/0x1350 drivers/net/wireguard/netlink.c:567

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 (&wg->static_identity.lock){++++}:
       down_read+0x95/0x430 kernel/locking/rwsem.c:1495
       wg_noise_handshake_create_initiation+0xc0/0x670 drivers/net/wireguard/noise.c:499
       wg_packet_send_handshake_initiation+0x185/0x250 drivers/net/wireguard/send.c:34
       wg_packet_handshake_send_worker+0x1d/0x30 drivers/net/wireguard/send.c:51
       process_one_work+0xa05/0x17a0 kernel/workqueue.c:2264
       worker_thread+0x98/0xe40 kernel/workqueue.c:2410
       kthread+0x361/0x430 kernel/kthread.c:255
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

-> #1 ((work_completion)(&peer->transmit_handshake_work)){+.+.}:
       process_one_work+0x972/0x17a0 kernel/workqueue.c:2240
       worker_thread+0x98/0xe40 kernel/workqueue.c:2410
       kthread+0x361/0x430 kernel/kthread.c:255
       ret_from_fork+0x24/0x30 arch/x86/entry/entry_64.S:352

-> #0 ((wq_completion)wg-kex-wireguard0){+.+.}:
       check_prev_add kernel/locking/lockdep.c:2475 [inline]
       check_prevs_add kernel/locking/lockdep.c:2580 [inline]
       validate_chain kernel/locking/lockdep.c:2970 [inline]
       __lock_acquire+0x2596/0x4a00 kernel/locking/lockdep.c:3954
       lock_acquire+0x190/0x410 kernel/locking/lockdep.c:4484
       flush_workqueue+0x126/0x14c0 kernel/workqueue.c:2775
       peer_remove_after_dead+0x16b/0x230 drivers/net/wireguard/peer.c:141
       wg_peer_remove+0x244/0x340 drivers/net/wireguard/peer.c:176
       wg_set_device+0xf76/0x1350 drivers/net/wireguard/netlink.c:575
       genl_family_rcv_msg_doit net/netlink/genetlink.c:672 [inline]
       genl_family_rcv_msg net/netlink/genetlink.c:717 [inline]
       genl_rcv_msg+0x67d/0xea0 net/netlink/genetlink.c:734
       netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477
       genl_rcv+0x29/0x40 net/netlink/genetlink.c:745
       netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
       netlink_unicast+0x59e/0x7e0 net/netlink/af_netlink.c:1328
       netlink_sendmsg+0x91c/0xea0 net/netlink/af_netlink.c:1917
       sock_sendmsg_nosec net/socket.c:652 [inline]
       sock_sendmsg+0xd7/0x130 net/socket.c:672
       ____sys_sendmsg+0x753/0x880 net/socket.c:2343
       ___sys_sendmsg+0x100/0x170 net/socket.c:2397
       __sys_sendmsg+0x105/0x1d0 net/socket.c:2430
       __do_sys_sendmsg net/socket.c:2439 [inline]
       __se_sys_sendmsg net/socket.c:2437 [inline]
       __x64_sys_sendmsg+0x78/0xb0 net/socket.c:2437
       do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
       entry_SYSCALL_64_after_hwframe+0x49/0xbe

other info that might help us debug this:

Chain exists of:
  (wq_completion)wg-kex-wireguard0 --> (work_completion)(&peer->transmit_handshake_work) --> &wg->static_identity.lock

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(&wg->static_identity.lock);
                               lock((work_completion)(&peer->transmit_handshake_work));
                               lock(&wg->static_identity.lock);
  lock((wq_completion)wg-kex-wireguard0);

 *** DEADLOCK ***

5 locks held by syz-executor103/9743:
 #0: ffffffff8a796128 (cb_lock){++++}, at: genl_rcv+0x1a/0x40 net/netlink/genetlink.c:744
 #1: ffffffff8a7961e0 (genl_mutex){+.+.}, at: genl_lock net/netlink/genetlink.c:33 [inline]
 #1: ffffffff8a7961e0 (genl_mutex){+.+.}, at: genl_rcv_msg+0x7de/0xea0 net/netlink/genetlink.c:732
 #2: ffffffff8a7403c0 (rtnl_mutex){+.+.}, at: rtnl_lock+0x17/0x20 net/core/rtnetlink.c:72
 #3: ffff88809ead90a0 (&wg->device_update_lock){+.+.}, at: wg_set_device+0x2be/0x1350 drivers/net/wireguard/netlink.c:510
 #4: ffff88809ead8e80 (&wg->static_identity.lock){++++}, at: wg_set_device+0xe8b/0x1350 drivers/net/wireguard/netlink.c:567

stack backtrace:
CPU: 1 PID: 9743 Comm: syz-executor103 Not tainted 5.5.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x197/0x210 lib/dump_stack.c:118
 print_circular_bug.isra.0.cold+0x163/0x172 kernel/locking/lockdep.c:1684
 check_noncircular+0x32e/0x3e0 kernel/locking/lockdep.c:1808
 check_prev_add kernel/locking/lockdep.c:2475 [inline]
 check_prevs_add kernel/locking/lockdep.c:2580 [inline]
 validate_chain kernel/locking/lockdep.c:2970 [inline]
 __lock_acquire+0x2596/0x4a00 kernel/locking/lockdep.c:3954
 lock_acquire+0x190/0x410 kernel/locking/lockdep.c:4484
 flush_workqueue+0x126/0x14c0 kernel/workqueue.c:2775
 peer_remove_after_dead+0x16b/0x230 drivers/net/wireguard/peer.c:141
 wg_peer_remove+0x244/0x340 drivers/net/wireguard/peer.c:176
 wg_set_device+0xf76/0x1350 drivers/net/wireguard/netlink.c:575
 genl_family_rcv_msg_doit net/netlink/genetlink.c:672 [inline]
 genl_family_rcv_msg net/netlink/genetlink.c:717 [inline]
 genl_rcv_msg+0x67d/0xea0 net/netlink/genetlink.c:734
 netlink_rcv_skb+0x177/0x450 net/netlink/af_netlink.c:2477
 genl_rcv+0x29/0x40 net/netlink/genetlink.c:745
 netlink_unicast_kernel net/netlink/af_netlink.c:1302 [inline]
 netlink_unicast+0x59e/0x7e0 net/netlink/af_netlink.c:1328
 netlink_sendmsg+0x91c/0xea0 net/netlink/af_netlink.c:1917
 sock_sendmsg_nosec net/socket.c:652 [inline]
 sock_sendmsg+0xd7/0x130 net/socket.c:672
 ____sys_sendmsg+0x753/0x880 net/socket.c:2343
 ___sys_sendmsg+0x100/0x170 net/socket.c:2397
 __sys_sendmsg+0x105/0x1d0 net/socket.c:2430
 __do_sys_sendmsg net/socket.c:2439 [inline]
 __se_sys_sendmsg net/socket.c:2437 [inline]
 __x64_sys_sendmsg+0x78/0xb0 net/socket.c:2437
 do_syscall_64+0xfa/0x790 arch/x86/entry/common.c:294
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x446909
Code: 18 89 d0 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 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 0f 83 9b d4 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffde39ca2e8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 0000000000003064 RCX: 0000000000446909
RDX: 0000000000000000 RSI: 0000000020001340 RDI: 0000000000000004
RBP: 7261756765726977 R08: 0000000000000000 R09: 0000000001bbbbbb
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00000000004042c0 R14: 0000000000000000 R15: 0000000000000000

Crashes (33):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2020/02/02 13:21 upstream 94f2630b1897 2274ad39 .config console log report syz C ci-upstream-kasan-gce-root
2020/02/01 03:33 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz C ci-upstream-kasan-gce-smack-root
2020/02/01 01:42 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz C ci-upstream-kasan-gce
2020/02/01 07:23 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz C ci-upstream-kasan-gce-386
2020/02/01 05:56 net-old 9f68e3655aae c30117b2 .config console log report syz C ci-upstream-net-this-kasan-gce
2020/02/01 04:57 net-old 9f68e3655aae c30117b2 .config console log report syz C ci-upstream-net-this-kasan-gce
2020/02/01 06:27 net-next-old 9f68e3655aae c30117b2 .config console log report syz C ci-upstream-net-kasan-gce
2020/02/01 01:01 net-next-old 9f68e3655aae c30117b2 .config console log report syz C ci-upstream-net-kasan-gce
2020/02/03 14:32 upstream 46d6b7becb1d 93e5e335 .config console log report syz ci-upstream-kasan-gce-selinux-root
2020/02/03 13:42 upstream 46d6b7becb1d 93e5e335 .config console log report syz ci-upstream-kasan-gce-selinux-root
2020/02/02 16:57 upstream 94f2630b1897 93e5e335 .config console log report syz ci-upstream-kasan-gce-root
2020/02/02 12:22 upstream 94f2630b1897 2274ad39 .config console log report syz ci-upstream-kasan-gce-root
2020/02/01 07:28 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz ci-upstream-kasan-gce
2020/02/01 05:30 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz ci-upstream-kasan-gce
2020/02/01 04:16 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz ci-upstream-kasan-gce-smack-root
2020/02/08 19:08 upstream f757165705e9 06150bf1 .config console log report ci-upstream-kasan-gce
2020/02/08 12:35 upstream f757165705e9 06150bf1 .config console log report ci-upstream-kasan-gce-smack-root
2020/02/08 00:37 upstream 41dcd67e8868 06150bf1 .config console log report ci-upstream-kasan-gce-root
2020/02/07 12:50 upstream 90568ecf5615 06150bf1 .config console log report ci-upstream-kasan-gce-smack-root
2020/02/03 23:05 upstream 754beeec1d90 93e5e335 .config console log report ci-upstream-kasan-gce-smack-root
2020/02/01 12:19 upstream 26dca6dbd62d 0eb59c27 .config console log report ci-upstream-kasan-gce
2020/02/01 00:04 upstream ccaaaf6fe5a5 c30117b2 .config console log report ci-upstream-kasan-gce-selinux-root
2020/02/01 00:02 upstream ccaaaf6fe5a5 c30117b2 .config console log report ci-upstream-kasan-gce
2020/02/06 21:42 upstream 4c46bef2e96a c91cbc9d .config console log report ci-upstream-kasan-gce-386
2020/02/06 20:09 upstream 4c46bef2e96a c91cbc9d .config console log report ci-upstream-kasan-gce-386
2020/02/01 00:50 upstream ccaaaf6fe5a5 c30117b2 .config console log report ci-upstream-kasan-gce-386
2020/02/01 00:07 upstream ccaaaf6fe5a5 c30117b2 .config console log report ci-upstream-kasan-gce-386
2020/01/31 23:50 net-old 9f68e3655aae c30117b2 .config console log report ci-upstream-net-this-kasan-gce
2020/02/06 21:36 net-next-old 33b40134e5cf c91cbc9d .config console log report ci-upstream-net-kasan-gce
2020/02/06 19:41 net-next-old 33b40134e5cf c91cbc9d .config console log report ci-upstream-net-kasan-gce
2020/02/05 16:13 net-next-old 33b40134e5cf 662cf49a .config console log report ci-upstream-net-kasan-gce
2020/02/01 00:11 net-next-old 9f68e3655aae c30117b2 .config console log report ci-upstream-net-kasan-gce
2020/01/31 23:53 net-next-old 9f68e3655aae c30117b2 .config console log report ci-upstream-net-kasan-gce
* Struck through repros no longer work on HEAD.