inconsistent lock state in tap_sock_destruct

Status: upstream: reported C repro on 2026/11/24 20:44
Subsystems: net
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+a2220efe757ca2a7358d@syzkaller.appspotmail.com
First crash: 4d01h, last: 2d02h
✨ AI cause bisection: introduced by (AI job) :
commit 362899b8725b35e32802882c67f99cbf42bce2af
Author: Jason Wang <jasowang@redhat.com>
Date: Fri Jul 15 07:46:31 2016 +0000

  macvtap: switch to use skb array

✨ AI-generated root cause summary:

In drivers/net/tap.c, tap_sock_destruct() calls ptr_ring_cleanup(&q->ring, __skb_array_destroy_skb), which drains the ring via ptr_ring_consume() and acquires &q->ring.consumer_lock with plain spin_lock() (without disabling softirqs/BH). Because tap_alloc_skb() attaches transmitted sk_buffs to &q->sk via sock_alloc_send_pskb() -> skb_set_owner_w(), an in-flight TX skb can outlive tap_release() -> tap_put_queue() and later drop the final sk_wmem_alloc reference in softirq context via sock_wfree() -> __sk_free() -> sk_destruct() -> __sk_destruct() -> tap_sock_destruct(). Since &q->ring.consumer_lock is normally acquired with plain spin_lock() in process context (e.g., tap_do_read(), tap_peek_len(), or synchronous tap_sock_destruct() in tap_release()), acquiring it in softirq context violates lockdep's {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} rule.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 65e4fd942f72:

Root Cause Analysis

The lockdep warning (inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage on &r->consumer_lock#3) is caused by tap_sock_destruct() calling ptr_ring_cleanup() when q->sk is destroyed from softirq context (sock_wfree()), while q->ring.consumer_lock is otherwise acquired with plain spin_lock() in process context (with softirqs enabled).

Mechanism and Involved Code

  1. Ring initialization and lock usage (drivers/net/tap.c, include/linux/ptr_ring.h):

    • tap_open() (drivers/net/tap.c:464) initializes q->ring via ptr_ring_init(&q->ring, tap->dev->tx_queue_len, GFP_KERNEL), creating the lockdep class &r->consumer_lock for q->ring.consumer_lock.
    • tap_open() sets q->sk.sk_destruct = tap_sock_destruct (drivers/net/tap.c:476).
    • In normal operation, &q->ring.consumer_lock is acquired in process context with softirqs enabled (SOFTIRQ-ON-W) via plain spin_lock(&r->consumer_lock):
  2. Socket ownership of TX sk_buffs and deferred destruction in softirq:

    • When userspace writes a packet via tap_write_iter() / tap_sendmsg() -> tap_get_user() (drivers/net/tap.c:623) -> tap_alloc_skb() (drivers/net/tap.c:556), sock_alloc_send_pskb() calls skb_set_owner_w(skb, &q->sk) (net/core/sock.c:2772), which sets skb->sk = &q->sk, sets skb->destructor = sock_wfree, and adds skb->truesize to q->sk.sk_wmem_alloc.
    • tap_get_user() then submits the packet via dev_queue_xmit(skb) (drivers/net/tap.c:675).
    • If the tap file descriptor is closed while such a TX sk_buff is still in flight, tap_release() -> tap_put_queue() detaches q, calls synchronize_rcu(), and drops sk_refcnt via sock_put(&q->sk) (drivers/net/tap.c:179). sk_free(&q->sk) (net/core/sock.c:2469) decrements sk->sk_wmem_alloc by the bias (1), which does not reach 0 because of the in-flight skb.
    • Later, when the in-flight skb is freed in softirq context (here in ksoftirqd: net_rx_action() -> process_backlog() -> llc_rcv() -> kfree_skb() -> skb_release_head_state() -> sock_wfree() at net/core/sock.c:2754), sk->sk_wmem_alloc reaches 0, triggering __sk_free(&q->sk) -> sk_destruct() -> __sk_destruct() -> tap_sock_destruct(&q->sk).
  3. Lockdep violation in ptr_ring_cleanup():

    • tap_sock_destruct() (drivers/net/tap.c:444) calls ptr_ring_cleanup(&q->ring, __skb_array_destroy_skb).
    • ptr_ring_cleanup() (include/linux/ptr_ring.h:695-703) drains the ring by calling ptr_ring_consume(r) (include/linux/ptr_ring.h:359-368), which acquires r->consumer_lock using plain spin_lock(&r->consumer_lock) (IN-SOFTIRQ-W) rather than draining locklessly (e.g., __ptr_ring_consume(r)) or using BH/IRQ-safe locking.
    • Because &q->ring.consumer_lock shares the same lockdep class with process-context SOFTIRQ-ON-W acquisitions, lockdep detects {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} and emits the inconsistent lock state warning.

Why No Real Deadlock Occurs on the Lock Instance

Although this violates lockdep's lock-class rules, tap_sock_destruct() only executes once per struct tap_queue after both sk_refcnt and sk_wmem_alloc have reached 0 (and after tap_put_queue()'s synchronize_rcu() or tap_del_queues() teardown). At that point, no file descriptor, tap_dev, tap_queue_resize() caller (which uses spin_lock_bh() anyway), or vhost_net consumer retains a reference to q or q->ring, so no process context can contend for &q->ring.consumer_lock concurrently with tap_sock_destruct().

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
7efe4b40 bisect-cause IsRelease: ❌ ❓ inconsistent lock state in tap_sock_destruct 2026/11/20 20:08 2026/11/20 20:08 2026/11/20 20:53 60a1d40d
7533448c assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ inconsistent lock state in tap_sock_destruct 2026/11/20 20:08 2026/11/20 20:08 2026/11/20 20:42 60a1d40d
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [net?] inconsistent lock state in tap_sock_destruct 0 (1) 2026/11/24 20:44
▶ ▼ Similar bugs (2)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-6.1 inconsistent lock state in tap_sock_destruct 4 syz, C 6 20h13m 7d04h 0/3 upstream: reported C repro on 2026/11/17 17:18
linux-5.15 inconsistent lock state in tap_sock_destruct 4 syz, C 9 1d04h 12d 0/3 upstream: reported C repro on 2026/11/12 16:37

Sample crash report:
================================
WARNING: inconsistent lock state
syzkaller #0 Not tainted
--------------------------------
inconsistent {IN-SOFTIRQ-W} -> {SOFTIRQ-ON-W} usage.
syz.0.18/6057 [HC0[0]:SC0[0]:HE1:SE1] takes:
ffff888053358720 (&r->consumer_lock#4){+.?.}-{3:3}, at: spin_lock include/linux/spinlock.h:347 [inline]
ffff888053358720 (&r->consumer_lock#4){+.?.}-{3:3}, at: ptr_ring_consume include/linux/ptr_ring.h:363 [inline]
ffff888053358720 (&r->consumer_lock#4){+.?.}-{3:3}, at: ptr_ring_cleanup include/linux/ptr_ring.h:700 [inline]
ffff888053358720 (&r->consumer_lock#4){+.?.}-{3:3}, at: tap_sock_destruct+0x13b/0x330 drivers/net/tap.c:444
{IN-SOFTIRQ-W} state was registered at:
  lock_acquire kernel/locking/lockdep.c:5942 [inline]
  lock_acquire+0x1d1/0x380 kernel/locking/lockdep.c:5899
  __raw_spin_lock include/linux/spinlock_api_smp.h:190 [inline]
  _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:173
  spin_lock include/linux/spinlock.h:347 [inline]
  ptr_ring_consume include/linux/ptr_ring.h:363 [inline]
  ptr_ring_cleanup include/linux/ptr_ring.h:700 [inline]
  tap_sock_destruct+0x13b/0x330 drivers/net/tap.c:444
  __sk_destruct+0x85/0xb70 net/core/sock.c:2386
  sk_destruct+0xc8/0xf0 net/core/sock.c:2448
  __sk_free+0xf4/0x3e0 net/core/sock.c:2459
  sock_wfree+0x254/0x7f0 net/core/sock.c:2754
  skb_release_head_state+0x35f/0x400 net/core/skbuff.c:1167
  skb_release_all net/core/skbuff.c:1187 [inline]
  __kfree_skb net/core/skbuff.c:1203 [inline]
  sk_skb_reason_drop+0xc4/0x1b0 net/core/skbuff.c:1242
  kfree_skb_reason include/linux/skbuff.h:1330 [inline]
  kfree_skb include/linux/skbuff.h:1339 [inline]
  llc_rcv+0x4d5/0xa70 net/llc/llc_input.c:112
  __netif_receive_skb_one_core+0x1b2/0x1e0 net/core/dev.c:6451
  __netif_receive_skb+0x1f/0x120 net/core/dev.c:6564
  process_backlog+0x487/0x1600 net/core/dev.c:6915
  __napi_poll.constprop.0+0xaf/0x450 net/core/dev.c:8001
  napi_poll net/core/dev.c:8064 [inline]
  net_rx_action+0xa40/0xf20 net/core/dev.c:8221
  handle_softirqs+0x216/0xa20 kernel/softirq.c:669
  run_ksoftirqd kernel/softirq.c:1133 [inline]
  run_ksoftirqd+0x38/0x60 kernel/softirq.c:1125
  smpboot_thread_fn+0x41f/0xb90 kernel/smpboot.c:162
  kthread+0x373/0x450 kernel/kthread.c:436
  ret_from_fork+0x730/0xd60 arch/x86/kernel/process.c:158
  ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
irq event stamp: 2807
hardirqs last  enabled at (2807): [<ffffffff81d94222>] raw_spin_rq_unlock_irq kernel/sched/sched.h:1739 [inline]
hardirqs last  enabled at (2807): [<ffffffff81d94222>] finish_lock_switch kernel/sched/core.c:5315 [inline]
hardirqs last  enabled at (2807): [<ffffffff81d94222>] finish_task_switch.isra.0+0x2c2/0x10d0 kernel/sched/core.c:5433
hardirqs last disabled at (2806): [<ffffffff8bf2b378>] __schedule+0x2ec8/0x7de0 kernel/sched/core.c:7237
softirqs last  enabled at (2774): [<ffffffff81cbcddf>] do_softirq kernel/softirq.c:569 [inline]
softirqs last  enabled at (2774): [<ffffffff81cbcddf>] do_softirq+0xaf/0xf0 kernel/softirq.c:556
softirqs last disabled at (2221): [<ffffffff81cbcddf>] do_softirq kernel/softirq.c:569 [inline]
softirqs last disabled at (2221): [<ffffffff81cbcddf>] do_softirq+0xaf/0xf0 kernel/softirq.c:556

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

       CPU0
       ----
  lock(&r->consumer_lock#4);
  <Interrupt>
    lock(&r->consumer_lock#4);

 *** DEADLOCK ***

locks held by syz.0.18/6057: 0, on CPU#2

stack backtrace:
CPU: 2 UID: 0 PID: 6057 Comm: syz.0.18 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
 print_usage_bug.part.0+0x258/0x340 kernel/locking/lockdep.c:4086
 print_usage_bug kernel/locking/lockdep.c:4054 [inline]
 valid_state kernel/locking/lockdep.c:4100 [inline]
 mark_lock_irq kernel/locking/lockdep.c:4311 [inline]
 mark_lock+0x956/0x1020 kernel/locking/lockdep.c:4797
 mark_usage kernel/locking/lockdep.c:4710 [inline]
 __lock_acquire+0x8e2/0x1f40 kernel/locking/lockdep.c:5242
 lock_acquire kernel/locking/lockdep.c:5942 [inline]
 lock_acquire+0x1d1/0x380 kernel/locking/lockdep.c:5899
 __raw_spin_lock include/linux/spinlock_api_smp.h:190 [inline]
 _raw_spin_lock+0x2e/0x40 kernel/locking/spinlock.c:173
 spin_lock include/linux/spinlock.h:347 [inline]
 ptr_ring_consume include/linux/ptr_ring.h:363 [inline]
 ptr_ring_cleanup include/linux/ptr_ring.h:700 [inline]
 tap_sock_destruct+0x13b/0x330 drivers/net/tap.c:444
 __sk_destruct+0x85/0xb70 net/core/sock.c:2386
 sk_destruct+0xc8/0xf0 net/core/sock.c:2448
 __sk_free+0xf4/0x3e0 net/core/sock.c:2459
 sk_free+0x61/0x90 net/core/sock.c:2470
 sock_put include/net/sock.h:2024 [inline]
 tap_put_queue drivers/net/tap.c:179 [inline]
 tap_release+0x2fc/0x450 drivers/net/tap.c:517
 __fput+0x3fb/0xb50 fs/file_table.c:512
 fput_close_sync+0x118/0x250 fs/file_table.c:618
 filp_close_sync+0x75/0xa0 fs/open.c:1574
 __range_close+0x4a6/0x8b0 fs/file.c:919
 __do_sys_close_range fs/file.c:1003 [inline]
 __se_sys_close_range fs/file.c:954 [inline]
 __x64_sys_close_range+0x1f8/0x430 fs/file.c:954
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x7b0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f56833a9559
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 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 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffceb470b88 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4
RAX: ffffffffffffffda RBX: 00007ffceb470c70 RCX: 00007f56833a9559
RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003
RBP: 00000000000100ee R08: 0000000000000001 R09: 0000000000000000
R10: 0000001b30d20000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f5683625fac R14: 00007f5683625fa8 R15: 00007f5683625fa0
 </TASK>

Crashes (6):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/20 21:18 upstream 65e4fd942f72 625aa117 .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream inconsistent lock state in tap_sock_destruct
2026/11/20 20:56 upstream 65e4fd942f72 625aa117 .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream inconsistent lock state in tap_sock_destruct
2026/11/20 20:32 upstream 65e4fd942f72 625aa117 .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream inconsistent lock state in tap_sock_destruct
2026/11/22 09:05 upstream f802b6558eb8 b2c69459 .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream inconsistent lock state in tap_sock_destruct
2026/11/20 20:07 upstream 65e4fd942f72 625aa117 .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream inconsistent lock state in tap_sock_destruct
2026/11/22 19:26 linux-next 909ef7a9a30f b2c69459 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-rust-kasan-gce inconsistent lock state in tap_sock_destruct
* Struck through repros no longer work on HEAD.