syzbot


possible deadlock in wg_noise_handshake_create_initiation

Status: fixed on 2020/03/11 20:34
Subsystems: wireguard
[Documentation on labels]
Reported-by: syzbot+d5bc560aaa1cedefffd5@syzkaller.appspotmail.com
Fix commit: ec31c2676a10 wireguard: noise: reject peers with low order public keys
First crash: 1600d, last: 1594d
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_noise_handshake_create_initiation 1 (2) 2020/02/03 20:24

Sample crash report:
======================================================
WARNING: possible circular locking dependency detected
5.5.0-syzkaller #0 Not tainted
------------------------------------------------------
kworker/u4:4/339 is trying to acquire lock:
ffff888085920e80 (&wg->static_identity.lock){++++}, at: wg_noise_handshake_create_initiation+0xc0/0x670 drivers/net/wireguard/noise.c:499

but task is already holding lock:
ffffc90001a77dc0 ((work_completion)(&peer->transmit_handshake_work)){+.+.}, at: process_one_work+0x917/0x17a0 kernel/workqueue.c:2239

which lock already depends on the new lock.


the existing dependency chain (in reverse order) is:

-> #2 ((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

-> #1 ((wq_completion)wg-kex-wireguard0){+.+.}:
       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

-> #0 (&wg->static_identity.lock){++++}:
       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
       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

other info that might help us debug this:

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

 Possible unsafe locking scenario:

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

 *** DEADLOCK ***

2 locks held by kworker/u4:4/339:
 #0: ffff888097b11528 ((wq_completion)wg-kex-wireguard0){+.+.}, at: __write_once_size include/linux/compiler.h:226 [inline]
 #0: ffff888097b11528 ((wq_completion)wg-kex-wireguard0){+.+.}, at: arch_atomic64_set arch/x86/include/asm/atomic64_64.h:34 [inline]
 #0: ffff888097b11528 ((wq_completion)wg-kex-wireguard0){+.+.}, at: atomic64_set include/asm-generic/atomic-instrumented.h:855 [inline]
 #0: ffff888097b11528 ((wq_completion)wg-kex-wireguard0){+.+.}, at: atomic_long_set include/asm-generic/atomic-long.h:40 [inline]
 #0: ffff888097b11528 ((wq_completion)wg-kex-wireguard0){+.+.}, at: set_work_data kernel/workqueue.c:615 [inline]
 #0: ffff888097b11528 ((wq_completion)wg-kex-wireguard0){+.+.}, at: set_work_pool_and_clear_pending kernel/workqueue.c:642 [inline]
 #0: ffff888097b11528 ((wq_completion)wg-kex-wireguard0){+.+.}, at: process_one_work+0x8dd/0x17a0 kernel/workqueue.c:2235
 #1: ffffc90001a77dc0 ((work_completion)(&peer->transmit_handshake_work)){+.+.}, at: process_one_work+0x917/0x17a0 kernel/workqueue.c:2239

stack backtrace:
CPU: 0 PID: 339 Comm: kworker/u4:4 Not tainted 5.5.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Workqueue: wg-kex-wireguard0 wg_packet_handshake_send_worker
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
 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

Crashes (11):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2020/02/03 20:19 upstream 754beeec1d90 93e5e335 .config console log report syz C ci-upstream-kasan-gce-selinux-root
2020/02/01 06:19 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz C ci-upstream-kasan-gce-smack-root
2020/02/01 03:22 upstream ccaaaf6fe5a5 c30117b2 .config console log report syz C ci-upstream-kasan-gce-386
2020/02/01 06:55 net-old 9f68e3655aae c30117b2 .config console log report syz C ci-upstream-net-this-kasan-gce
2020/02/01 07:34 net-next-old 9f68e3655aae c30117b2 .config console log report syz C ci-upstream-net-kasan-gce
2020/02/05 07:18 upstream 33b40134e5cf 93e5e335 .config console log report ci-upstream-kasan-gce-root
2020/02/07 04:54 upstream 90568ecf5615 06150bf1 .config console log report ci-upstream-kasan-gce-386
2020/02/01 15:18 net-old 784f8344de75 0eb59c27 .config console log report ci-upstream-net-this-kasan-gce
2020/02/01 00:36 net-old 9f68e3655aae c30117b2 .config console log report ci-upstream-net-this-kasan-gce
2020/02/05 03:59 net-next-old 33b40134e5cf 93e5e335 .config console log report ci-upstream-net-kasan-gce
2020/01/31 23:54 net-next-old 9f68e3655aae c30117b2 .config console log report ci-upstream-net-kasan-gce
* Struck through repros no longer work on HEAD.