Article View: linux.kernel.netdev
Article #23802Re: [PATCH net v2 1/4] net: wait for RCU readers after flushing routes
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 06:42
Date: Sat, 28 Nov 2026 06:42
185 lines
14216 bytes
14216 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The new grace period runs too early, so the fix is incomplete.
- [Low] The Fixes: tag only names 4a6ce2b6f2ec ("net: introduce a new
function dst_dev_put()", 2017).
--
net: wait for RCU readers after flushing routes
This patch adds a synchronize_net() call to netdev_run_todo(), after
rt_flush_dev(NULL) and rt6_uncached_list_flush_dev(NULL). The goal is to
wait for RCU readers that loaded the old device from dst->dev before
dst_dev_put() dropped the last device reference, so the device is not
freed underneath them.
Link: https://lore.kernel.org/netdev/20261125190113.GA421469@shredder/
> Fixes: 4a6ce2b6f2ec ("net: introduce a new function dst_dev_put()")
[Severity: Low]
Should this also have Fixes tags for these two commits?
ca6854799069 ("ipv4: Batch rt_flush_dev() in netdev_run_todo().")
f12d2907992d ("ipv6: Batch rt6_uncached_list_flush_dev() in netdev_run_todo().")
Those commits added the block in netdev_run_todo() that this hunk changes:
rt_flush_dev(NULL);
rt6_uncached_list_flush_dev(NULL);
They also added the dev->dismantle early return. That return makes the
NETDEV_UNREGISTER-time flushes in fib_netdev_event() and rt6_disable_ip()
into no-ops.
Before those commits, both flushes ran from the NETDEV_UNREGISTER notifier.
The synchronize_net() in unregister_netdevice_many_notify() always followed
them, before net_set_todo():
net/core/dev.c:unregister_netdevice_many_notify() {
...
synchronize_net();
...
}
So the window in the first paragraph of the commit message seems to exist
only on top of the batching commits. The 2017 tag seems to apply only to
the RCU-callback case in the second paragraph.
With Cc: stable, the hunk will not apply to trees that lack the batching
commits. Those trees would also need the wait in a different place.
Could the tags and the commit message keep these two cases apart?
> diff --git a/net/core/dev.c b/net/core/dev.c
> index cd0796a1dbfdf..2a9d9a06ccb58 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -12039,6 +12039,7 @@ void netdev_run_todo(void)
> if (!list_empty(&list)) {
> rt_flush_dev(NULL);
> rt6_uncached_list_flush_dev(NULL);
> + synchronize_net();
> }
>
> cnt = 0;
[Severity: High]
Is this grace period late enough to cover every final device reference
drop?
It only covers references dropped before this point. Some RCU callbacks
can still call dst_dev_put() after synchronize_net() has returned.
dst_dev_put() drops the device reference right after the pointer swap:
net/core/dst.c:dst_dev_put() {
...
rcu_assign_pointer(dst->dev_rcu, blackhole_netdev);
netdev_ref_replace(dev, blackhole_netdev, &dst->dev_tracker,
GFP_ATOMIC);
...
}
The first path starts in the flush this patch targets.
rt6_uncached_list_flush_dev() calls fib6_info_release() on entries that
have fib6_destroying set:
net/ipv6/route.c:rt6_uncached_list_flush_dev() {
...
from = unrcu_pointer(xchg(&rt->from, NULL));
fib6_info_release(from);
...
}
If that drops the last fib6_ref, it queues
call_rcu_hurry(&f6i->rcu, fib6_info_destroy_rcu). This happens after the
first rcu_barrier() in netdev_run_todo(). The callback then runs:
fib6_info_destroy_rcu()
fib6_nh_release()
fib6_nh_release_dsts()
dst_dev_put(&pcpu_rt->dst)
It does this on the per-CPU routes of a fib6_nh on the dying device. Those
routes hold their real device reference until then, because
fib6_purge_rt() only drops their from reference.
The second path is a chained nexthop callback.
fib6_info_destroy_rcu() or free_fib_info_rcu() can run during the first
rcu_barrier() and call nexthop_put(). nexthop_put() then queues
call_rcu_hurry(&nh->rcu, nexthop_free_rcu) from inside that callback.
rcu_barrier() does not wait for the chained callback, which later runs:
nexthop_free_rcu()
nexthop_free_single()
fib6_nh_release()
fib6_nh_release_dsts()
dst_dev_put()
IPv4 has the same pattern through rt_fibinfo_free_cpus().
In both paths, a reader can enter RCU after synchronize_net() has started
and before the callback runs. That reader can still load the old device.
One example is ip6_dst_mtu_maybe_forward(), reached through dst_mtu() on a
socket's cached per-CPU dst:
include/net/ip6_route.h:ip6_dst_mtu_maybe_forward() {
...
rcu_read_lock();
idev = __in6_dev_get(dst_dev_rcu(dst));
...
}
netdev_wait_allrefs_any() returns as soon as the refcount reaches 1. On
the first pass wait is 0, so msleep() is skipped. The device can be
returned right after rcu_barrier() has run the callback:
net/core/dev.c:netdev_wait_allrefs_any() {
...
rcu_barrier();
if (!wait) {
wait = WAIT_REFS_MIN_MSECS;
} else {
msleep(wait);
...
}
netdev_run_todo() then moves straight to freeing the device, with no
grace period after the last reference drop:
netdev_do_free_pcpu_stats()
priv_destructor()
free_netdev()
kobject_put() -> netdev_release() -> kvfree(dev)
Can the reader still be running when kvfree(dev) is called?
Two later patches in this series depend on this grace period:
"ipv4: route: fix use-after-free in ipv4_confirm_neigh()"
"ipv6: route: fix use-after-free in ip6_confirm_neigh()"
Both say "The grace period added to netdev_run_todo() ensures that the
device remains alive until the read-side critical section finishes". No
later patch in the series changes net/core/.
Would it be better to wait for a grace period after
netdev_wait_allrefs_any() sees refcnt == 1 and before the free? That could
be a batched synchronize_net() at that point, or an RCU-deferred netdev
free. Either would replace the placement in this patch rather than add to
it.
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795754281.git.n0ps1edzz%40gmail.com
Technical Details
Message-ID:
<179584815675.3135.5910244068046256837@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373036-linux-kernel-netdev=dewy.ruReferences:
<f717d85edfc29966526f156ecfcf5b9dfca23fab.1795754281.git.n0ps1edzz@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373036-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2 1/4] net: wait for RCU readers after flushing routes Date: Sat, 28 Nov 2026 06:42:36 +0000 Organization: Usenet Network Message-ID: <179584815675.3135.5910244068046256837@kernel.org> References: <f717d85edfc29966526f156ecfcf5b9dfca23fab.1795754281.git.n0ps1edzz@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="898863"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:yQU9/+lx+sQSi+QPdZiAf03ydLY= sha256:IcjGTt/df0meZ+D6mYyMXQ4nP2LP9hGO7vxlAcJ/kmY= sha1:pigx4nz/SQH+6uKvGOFyUY401dE= sha256:Sw3k/Ql/dF7JvtmeXUZJy6gYb9LFtNa1F0zGZPtd1nk= 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 D8AFD125F72; Sat, 28 Nov 2026 09:42:53 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org 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 r02EmkNEgNvH; Sat, 28 Nov 2026 09:42:49 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373036-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 61FD4125F70; Sat, 28 Nov 2026 09:42:40 +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 4E1302BA30; Sat, 28 Nov 2026 06:42:39 +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=1795848159; b=AvZBBqsMO1Kvwcj91tBQ7gp+NbYOlZtIt9VZlaz+PApciXnd7W9BntB0iXSxyfnOaXuh ixL38fS5YFuaHLAxPuxTf8Ve58uvAB/4JTX2g2KEVVt5PezADQHExc+UC7rVnFGDIGgbH c3JFumE1BP9chn6qPkvz3fFD9GjPuQ9qn2NGes6rEMPfuVDUw0mpDVdOceLLIuNcqFtAo q8wLFmLYHcNPuhMEI3UnjDvM5840MAUYJKfIc/HfzaUNs689lxOH/1PTeGhQIzi1QJj3x aoDNTMuNWylh/Hsnk8oX6CNTacuAW9n36WdrtzQ9tTiGsIXogXe8zPlbK0cJ7EYg/LA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795848159; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=/46tpLCHBarOr1nJSSNpTCgNB/+AZxC0310uNX9POUA=; b=cM1k+H9U/eC+Wx0ypnQUm5lCs7Xkbz/M+0P7whRgswBCHcAVNiLdk6brBk2Y3r1A0JpJ khKQg8d4BwBPDf52L8VMKhYr/B7H/0S7OV6IOQPOPHadb3G1JJk3dOVndwolKUwhhJvh5 IF/hq6jshIFaRGZgvh8oP5/tiP3TZ5JONVrwJNfNyDpsgkMfVUO34Emui5cyzDJuO6CM2 9zprP9MGcKA3LRmf6w0ckpUdSZYkeDUtz3NcTHyrfPfaOPYO2d68PjEmgSU8902AKBb5f yixXLWywpKlPTpO5it2axNUCa+ytx22ngaT8kDKsu0YGAsCXVYh5JfAaG7nqWQSo6gw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ztc4I4Fm; 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 25629606A326; Sat, 28 Nov 2026 06:42:39 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ztc4I4Fm X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795848158; b=3UylBLcpr3N2dSrGcpUb2e+K/3xMwtC8k1ckMAHi8jQ6Z1pEAdfclv543rprZpAHs8ub X9FhbnOS0fREPu3WiHcp7p+O3sIvAD/dE2KQhr5kCRVbn3pDtOco7LxrL+YJAlOfJVAPA iTh3vVOSheFTed9jdSjvKexTQzkEdwLpR2P+h4xBUnKaVyJwNdVKrfPTrRX8LThFobWB0 /I5MGAUyhpmNGwqk61k1fFLOC9f98HdGJr1PiPO3unFraX5fyRoC/h+0LzdYWiga+OSwb /rWSVzBiPhRlrsosklDY9TrrNncgkq1scpnF7282kQNmx+NI2Ns0KHkZXA5WK9d6U9w== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795848158; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=/46tpLCHBarOr1nJSSNpTCgNB/+AZxC0310uNX9POUA=; b=URVz7xXcG973YIrpvZjuUsJHuB2jNTVIAPbKM/CBA6tZohqk3yZ2i3Z+B8SyBuSeSvct RAzYLAofq7KsjvRLo3EWLaDq0o/l0tJPJP8PO2WYD8arOucbVH1lgsf9h7D0H4FT1KHpz qhky9uHTTjOi38RH/OjC94+dURoTstRXO8Q97jTO8oNEgyx9fdnO98fDb7hoQ97pqRkIn YDIGJeULjKB+VWkWQGDVi8Kbndv8rNPlrppc5WykntjIjiJs89r4eDLnYq6WaF4VI1six F4mHUv6HJKox4PezOiceOX79x5EOtdnWV8aSozJXXUsBhgn7U1sNawSHShQOWfqCbBA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ztc4I4Fm; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41815606A31C for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 06:42:38 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39FA21F000C1; Sat, 28 Nov 2026 06:42:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795848157; bh=/46tpLCHBarOr1nJSSNpTCgNB/+AZxC0310uNX9POUA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Ztc4I4FmnXm5ScpkHFSIsKgpKxP/NrNpSrWIwZ282k1Uni4G6WBRyvANUyXRVnu2f Jps8XaVe3KYu0Ggx1ddHBWQTgFOXDCbZGqtEPVSKwN0U9Hmqgm/z+8OKpi+5nKVqmI c6mJ7Xib6sGnL68T0DsRgG5N4vmZQFtFnxRdQgW0beVHCVCkxhOiH6TY9P/NGwmpam YO1YHETR+uhwkt3lraWCRE+apF69jFgqzd6pRaFUBV6xDl45TLd3p9Ch6MfSLrjCFJ DgiSSpAUT075ipUwvl0X7j7syXd1pn1pSnuwOv/2KYSeeGg9CYIB+Ddc7gd+7afP5/ 9Famf4BBre64g== X-Cc: netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, willemb@google.com, kuniyu@google.com, hangbin.liu@linux.dev X-In-Reply-To: <f717d85edfc29966526f156ecfcf5b9dfca23fab.1795754281.git.n0ps1edzz@gmail.com> X-sashiko-severity: High 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