Netdev List
 help / color / mirror / Atom feed
From: Jun Yang <juny24602@gmail.com>
To: jason@zx2c4.com
Cc: andrew+netdev@lunn.ch, corvus@tencent.com, davem@davemloft.net,
	edumazet@kernel.org, junvyyang@tencent.com, juny24602@gmail.com,
	kuba@kernel.org, netdev@vger.kernel.org, pabeni@redhat.com,
	stable@kernel.org, wireguard@lists.zx2c4.com
Subject: Re: [PATCH net] wireguard: flush endpoint dst cache when a peer is removed
Date: Tue,  1 Dec 2026 19:27:39 +0800	[thread overview]
Message-ID: <20261201112740.86971-1-juny24602@gmail.com> (raw)
In-Reply-To: <avNM0VAw0fpqzpgv@zx2c4.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2075 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.

      reply	other threads:[~2026-12-01 11:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06  8:15 [PATCH net] wireguard: flush endpoint dst cache when a peer is removed Jun Yang
2026-11-10 16:56 ` Jason A. Donenfeld
2026-12-01 11:27   ` Jun Yang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201112740.86971-1-juny24602@gmail.com \
    --to=juny24602@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=corvus@tencent.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jason@zx2c4.com \
    --cc=junvyyang@tencent.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@kernel.org \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox