Article View: linux.kernel.netdev
Article #25189Re: [PATCH net] wireguard: flush endpoint dst cache when a peer is removed
From: Jun Yang
Date: Tue, 01 Dec 2026 11:27
Date: Tue, 01 Dec 2026 11:27
47 lines
13095 bytes
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.
Technical Details
Message-ID:
<20261201112740.86971-1-juny24602@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374974-linux-kernel-netdev=dewy.ruReferences:
<avNM0VAw0fpqzpgv@zx2c4.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374974-linux-kernel-netdev=dewy.ru
From: juny24602@gmail.com (Jun Yang)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] wireguard: flush endpoint dst cache when a peer is removed
Date: Tue, 1 Dec 2026 19:27:39 +0800
Organization: Usenet Network
Message-ID: <20261201112740.86971-1-juny24602@gmail.com>
References: <avNM0VAw0fpqzpgv@zx2c4.com>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1696218"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qYRT1pZl9ZrO/y4saBE+/ZcgUuM= sha256:eZDjgsuC30s7+AlxjyGTzHtBPqZ5C8RDG/yVit8nHOo=
sha1:BpjFT0tjIKlmannIAsdxqmsAhD4= sha256:wn/O2nESZonQoKbVPCcJWz2eRtTv4gHy4q6f2joVhTQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 2D2EC117347; Tue, 1 Dec 2026 14:28:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id nv2QiRrV-z-q;
Tue, 1 Dec 2026 14:28:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374974-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 1A5731172FF; Tue, 1 Dec 2026 14:28:09 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id E5E6832659; Tue, 1 Dec 2026 11:27:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796124467;
b=V///GZCee1BDv515zzsn9pK5eQ4Xcjf9kJY/dHn83L+VDuDtviYxXQ3uGAFAq2sdIKZG
SO6InvAd9pvJd98x4pIjR8NYAfD82i5iKQlN2oQpdmVJ8Atco74yHLE4EsQ/6NkfjQaGg
ATZjmCVaNguv5MMi3NjZ786+jLuuAvvay6aLv7wAjhS8hsjg8DiOiSKd6Z3CiVq+mNpkw
OfNdodAF+4R+shjixnfaJPBTxd+c4pzaalKBx9CFm95tEPvRmfnVT4ksHmzShQTyGK2c8
oy+OI1qJ17cw/WDGCMiXJV9C849Xrv5riZHgn0EeTdS2l7MQ5y3vnmQd4p/+bH00rHQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796124467;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
MIME-Version:Content-Transfer-Encoding;
bh=e9inus4CRKx1qiSksmJgjEGmDydFux2Zeo05B04O3Gs=;
b=nAegAKHMbIIWBZB2fvclnmwUuqwWdSbdt9njtLLRPP3FUdarA8GuFZVGdKHkEqfqjc35
Kq7ZWR9npnXQa1IyOlQE3HxAW/RBpEbOA5n8+1wRZjTIjejBqi6Ds9dViNM/HqwMbVlzn
udrCmzLa7N3+VP/Zp474KRtS8OHyhr+oFZcsP6MrzC8TqqGwA3HQFd/j614iqbG4+nKPH
6FRsYHndxOZhEf5JqPYVby3NVeZqOWOUMKC7g4HILvcQsYTLDTqzBRXUTJPDAXHXjHbDB
Niv7Onbzv5Tsb4jQZZrbPlJ52rVzvrqsGvuwHjDdL0RGM7mAB6VyTBGl9r6bS5xcd+g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=A0r6IqGy;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id BC283606A32D;
Tue, 1 Dec 2026 11:27:47 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=A0r6IqGy
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.182
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796124466;
b=fdpuIK7P+9tGscZo+ZcILGRu/izXPh75Gp0yWkZynlr/lzbpriFsWiHpiIRxCYi/lWMU
w8B6yYkhVNfd3+7tgMA78hflhuOc8jG5sAA0gkMdct0DrPvtB6mnmtLa1ZGQjo7RQ/rl7
0XvTima2almh1tWSICUKHJVF2Q5rYoarLG2m7J9s6CGwyT1vOBZXRqU6OxniB03W75nJX
kdoK29enh+GrKSoYerRBHs8g/8tMBvP+HOxRaeOLu4kAYauFHvP61j+WjP+OL9zV04rRf
RJzH5LeKx3KBxI+toyOG8wvsbNFvbxlCP4ZE1kr5ottSqVJ6NLXcEUHMb95NrEYMwNg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796124466;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
MIME-Version:Content-Transfer-Encoding;
bh=e9inus4CRKx1qiSksmJgjEGmDydFux2Zeo05B04O3Gs=;
b=TdyXv0DipRn/n+Biz3SimoA/5Pfju/mw/nqU0ST+ao8zaFn0F4WzRyOSOBstMkjnVoTf
kU0IRw21xl+gZR3CLdm0dlJ+0SSPmUJbv9tNqhCr7JJQA0HujNYLz/VgMH+cq/XHtRKWg
McuH+1UXxNqaTLyfYnFWhH8LM8DijE8VeHO22W7ucuQc8yEjVnIi2SaN9uY6S56q/SQ62
Wm4YcZTOx0bZSIiBkBaNt1WLMyoF6HjDJUES/sMvZMYPqdUg2Q1bgKYQAzdfIV9kdcQVj
UHnAi9GWeuyfxMxavh8PmC9bd66oCP1qAguFHfmJg3c9Yc4fDT9yglizieF8RMuYUag==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=A0r6IqGy;
arc=none smtp.remote-ip=209.85.214.182
X-Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C26A606A31A
for <netdev@vger.kernel.org>; Tue, 1 Dec 2026 11:27:46 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8C26A606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2f04ad2c46dso69794905ad.2
for <netdev@vger.kernel.org>; Tue, 01 Dec 2026 03:27:46 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796124466; x=1796729266; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=e9inus4CRKx1qiSksmJgjEGmDydFux2Zeo05B04O3Gs=;
b=A0r6IqGyp8tvtb/mzNXBG+e7YhTAFYuA0dpFToK//NLXCC+/AZhzUUrjl5XZjjlRNc
nIcdfHnlI8Ga2fnaRQE6r/3HaMytTyUx7KyqwY1csbVhatDbGkTwZWAGAYzRLVH7s194
0FZqpMYinUs+LQ2jOoO1V4xDdFr6C8Q6+18N6gcCw9TLNnSE/IxSKcvJJG4BNMffaHSE
x/nif22vFNsuy0NBns4hTT6oMfNucvlOR0lSiy7Op6FgU54Q1U+1KxinoD6NnCpRRzbc
yhUCisOohmvoWzJQdXdzORZCN1xtTqxhAymKkcbDLZC/mGoRCM4Wu1UyA2+L+Q8BduJ+
Rd2w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796124466; x=1796729266;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=e9inus4CRKx1qiSksmJgjEGmDydFux2Zeo05B04O3Gs=;
b=Q4V4J5U5la4pOji4ml5/BFLNHfvEJhJeqt/C/hAkF3/Kydizm0baUcLMXNnXgGcmnP
yCGP40z8GnD1AEMwS66OeFdRd5ey7754n4SpdSLzT6Padc171Yz/FixPd5Bx0KVS5Prs
5bEEnWGhtt0I2PlS/W8fhkIzWL+G07Yct8dz5lg9c0is9HcH4FaFkXyX9VyPtLOKNqzr
IAKidWiocdLjLD7+Ommz6QifLneYmHGVZy9fhBywM++ODtVIXsKMPEjxizvNcMLC0rgm
DKW/7CCuGB+aZCm/yv3ZDFjm1OafgMW9JYGDiL6SKkHAVVC6Px12/L+I4fsp57hJ/bfy
s6zQ==
X-Forwarded-Encrypted: i=1; AL+hErFmaqK/kEta2odEC420m0K4zoYwYLBhmzCwvgoakkv44waHxIjDBe++Sla7adr+7HywGrbnq78=@vger.kernel.org
X-Gm-Message-State: APuU4Z9sPstRlv5zmkAscuuSbSODYCH1m/TXmnuVkwHLT+OJDR4EnwbN
lVeDbygkS2Uk0DRwvGs1PqwgC+7CSUUEl09AgPnK6IRu15kFYBcxphEG
X-Gm-Gg: AZFdTZd3QJn6kxZynDal4LbJ4Jo2TFen0OSA4NUPn2qLZGe18eIAmdkDqNx7hnNaMV3
WgzsIGvBGA4nyKVpZOZ5Hd5e8bYeh1y8l7CEECUs4MOVAj9kz9q5gp8R3KEV0rXoDA3zX9Ce06h
o1gQX0vVkxLEHKuazhI7Y7/J4b8mKjmUwq0wLeTO0PPxDpR8UKd0eTduqUkpqNoBWW5CRZPqdbk
4qG5+kEzLfFGphh44rAksYIV67OKai/8m+z9FIB1zfNGMdm+TvNEeENM9v+BjVc+lPnc7cK2iXH
TksT11qonSJ8zSg/n1LA5Vq6+QKmTvRRBy4TKqsNmzsy5fikxk6PFEGjlEQIi/40yC9PDs+oM3/
bvG4lgG43zxAsuYfMmb+IFqjmSvNkCbIVcpcwuBEoHcGDaIyxCa2owflc2K4g/konxkBVB2CLrW
7dT/4cJobG5fguT5Tive+Xo4yWqDz4xD1JRu17vVWVgDoHGXJv+6PK2jX6QEXGza/iqFz80mbMH
08P4KzqSfoeeMZwMp//54XGjaaBNzfO4TNkJ6xQkdFxIm9oQUftcGWWjwvezOjvohhtBiOW/nx7
s9Q6P/SUZld0VR8JXZz7+O724SGBXuzhOtMUbXCrXvlU1rdGDk2j6LuGqMEwHkw0BxumIFdEOtK
XpGqBpoz6y8fv
X-Received: by 2002:a17:903:3250:b0:2ef:e59b:f562 with SMTP id d9443c01a7336-2f03f203247mr432232485ad.58.1796124465403;
Tue, 01 Dec 2026 03:27:45 -0800 (PST)
X-Received: from JUNVYYANG-MC1.tencent.com ([43.132.141.24])
by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f1215d7sm178134825ad.65.2026.12.01.03.27.42
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Tue, 01 Dec 2026 03:27:44 -0800 (PST)
X-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
X-Mailer: git-send-email 2.54.0
X-In-Reply-To: <avNM0VAw0fpqzpgv@zx2c4.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list