Re: [PATCH] net: tap: fix inconsistent lock state in tap_sock_destruct
From: willemb
Date: Thu Nov 26 2026 - 12:34:34 EST
Shuai Liu wrote:
tap_sock_destruct() calls ptr_ring_cleanup(), which in turn uses
ptr_ring_consume() with a plain spin_lock() for consumer_lock.
This destructor runs in two distinct contexts:
1. softirq context: from softirq rx drop paths via
skb_release_head_state() -> sock_wfree() -> __sk_free() ->
sk_destruct() -> tap_sock_destruct(). In softirq the BH
state is already disabled, so consumer_lock is taken with
SOFTIRQ-ON-W semantics.
2. process context: from tap_release() -> __fput() -> sk_free()
-> sk_destruct() -> tap_sock_destruct() (triggered by
close_range syscall). Here softirq is enabled when the
same consumer_lock is taken.
lockdep flags this as inconsistent {IN-SOFTIRQ-W} ->
{SOFTIRQ-ON-W} usage of (&r->consumer_lock) and warns about
a possible deadlock scenario.
Fix by hand-rolling the cleanup loop with spin_lock_irqsave() /
spin_unlock_irqrestore() so consumer_lock is always taken from a
uniform softirq state. irqsave is a no-op on the softirq path
(interrupts are already off), so there is no extra cost there.
Reported-by: syzbot <syzbot+a2220efe757ca2a7358d@xxxxxxxxxxxxxxxxxxxxxxxxx>
Link: https://syzkaller.appspot.com/bug?extid=a2220efe757ca2a7358d
Signed-off-by: Shuai Liu <847807867@xxxxxx>
Dropped in line with your below comment, thanks
https://lore.kernel.org/netdev/tencent_21D314AEB4D8C2C489FB8D74348B93FC7706@xxxxxx/