syzbot


inconsistent lock state in nf_connlabels_put

Status: fixed on 2024/01/03 15:50
Subsystems: netfilter
[Documentation on labels]
Fix commit: 643d12603664 netfilter: conntrack: switch connlabels to atomic_t
First crash: 352d, last: 351d
Cause bisection: introduced by (bisect log) :
commit 70f06c115bcca26ceeebf938e48bc8143668e38b
Author: Florian Westphal <fw@strlen.de>
Date: Tue Oct 24 11:05:51 2023 +0000

  sched: act_ct: switch to per-action label counting

Crash: inconsistent lock state in nf_connlabels_put (log)
Repro: C syz .config
  

Sample crash report:
================================
WARNING: inconsistent lock state
6.6.0-rc6-syzkaller-01837-gdf3bc66219e3 #0 Not tainted
--------------------------------
inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
sshd/5040 [HC0[0]:SC1[1]:HE1:SE0] takes:
ffffffff8e69d658 (nf_connlabels_lock){+.?.}-{2:2}, at: spin_lock include/linux/spinlock.h:351 [inline]
ffffffff8e69d658 (nf_connlabels_lock){+.?.}-{2:2}, at: nf_connlabels_put+0x19/0x60 net/netfilter/nf_conntrack_labels.c:78
{SOFTIRQ-ON-W} state was registered at:
  lock_acquire kernel/locking/lockdep.c:5753 [inline]
  lock_acquire+0x1ae/0x510 kernel/locking/lockdep.c:5718
  __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]
  nf_connlabels_get+0x32/0x90 net/netfilter/nf_conntrack_labels.c:66
  ovs_ct_init+0x62/0x4c0 net/openvswitch/conntrack.c:1975
  ovs_init_net+0x2ff/0x5a0 net/openvswitch/datapath.c:2638
  ops_init+0xb9/0x650 net/core/net_namespace.c:136
  __register_pernet_operations net/core/net_namespace.c:1165 [inline]
  register_pernet_operations+0x34b/0x820 net/core/net_namespace.c:1234
  register_pernet_device+0x29/0x70 net/core/net_namespace.c:1321
  dp_init+0xb7/0x2b0 net/openvswitch/datapath.c:2745
  do_one_initcall+0x117/0x630 init/main.c:1232
  do_initcall_level init/main.c:1294 [inline]
  do_initcalls init/main.c:1310 [inline]
  do_basic_setup init/main.c:1329 [inline]
  kernel_init_freeable+0x5c2/0x900 init/main.c:1547
  kernel_init+0x1c/0x2a0 init/main.c:1437
  ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147
  ret_from_fork_asm+0x11/0x20 arch/x86/entry/entry_64.S:304
irq event stamp: 3030552
hardirqs last  enabled at (3030552): [<ffffffff8a440c8e>] __raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:151 [inline]
hardirqs last  enabled at (3030552): [<ffffffff8a440c8e>] _raw_spin_unlock_irqrestore+0x4e/0x70 kernel/locking/spinlock.c:194
hardirqs last disabled at (3030551): [<ffffffff8a440a3e>] __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:108 [inline]
hardirqs last disabled at (3030551): [<ffffffff8a440a3e>] _raw_spin_lock_irqsave+0x4e/0x50 kernel/locking/spinlock.c:162
softirqs last  enabled at (3030342): [<ffffffff88b7f498>] tcp_sendmsg+0x38/0x40 net/ipv4/tcp.c:1339
softirqs last disabled at (3030447): [<ffffffff814fe6c7>] invoke_softirq kernel/softirq.c:427 [inline]
softirqs last disabled at (3030447): [<ffffffff814fe6c7>] __irq_exit_rcu kernel/softirq.c:632 [inline]
softirqs last disabled at (3030447): [<ffffffff814fe6c7>] irq_exit_rcu+0xb7/0x120 kernel/softirq.c:644

other info that might help us debug this:
 Possible unsafe locking scenario:

       CPU0
       ----
  lock(nf_connlabels_lock);
  <Interrupt>
    lock(nf_connlabels_lock);

 *** DEADLOCK ***

1 lock held by sshd/5040:
 #0: ffffffff8cbab280 (rcu_callback){....}-{0:0}, at: rcu_lock_acquire include/linux/rcupdate.h:303 [inline]
 #0: ffffffff8cbab280 (rcu_callback){....}-{0:0}, at: rcu_do_batch kernel/rcu/tree.c:2134 [inline]
 #0: ffffffff8cbab280 (rcu_callback){....}-{0:0}, at: rcu_core+0x7c1/0x1bb0 kernel/rcu/tree.c:2403

stack backtrace:
CPU: 0 PID: 5040 Comm: sshd Not tainted 6.6.0-rc6-syzkaller-01837-gdf3bc66219e3 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/06/2023
Call Trace:
 <IRQ>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd9/0x1b0 lib/dump_stack.c:106
 print_usage_bug kernel/locking/lockdep.c:3970 [inline]
 valid_state kernel/locking/lockdep.c:4012 [inline]
 mark_lock_irq kernel/locking/lockdep.c:4215 [inline]
 mark_lock+0x11f3/0x1950 kernel/locking/lockdep.c:4677
 mark_usage kernel/locking/lockdep.c:4566 [inline]
 __lock_acquire+0x165c/0x5de0 kernel/locking/lockdep.c:5090
 lock_acquire kernel/locking/lockdep.c:5753 [inline]
 lock_acquire+0x1ae/0x510 kernel/locking/lockdep.c:5718
 __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]
 nf_connlabels_put+0x19/0x60 net/netfilter/nf_conntrack_labels.c:78
 tcf_ct_params_free+0x251/0x460 net/sched/act_ct.c:833
 rcu_do_batch kernel/rcu/tree.c:2139 [inline]
 rcu_core+0x805/0x1bb0 kernel/rcu/tree.c:2403
 __do_softirq+0x218/0x965 kernel/softirq.c:553
 invoke_softirq kernel/softirq.c:427 [inline]
 __irq_exit_rcu kernel/softirq.c:632 [inline]
 irq_exit_rcu+0xb7/0x120 kernel/softirq.c:644
 sysvec_apic_timer_interrupt+0x93/0xc0 arch/x86/kernel/apic/apic.c:1074
 </IRQ>
 <TASK>
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:645
RIP: 0010:lock_release+0x3b8/0x680 kernel/locking/lockdep.c:5761
Code: 7e 83 f8 01 0f 85 dd 01 00 00 9c 58 f6 c4 02 0f 85 c8 01 00 00 48 f7 04 24 00 02 00 00 74 01 fb 48 b8 00 00 00 00 00 fc ff df <48> 01 c5 48 c7 45 00 00 00 00 00 c7 45 08 00 00 00 00 48 8b 84 24
RSP: 0018:ffffc900039af7f0 EFLAGS: 00000206
RAX: dffffc0000000000 RBX: ffffffffffffffff RCX: ffffc900039af840
RDX: 1ffff110033dc50f RSI: ffffffff8a8cafa0 RDI: ffffffff8ae93ea0
RBP: 1ffff92000735f00 R08: 0000000000000000 R09: fffffbfff1d989aa
R10: ffffffff8ecc4d57 R11: 0000000000000000 R12: 0000000000000000
R13: 0000000000000001 R14: ffff888019ee2880 R15: ffff888019ee1dc0
 __might_fault mm/memory.c:5896 [inline]
 __might_fault+0x158/0x1a0 mm/memory.c:5889
 _copy_from_user+0x2b/0xf0 lib/usercopy.c:14
 copy_from_user include/linux/uaccess.h:183 [inline]
 do_sys_poll+0x1d3/0xde0 fs/select.c:997
 __do_sys_ppoll fs/select.c:1121 [inline]
 __se_sys_ppoll fs/select.c:1101 [inline]
 __x64_sys_ppoll+0x256/0x2d0 fs/select.c:1101
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f5a9bb19ad5
Code: 85 d2 74 0d 0f 10 02 48 8d 54 24 20 0f 11 44 24 20 64 8b 04 25 18 00 00 00 85 c0 75 27 41 b8 08 00 00 00 b8 0f 01 00 00 0f 05 <48> 3d 00 f0 ff ff 76 75 48 8b 15 24 73 0d 00 f7 d8 64 89 02 48 83
RSP: 002b:00007fff44a07f80 EFLAGS: 00000246 ORIG_RAX: 000000000000010f
RAX: ffffffffffffffda RBX: 00000000000668a0 RCX: 00007f5a9bb19ad5
RDX: 00007fff44a07fa0 RSI: 0000000000000004 RDI: 0000564a8ac96ab0
RBP: 0000564a8ac95570 R08: 0000000000000008 R09: 0000000000000000
R10: 00007fff44a08088 R11: 0000000000000246 R12: 0000564a891faaa4
R13: 0000000000000001 R14: 0000564a891fb3e8 R15: 00007fff44a08008
 </TASK>
----------------
Code disassembly (best guess):
   0:	7e 83                	jle    0xffffff85
   2:	f8                   	clc
   3:	01 0f                	add    %ecx,(%rdi)
   5:	85 dd                	test   %ebx,%ebp
   7:	01 00                	add    %eax,(%rax)
   9:	00 9c 58 f6 c4 02 0f 	add    %bl,0xf02c4f6(%rax,%rbx,2)
  10:	85 c8                	test   %ecx,%eax
  12:	01 00                	add    %eax,(%rax)
  14:	00 48 f7             	add    %cl,-0x9(%rax)
  17:	04 24                	add    $0x24,%al
  19:	00 02                	add    %al,(%rdx)
  1b:	00 00                	add    %al,(%rax)
  1d:	74 01                	je     0x20
  1f:	fb                   	sti
  20:	48 b8 00 00 00 00 00 	movabs $0xdffffc0000000000,%rax
  27:	fc ff df
* 2a:	48 01 c5             	add    %rax,%rbp <-- trapping instruction
  2d:	48 c7 45 00 00 00 00 	movq   $0x0,0x0(%rbp)
  34:	00
  35:	c7 45 08 00 00 00 00 	movl   $0x0,0x8(%rbp)
  3c:	48                   	rex.W
  3d:	8b                   	.byte 0x8b
  3e:	84                   	.byte 0x84
  3f:	24                   	.byte 0x24

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/10/26 09:22 net-next df3bc66219e3 72e794c4 .config strace log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-net-kasan-gce inconsistent lock state in nf_connlabels_put
2023/10/26 12:31 net-next df3bc66219e3 23afc60f .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-net-kasan-gce inconsistent lock state in nf_connlabels_put
2023/10/26 05:58 net-next df3bc66219e3 72e794c4 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-net-kasan-gce inconsistent lock state in nf_connlabels_put
2023/10/25 15:55 net-next f3bbfe4dbfd4 72e794c4 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-net-kasan-gce inconsistent lock state in nf_connlabels_put
* Struck through repros no longer work on HEAD.