Subject: Re: possible deadlock in nr_destroy_socket

From: syzbot <[email-masked]>
Date: Sun, 06 Jan 2019 13:43:03 -0800

syzbot has found a reproducer for the following crash on:

HEAD commit:    b71acb0e3721 Merge branch 'linus' of git://git.kernel.org/..
git tree:       net-next
console output: https://syzkaller.appspot.com/x/log.txt?x=165dec07400000
kernel config:  https://syzkaller.appspot.com/x/.config?x=b03c5892bb940c76
dashboard link: https://syzkaller.appspot.com/bug?extid=acfc1713819b146ae4b2
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=11bb1be7400000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: [email-masked]

8021q: adding VLAN 0 to HW filter on device batadv0
8021q: adding VLAN 0 to HW filter on device batadv0
IPv6: ADDRCONF(NETDEV_UP): vxcan1: link is not ready
8021q: adding VLAN 0 to HW filter on device batadv0
======================================================
WARNING: possible circular locking dependency detected
4.20.0+ #3 Not tainted
------------------------------------------------------
swapper/0/0 is trying to acquire lock:
00000000bfd26260 (nr_list_lock){+.-.}, at: spin_lock_bh  
include/linux/spinlock.h:334 [inline]
00000000bfd26260 (nr_list_lock){+.-.}, at: nr_remove_socket  
net/netrom/af_netrom.c:96 [inline]
00000000bfd26260 (nr_list_lock){+.-.}, at: nr_destroy_socket+0x96/0x6e0  
net/netrom/af_netrom.c:264

but task is already holding lock:
00000000a8313e1f (slock-AF_NETROM){+.-.}, at: spin_lock  
include/linux/spinlock.h:329 [inline]
00000000a8313e1f (slock-AF_NETROM){+.-.}, at: nr_destroy_timer+0x32/0x90  
net/netrom/af_netrom.c:247

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #1 (slock-AF_NETROM){+.-.}:
        __raw_spin_lock include/linux/spinlock_api_smp.h:142 [inline]
        _raw_spin_lock+0x2f/0x40 kernel/locking/spinlock.c:144
        spin_lock include/linux/spinlock.h:329 [inline]
        nr_find_listener net/netrom/af_netrom.c:156 [inline]
        nr_rx_frame+0x60c/0x1d50 net/netrom/af_netrom.c:955
        nr_loopback_timer+0x7b/0x170 net/netrom/nr_loopback.c:62
        call_timer_fn+0x254/0x900 kernel/time/timer.c:1325
        expire_timers kernel/time/timer.c:1362 [inline]
        __run_timers+0x6fc/0xd50 kernel/time/timer.c:1681
        run_timer_softirq+0x52/0xb0 kernel/time/timer.c:1694
        __do_softirq+0x30b/0xb11 kernel/softirq.c:292
        invoke_softirq kernel/softirq.c:373 [inline]
        irq_exit+0x180/0x1d0 kernel/softirq.c:413
        exiting_irq arch/x86/include/asm/apic.h:536 [inline]
        smp_apic_timer_interrupt+0x1b7/0x760 arch/x86/kernel/apic/apic.c:1062
        apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:807
        arch_local_irq_restore arch/x86/include/asm/paravirt.h:766 [inline]
        lock_is_held_type+0x17e/0x210 kernel/locking/lockdep.c:3881
        lock_is_held include/linux/lockdep.h:337 [inline]
        ___might_sleep+0x248/0x310 kernel/sched/core.c:6113
        __might_sleep+0x95/0x190 kernel/sched/core.c:6101
        slab_pre_alloc_hook mm/slab.h:421 [inline]
        slab_alloc mm/slab.c:3378 [inline]
        kmem_cache_alloc+0x2a7/0x700 mm/slab.c:3552
        getname_flags fs/namei.c:140 [inline]
        getname_flags+0xd6/0x5b0 fs/namei.c:129
        getname+0x1a/0x20 fs/namei.c:211
        do_sys_open+0x3a5/0x740 fs/open.c:1057
        __do_sys_open fs/open.c:1081 [inline]
        __se_sys_open fs/open.c:1076 [inline]
        __x64_sys_open+0x7e/0xc0 fs/open.c:1076
        do_syscall_64+0x1a3/0x800 arch/x86/entry/common.c:290
        entry_SYSCALL_64_after_hwframe+0x49/0xbe

-> #0 (nr_list_lock){+.-.}:
        lock_acquire+0x1db/0x570 kernel/locking/lockdep.c:3841
        __raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
        _raw_spin_lock_bh+0x33/0x50 kernel/locking/spinlock.c:168
        spin_lock_bh include/linux/spinlock.h:334 [inline]
        nr_remove_socket net/netrom/af_netrom.c:96 [inline]
        nr_destroy_socket+0x96/0x6e0 net/netrom/af_netrom.c:264
        nr_destroy_timer+0x42/0x90 net/netrom/af_netrom.c:249
        call_timer_fn+0x254/0x900 kernel/time/timer.c:1325
        expire_timers kernel/time/timer.c:1362 [inline]
        __run_timers+0x6fc/0xd50 kernel/time/timer.c:1681
        run_timer_softirq+0x52/0xb0 kernel/time/timer.c:1694
        __do_softirq+0x30b/0xb11 kernel/softirq.c:292
        invoke_softirq kernel/softirq.c:373 [inline]
        irq_exit+0x180/0x1d0 kernel/softirq.c:413
        exiting_irq arch/x86/include/asm/apic.h:536 [inline]
        smp_apic_timer_interrupt+0x1b7/0x760 arch/x86/kernel/apic/apic.c:1062
        apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:807
        native_safe_halt+0x2/0x10 arch/x86/include/asm/irqflags.h:57
        arch_cpu_idle+0x10/0x20 arch/x86/kernel/process.c:555
        default_idle_call+0x36/0x90 kernel/sched/idle.c:93
        cpuidle_idle_call kernel/sched/idle.c:153 [inline]
        do_idle+0x386/0x5d0 kernel/sched/idle.c:262
        cpu_startup_entry+0x1b/0x20 kernel/sched/idle.c:353
        rest_init+0x245/0x37b init/main.c:443
        arch_call_rest_init+0xe/0x1b
        start_kernel+0x882/0x8bd init/main.c:741
        x86_64_start_reservations+0x29/0x2b arch/x86/kernel/head64.c:470
        x86_64_start_kernel+0x77/0x7b arch/x86/kernel/head64.c:451
        secondary_startup_64+0xa4/0xb0 arch/x86/kernel/head_64.S:243

other info that might help us debug this:

  Possible unsafe locking scenario:

        CPU0                    CPU1
        ----                    ----
   lock(slock-AF_NETROM);
                                lock(nr_list_lock);
                                lock(slock-AF_NETROM);
   lock(nr_list_lock);

  *** DEADLOCK ***

2 locks held by swapper/0/0:
  #0: 000000007f861baa ((&sk->sk_timer)){+.-.}, at: lockdep_copy_map  
include/linux/lockdep.h:171 [inline]
  #0: 000000007f861baa ((&sk->sk_timer)){+.-.}, at:  
call_timer_fn+0x1b4/0x900 kernel/time/timer.c:1315
  #1: 00000000a8313e1f (slock-AF_NETROM){+.-.}, at: spin_lock  
include/linux/spinlock.h:329 [inline]
  #1: 00000000a8313e1f (slock-AF_NETROM){+.-.}, at:  
nr_destroy_timer+0x32/0x90 net/netrom/af_netrom.c:247

stack backtrace:
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.20.0+ #3
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
Call Trace:
  <IRQ>
  __dump_stack lib/dump_stack.c:77 [inline]
  dump_stack+0x1db/0x2d0 lib/dump_stack.c:113
  print_circular_bug.isra.0.cold+0x1cc/0x28f kernel/locking/lockdep.c:1224
  check_prev_add kernel/locking/lockdep.c:1866 [inline]
  check_prevs_add kernel/locking/lockdep.c:1979 [inline]
  validate_chain kernel/locking/lockdep.c:2350 [inline]
  __lock_acquire+0x3014/0x4a30 kernel/locking/lockdep.c:3338
  lock_acquire+0x1db/0x570 kernel/locking/lockdep.c:3841
  __raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]
  _raw_spin_lock_bh+0x33/0x50 kernel/locking/spinlock.c:168
  spin_lock_bh include/linux/spinlock.h:334 [inline]
  nr_remove_socket net/netrom/af_netrom.c:96 [inline]
  nr_destroy_socket+0x96/0x6e0 net/netrom/af_netrom.c:264
  nr_destroy_timer+0x42/0x90 net/netrom/af_netrom.c:249
  call_timer_fn+0x254/0x900 kernel/time/timer.c:1325
  expire_timers kernel/time/timer.c:1362 [inline]
  __run_timers+0x6fc/0xd50 kernel/time/timer.c:1681
  run_timer_softirq+0x52/0xb0 kernel/time/timer.c:1694
  __do_softirq+0x30b/0xb11 kernel/softirq.c:292
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
  invoke_softirq kernel/softirq.c:373 [inline]
  irq_exit+0x180/0x1d0 kernel/softirq.c:413
  exiting_irq arch/x86/include/asm/apic.h:536 [inline]
  smp_apic_timer_interrupt+0x1b7/0x760 arch/x86/kernel/apic/apic.c:1062
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
  apic_timer_interrupt+0xf/0x20 arch/x86/entry/entry_64.S:807
  </IRQ>
RIP: 0010:native_safe_halt+0x2/0x10 arch/x86/include/asm/irqflags.h:58
Code: ff ff ff 48 89 c7 48 89 45 d8 e8 c9 1a ce f9 48 8b 45 d8 e9 ce fe ff  
ff 48 89 df e8 b8 1a ce f9 eb 82 90 90 90 90 90 90 fb f4 <c3> 0f 1f 00 66  
2e 0f 1f 84 00 00 00 00 00 f4 c3 90 90 90 90 90 90
RSP: 0018:ffffffff89807c60 EFLAGS: 00000282 ORIG_RAX: ffffffffffffff13
RAX: 1ffffffff1324a09 RBX: 1ffffffff1300f8f RCX: 0000000000000000
kobject: 'loop4' (000000002df42488): kobject_uevent_env
RDX: dffffc0000000000 RSI: 0000000000000001 RDI: ffffffff8987b73c
RBP: ffffffff89807d20 R08: ffffffff8987aec0 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
R13: ffffffff89807cf8 R14: 0000000000000000 R15: ffffffff89925038
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
  arch_cpu_idle+0x10/0x20 arch/x86/kernel/process.c:555
  default_idle_call+0x36/0x90 kernel/sched/idle.c:93
  cpuidle_idle_call kernel/sched/idle.c:153 [inline]
  do_idle+0x386/0x5d0 kernel/sched/idle.c:262
  cpu_startup_entry+0x1b/0x20 kernel/sched/idle.c:353
  rest_init+0x245/0x37b init/main.c:443
  arch_call_rest_init+0xe/0x1b
  start_kernel+0x882/0x8bd init/main.c:741
  x86_64_start_reservations+0x29/0x2b arch/x86/kernel/head64.c:470
  x86_64_start_kernel+0x77/0x7b arch/x86/kernel/head64.c:451
  secondary_startup_64+0xa4/0xb0 arch/x86/kernel/head_64.S:243
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop5' (00000000dd3ce6d6): kobject_uevent_env
kobject: 'loop5' (00000000dd3ce6d6): fill_kobj_path: path  
= '/devices/virtual/block/loop5'
kobject: 'loop4' (000000002df42488): kobject_uevent_env
kobject: 'loop4' (000000002df42488): fill_kobj_path: path  
= '/devices/virtual/block/loop4'
kobject: 'loop3' (00000000cf50dc1c): kobject_uevent_env
kobject: 'loop3' (00000000cf50dc1c): fill_kobj_path: path  
= '/devices/virtual/block/loop3'
kobject: 'loop0' (00000000a2069ce8): kobject_uevent_env
kobject: 'loop0' (00000000a2069ce8): fill_kobj_path: path  
= '/devices/virtual/block/loop0'
kobject: 'loop2' (00000000931f70f4): kobject_uevent_env
kobject: 'loop2' (00000000931f70f4): fill_kobj_path: path  
= '/devices/virtual/block/loop2'
kobject: 'loop1' (0000000096e13d4d): kobject_uevent_env
kobject: 'loop1' (0000000096e13d4d): fill_kobj_path: path  
= '/devices/virtual/block/loop1'