[PATCH net v3 0/2] wireguard: free receive queue packets on peer removal, and test it
From: Andrii Pasichnyk
Date: Fri Nov 27 2026 - 05:22:59 EST
Removing a peer while its receive queue is busy can leave packets on
the per-peer receive queue. Each of them holds a keypair and a peer
reference, so the peer and the keypair are never freed. Patch 1 frees
what is left; patch 2 adds the test Jason asked for in the v1 thread to
netns.sh.
Tested on net e9e45fcb6 with the WireGuard selftest VM (x86_64 KVM):
both patches, 4 vCPUs: pass
both patches, NR_CPUS=1: pass
both patches, NR_CPUS=1, 200 removals: pass, nothing leaked
patch 2 only, NR_CPUS=1: fail, a peer and a keypair
"merely created"
Changes in v3:
- Patch 1: purge rx_queue only. The tx_queue purge in v2 could run
beside a transmit_packet_work that was queued during the second
flush, as the Sashiko review pointed out, and it was not needed: the
leak is on rx_queue. The older comment in peer_remove_after_dead() is
updated, the subject follows, and the commit message says how the bug
was found.
- Patch 2: CONFIG_LOG_BUF_SHIFT is 21 instead of 20, which covers the
worst case of the loop; the commit message says that NR_CPUS=1 is the
configuration that checks for the leak.
- Rebased on current net.
v2: https://lore.kernel.org/netdev/20261126094722.73025-1-apasichnik9@xxxxxxxxx/
v1: https://lore.kernel.org/netdev/20261003201625.4572-1-apasichnik9@xxxxxxxxx/
Andrii Pasichnyk (2):
wireguard: peer: free packets left on the receive queue on removal
wireguard: selftests: remove a peer under load
drivers/net/wireguard/peer.c | 25 +++++++++++++++++--
tools/testing/selftests/wireguard/netns.sh | 14 +++++++++++
.../selftests/wireguard/qemu/kernel.config | 2 +-
3 files changed, 38 insertions(+), 3 deletions(-)
base-commit: e9e45fcb6d39bee9325e6a7dca72bd14e82760f3
--
2.43.0