* [PATCH] net: tap: fix inconsistent lock state in tap_sock_destruct
@ 2026-11-26 0:34 Shuai Liu
2026-11-26 17:34 ` willemb
0 siblings, 1 reply; 2+ messages in thread
From: Shuai Liu @ 2026-11-26 0:34 UTC (permalink / raw)
To: willemdebruijn.kernel, jasowangio, andrew+netdev, davem, edumazet,
kuba, pabeni
Cc: syzbot+a2220efe757ca2a7358d, netdev, linux-kernel, Shuai Liu
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@syzkaller.appspotmail.com>
Link: https://syzkaller.appspot.com/bug?extid=a2220efe757ca2a7358d
Signed-off-by: Shuai Liu <847807867@qq.com>
---
drivers/net/tap.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 2f19fb07bb2d4..d749c7e73858a 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -440,8 +440,18 @@ static void tap_sock_write_space(struct sock *sk)
static void tap_sock_destruct(struct sock *sk)
{
struct tap_queue *q = container_of(sk, struct tap_queue, sk);
-
- ptr_ring_cleanup(&q->ring, __skb_array_destroy_skb);
+ unsigned long flags;
+ void *ptr;
+
+ while (true) {
+ spin_lock_irqsave(&q->ring.consumer_lock, flags);
+ ptr = __ptr_ring_consume(&q->ring);
+ spin_unlock_irqrestore(&q->ring.consumer_lock, flags);
+ if (!ptr)
+ break;
+ __skb_array_destroy_skb(ptr);
+ }
+ kvfree(q->ring.queue);
}
static int tap_open(struct inode *inode, struct file *file)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] net: tap: fix inconsistent lock state in tap_sock_destruct
2026-11-26 0:34 [PATCH] net: tap: fix inconsistent lock state in tap_sock_destruct Shuai Liu
@ 2026-11-26 17:34 ` willemb
0 siblings, 0 replies; 2+ messages in thread
From: willemb @ 2026-11-26 17:34 UTC (permalink / raw)
To: Shuai Liu, willemdebruijn.kernel, jasowangio, andrew+netdev,
davem, edumazet, kuba, pabeni
Cc: syzbot+a2220efe757ca2a7358d, netdev, linux-kernel, Shuai Liu
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@syzkaller.appspotmail.com>
> Link: https://syzkaller.appspot.com/bug?extid=a2220efe757ca2a7358d
> Signed-off-by: Shuai Liu <847807867@qq.com>
Dropped in line with your below comment, thanks
https://lore.kernel.org/netdev/tencent_21D314AEB4D8C2C489FB8D74348B93FC7706@qq.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-26 17:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 0:34 [PATCH] net: tap: fix inconsistent lock state in tap_sock_destruct Shuai Liu
2026-11-26 17:34 ` willemb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox