From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.182 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== 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== 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 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 ; Tue, 1 Dec 2026 11:27:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8C26A606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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 Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2f04ad2c46dso69794905ad.2 for ; Tue, 01 Dec 2026 03:27:46 -0800 (PST) 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) 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) From: Jun Yang 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 Message-ID: <20261201112740.86971-1-juny24602@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: References: X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Here is my proposed text for the commit message:=0D =0D When a WireGuard device is moved to another network namespace, the =0D endpoint_cache of a peer may still hold routes belonging to that =0D original namespace.=0D =0D peer_make_dead() removes a peer from wg->peer_list=0D but fails to clear peer->endpoint_cache. If a netlink query still holds a=0D reference to the peer, the peer remains alive, and its endpoint_cache may=0D continue to hold an IPv6 route (marked with the RTF_CACHE flag) from the=0D original namespace. When the original namespace exits, wg_netns_exit_rtnl()= =0D only cleans up the endpoint_cache for peers still present in wg->peer_list.= =0D Since the peer in question has already been removed from the list,=0D wg_netns_exit_rtnl() does not release its endpoint_cache reference to the=0D route. Subsequently, ip6_route_net_exit() destroys the IPv6 route counter=0D for the original namespace.=0D =0D When the peer is eventually reclaimed, rcu_release() calls=0D dst_cache_destroy(&peer->endpoint_cache). dst_cache_destroy() invokes=0D dst_release(dst) for the cached route. If this is the final reference to=0D the dst object, dst_release() calls dst_count_dec()=E2=80=94attempting to d= ecrement=0D the IPv6 route counter of the original namespace=E2=80=94which triggers a=0D Use-After-Free.=0D =0D By acquiring the endpoint_lock (write lock) within peer_make_dead(), we can= =0D mark the peer as is_dead and immediately clear its endpoint_cache. Any=0D ongoing send operations that already hold the read lock will complete, and= =0D their newly cached routes will also be cleared. Subsequent send operations= =0D that acquire the read lock will observe the is_dead flag and bypass the=0D cache. Thus, even if a netlink query retains a reference to the peer, the=0D peer=E2=80=99s endpoint_cache will have already released its references to = the=0D routes.=0D =0D If this text looks good to you, I will proceed to submit a v2 patch;=0D otherwise, I am happy to make further adjustments.=0D =0D I previously sent you the PoC code privately=E2=80=94I am not sure if you r= eceived=0D it, but I can resend it if necessary.=0D