Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Nguyen Ngoc Thang
Sun, 29 Nov 2026 15:59
[PATCH net] tap: don't take consumer_lock in tap_sock_destruct()
Author: Nguyen Ngoc Thang
Date: Sun, 29 Nov 2026 15:59
Date: Sun, 29 Nov 2026 15:59
63 lines
13425 bytes
13425 bytes
tap_sock_destruct() runs when the last reference to the queue socket
is dropped. That is not necessarily tap_release(): skbs written to the
tap fd are charged to the socket, so the final sock_put() can come
from sock_wfree() anywhere in the transmit path, with BH disabled and
arbitrary locks held.
syzbot hit this with a macvtap -> veth -> mirred -> wireguard setup.
The wireguard tx worker sends the encrypted skb to a loopback endpoint
while holding peer->endpoint_lock (SOFTIRQ-safe). loopback_xmit()
orphans the skb, the tap socket goes away, and ptr_ring_cleanup()
takes q->ring.consumer_lock, which is SOFTIRQ-unsafe:
WARNING: SOFTIRQ-safe -> SOFTIRQ-unsafe lock order detected
...
tap_sock_destruct+0x40/0x3f8 drivers/net/tap.c:444
__sk_free+0x264/0x328 net/core/sock.c:2459
sock_wfree+0x234/0x6fc net/core/sock.c
loopback_xmit+0x144/0x6cc drivers/net/loopback.c:81
...
send4+0x8cc/0xcf4 drivers/net/wireguard/socket.c:85
wg_socket_send_skb_to_peer+0xc0/0x19c drivers/net/wireguard/socket.c:174
wg_packet_tx_worker+0x188/0x75c drivers/net/wireguard/send.c:276
The lock is not needed there. The refcount is zero and tap_put_queue()
has already unpublished the queue and waited for an RCU grace period,
so neither tap_handle_frame() nor a reader can touch the ring anymore.
Drain it with __ptr_ring_consume() and free it without locking.
Fixes: 362899b8725b ("macvtap: switch to use skb array")
Reported-by: syzbot+fc3b1b923a16043b9d3c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=fc3b1b923a16043b9d3c
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
---
Tested in QEMU (x86_64, PROVE_LOCKING) with the syzbot C reproducer:
without the patch the lockdep splat fires on the first run; with it,
3 boots x 3 reproducer runs are clean and debug_locks stays 1.
drivers/net/tap.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 2f19fb07bb2d4..bcb37679c5a1f 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -440,8 +440,14 @@ 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);
+ struct sk_buff *skb;
- ptr_ring_cleanup(&q->ring, __skb_array_destroy_skb);
+ /* Last reference is gone and the ring is private. This may run from
+ * sock_wfree() in the xmit path, so don't take consumer_lock.
+ */
+ while ((skb = __ptr_ring_consume(&q->ring)))
+ kfree_skb(skb);
+ ptr_ring_cleanup(&q->ring, NULL);
}
static int tap_open(struct inode *inode, struct file *file)
--
2.43.0
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads