🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Jun Yang Tue, 01 Dec 2026 11:27
Re: [PATCH net] wireguard: flush endpoint dst cache when a peer is removed
#25189
Author: Jun Yang
Date: Tue, 01 Dec 2026 11:27
47 lines
13095 bytes
Here is my proposed text for the commit message:

When a WireGuard device is moved to another network namespace, the 
endpoint_cache of a peer may still hold routes belonging to that 
original namespace.

peer_make_dead() removes a peer from wg->peer_list
but fails to clear peer->endpoint_cache. If a netlink query still holds a
reference to the peer, the peer remains alive, and its endpoint_cache may
continue to hold an IPv6 route (marked with the RTF_CACHE flag) from the
original namespace. When the original namespace exits, wg_netns_exit_rtnl()
only cleans up the endpoint_cache for peers still present in wg->peer_list.
Since the peer in question has already been removed from the list,
wg_netns_exit_rtnl() does not release its endpoint_cache reference to the
route. Subsequently, ip6_route_net_exit() destroys the IPv6 route counter
for the original namespace.

When the peer is eventually reclaimed, rcu_release() calls
dst_cache_destroy(&peer->endpoint_cache). dst_cache_destroy() invokes
dst_release(dst) for the cached route. If this is the final reference to
the dst object, dst_release() calls dst_count_dec()—attempting to decrement
the IPv6 route counter of the original namespace—which triggers a
Use-After-Free.

By acquiring the endpoint_lock (write lock) within peer_make_dead(), we can
mark the peer as is_dead and immediately clear its endpoint_cache. Any
ongoing send operations that already hold the read lock will complete, and
their newly cached routes will also be cleared. Subsequent send operations
that acquire the read lock will observe the is_dead flag and bypass the
cache. Thus, even if a netlink query retains a reference to the peer, the
peer’s endpoint_cache will have already released its references to the
routes.

If this text looks good to you, I will proceed to submit a v2 patch;
otherwise, I am happy to make further adjustments.

I previously sent you the PoC code privately—I am not sure if you received
it, but I can resend it if necessary.
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