🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5842

Re: [PATCH net-next v2 1/3] ipv4: draw rt_genid from a sequence shared by all netns

#5842
From: netdev-bot+sashiko
Date: Wed, 21 Oct 2026 02:44
137 lines
13109 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · 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).

- [Medium] The commit says "a cached route never matches the rt_genid of
  the netns its device moves to".
- [Low] The comment added above rt_genid_seq in net/ipv4/route.c, and the
  commit message, say each netns "bumps on NETDEV_UP before any of its…

--

ipv4: draw rt_genid from a sequence shared by all netns

This commit stops incrementing rt_genid separately in each netns. Instead,
every bump takes its value from one global sequence that never returns 0.
The goal is that a route cached through a device can never match the
rt_genid of the netns the device moves into.

> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index 595a3b7f17830..25bebbb30bf3c 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -393,6 +393,26 @@ static inline int ip_rt_proc_init(void)
>  }
>  #endif /* CONFIG_PROC_FS */
>  
> +/*
> + * Draw rt_genid bumps from one sequence shared by all netns. A route keeps
> + * the genid of the netns it was created in, and is checked against the netns
> + * its device is in now, so distinct values make that check fail once the
> + * device has moved. Every netns starts at 0, which the sequence never hands
> + * out, and bumps on NETDEV_UP before any of its devices can carry traffic.
> + */

[Severity: Low]
Is the last sentence of this comment accurate? The commit message makes
the same claim:

  "A netns bumps its rt_genid on NETDEV_UP before its devices can carry
  traffic"

In net/core/dev.c, __dev_open() marks the device up and activates it
before any notifier runs:

    netif_set_up(dev, true);
    dev_set_rx_mode(dev);
    dev_activate(dev);

netif_open() only sends NETDEV_UP after __dev_open() has returned:

    rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP | IFF_RUNNING, GFP_KERNEL, 0, NULL);
    call_netdevice_notifiers(NETDEV_UP, dev);

So rt_cache_flush() in fib_netdev_event() runs after the device can
already transmit.

The NETDEV_UP bump also doesn't always happen. For a device with no
in_device, for example one whose MTU is too small for IPv4,
fib_netdev_event() returns early:

    in_dev = __in_dev_get_rtnl(dev);
    if (!in_dev)
        return NOTIFY_DONE;

The nonzero genid on cached routes seems to come from the FIB insertion
paths instead, such as fib_table_insert()->rt_cache_flush() and the
NETDEV_UP case of fib_inetaddr_event().

The next patch in the series, "net: remove rcu_barrier() from
__dev_change_net_namespace()", depends on this invariant. Could the
comment and the commit message describe the ordering that actually holds?

> +static atomic_t rt_genid_seq;
> +
> +void rt_genid_bump_ipv4(struct net *net)
> +{
> +	int genid;
> +
> +	do {
> +		genid = atomic_inc_return(&rt_genid_seq);
> +	} while (!genid);
> +	atomic_set(&net->ipv4.rt_genid, genid);
> +}

[Severity: Medium]
The commit message says:

  "so a cached route never matches the rt_genid of the netns its device
  moves to."

Doesn't that only hold modulo 2^32? rt_genid_seq is one 32-bit atomic_t
shared by every netns, and rtable::rt_genid is an int. The loop only
skips 0, so values start repeating after 2^32 - 1 bumps.

Anyone who can create a user namespace and a netns can advance the
shared counter by writing /proc/sys/net/ipv4/route/flush. Each write
makes ipv4_sysctl_rtcache_flush() call rt_cache_flush(), and
sysctl_route_net_init() keeps the flush entry for netns owned by non-init
user namespaces:

    /* Don't export non-whitelisted sysctls to unprivileged users */
    if (net->user_ns != &init_user_ns) {
        if (tbl[0].procname != ipv4_route_flush_procname)
            table_size = 0;
    }

Suppose a route is cached in netns A with genid X, and its device then
moves to netns B. If B's genid equals X before
free_fib_info_rcu()->nexthop_free_rcu() gets to dst_dev_put(), the check
in rt_is_expired() passes:

    res = rth->rt_genid != rt_genid_ipv4(dev_net_rcu(rth->dst.dev));

ipv4_dst_check() then accepts the dst, and the socket in A keeps sending
through a device that B now owns.

This is hard to hit, because B's bump has to land on the unknown X
within a few RCU grace periods. However, the follow-up patch "net: remove
rcu_barrier() from __dev_change_net_namespace()" removes the barrier. It
then relies on genid uniqueness alone to reject every FIB-cached route
through the moved device, not just routes that use nexthop objects.

Would an approach that doesn't depend on a wrapping 32-bit value work
here? For example, the move could invalidate the cached dsts, or call
dst_dev_put() on them, synchronously. Another option would be to check
the netns the route was created in.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261019-bug-net-netns-move-rcu-barrier-v2-0-b6eb7780c492%40gmail.com
Technical Details
Message-ID: <179255064227.3135.1573234159062930165@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349730-linux-kernel-netdev=dewy.ru
References: <20261019-bug-net-netns-move-rcu-barrier-v2-1-b6eb7780c492@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-349730-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v2 1/3] ipv4: draw rt_genid from a sequence
 shared by all netns
Date: Wed, 21 Oct 2026 02:44:02 +0000
Organization: Usenet Network
Message-ID: <179255064227.3135.1573234159062930165@kernel.org>
References: <20261019-bug-net-netns-move-rcu-barrier-v2-1-b6eb7780c492@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4020734"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:01wJPEd51iRNVT+pt/UaWJ4WDqk= sha256:yoOBKy+myzn5haHx46uG1Y0ygmD7efJ749bj2SRnNKk=
	sha1:AVVBuMZEXI9BC0bSYe2OCImFws4= sha256:h0cGb8LavKfX2wrcaTM+rMqjmTrLGCVLqspew2e4Ey4=
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 C458B110EEC; Wed, 21 Oct 2026 05:44:20 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.828
X-Spam-Status: No, score=-3.828 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.329, 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,
	URIBL_BLOCKED=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 9G-igTYlXfnL;
	Wed, 21 Oct 2026 05:44:17 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-349730-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id A8A63110EEB; Wed, 21 Oct 2026 05:44:08 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 97C57605F92; Wed, 21 Oct 2026 02:44:06 +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=1792550645;
	b=muIDhz3PH6q/AJiyCBRReRaSNUgY4nMwQ3klqLyyNejJiqMmFmVJGSvyJ6O3yzHR73PR
	 L657VxDGwUE5/TikfY9rZTGfmnpzhx14S7ORRZzlzZPjgqXRP811u27kpPX+AXxQ5WtzC
	 DH0lid+a3GwB1ctqvLNmuJ5ZY+ubLfZXG6qfhjNLkx+BgaKq0qDnxKYTYl5f2mIR8rSOF
	 fsrrBJBGMqj51nKzTPUABixsBcLVdTLVRcFU0vZe8GhynD3ZpIFxJ8diHL1a+n5BSQqQy
	 MKShn83TPphVbeuhkPD1ssXtWY32Wysou9nMKGaXKVj8VTgPtAO30UCztmnxmbucH1g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792550645;
	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=pvMWMt14YWUTlKsuuOS9brN/+GEAU/YOCzBR9QabAX4=;
	b=lzJ6TqRXXCiy6tcP984NBp27aMhWjnQOOS7dN2pbljRXgNYtAlk2w12VzC9mjnyAlhsv
	 qz4nLfM+BPptREgF+nnW6BIfBGGItHQH0EDONl32SbUcnX4rxfP8D0HsRmkiUVzquYzdS
	 wSHukj4nkSHvQWrcU3lYI9eLiyfccKNFY5CVESuCz3hFjyxcSrfodaE9MO0sT0Xjz2JdT
	 hq8NrA0ZQepy4vOq9Qp+L+I7ZL9knBQixEF3zSWTxxzH5SznMV+XO7vxpBZisF0TRnTp1
	 NGj5VM3KvomlVMNiUpsDTuRBhh6zfdOtV0X7fnM44TUJrUhwMWhVE48ZlGBI4PNlrRQ==
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=ZGSIizvr;
	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 24C84606A323;
	Wed, 21 Oct 2026 02:44:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZGSIizvr
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=1792550644;
	b=wI+0UAmZStJFWPE8aEWItUur1tQSxc+rkK74hp1+/oWl8rneNyfBC5K3KwMnq9RIziTB
	 PjsQQ1v65d8ORb1uhCOasTcfygk4D4b7OcwBDpaAg62rMrgA96bt9749FAzsuOEKmqIDu
	 O/8hCqThMChfVGyCiE/cAprQPZ+/fhCkwLopqkkmQs3YXRY8h1iDVeOl0kK1zvr5aRHns
	 mY+sWuQvYH66+4zuYL+pQULpHk0LvX3jtVJTTg38IRBNFT4rxhSqJwqhahtlzIlLLU1FJ
	 1PTONI3YWRTZtBiKTA+ce+DgZHUNdpdfTt3DNiYNOrtib1FAkb90Vky9/0dKP8X5xGg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792550644;
	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=pvMWMt14YWUTlKsuuOS9brN/+GEAU/YOCzBR9QabAX4=;
	b=OvTpfWmDbisnPz8Z7HgnaB4D35JvY1HVmSM2/Owvp8QKinTM3kt1eIUh7pXxYhBiB/nK
	 eJpIHU62oYoKnk3LR7xcm2AID0vnj1d57/nTLHN0i8bSUnid7fWO0ErR5OTOrQmV/zAnq
	 CvWqgVbHjEH3cb8PCVlClw+4x1o+tyklqwPoUVhZj72ETY4M7Qlmmfa4RoRVOhk72sYff
	 qDaO1mxoNuEVz7Y7uBfMy0Ur0C41hywdq4DEf+b1xFTSBdgWHzFeTmRI8OzZSgUrT+oT4
	 3LcS5s1D0bdp1yxzJnhphi9Z3VXSC4JvMyCCyI/RiCy2XeZ9nN+OUdTNFpmnsBBqsWw==
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=ZGSIizvr;
	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 DB66B606A319;
	Wed, 21 Oct 2026 02:44:03 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C551A1F000C9;
	Wed, 21 Oct 2026 02:44:02 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792550643;
	bh=pvMWMt14YWUTlKsuuOS9brN/+GEAU/YOCzBR9QabAX4=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=ZGSIizvrzRcR8g52cd07DadGtP30s08v0SHHDCS+XW0/Z3Ji0Wa2r5kr8/Xyrez4M
	 OUtPtEj+d0ce+PFUlgTrxmeVdjK8l8/huauA2YLOfaWiL1vfrgf+pfh0pBz9Im3NCp
	 GCQwTVGeaqoMabJ3f4KwVgNEOPbwJXQKY5rvTTvX8YVa6ljW36GkFv3Z9e3vWHromK
	 XObt7QWJxEqp993lhMfTVj2ezDQXtzQoaPIHYZIvj5ORfbxaB4WFWap/V9djHNE1Cf
	 BqDV/TmflGKAawHB0d5Ek0QlaAUPsrDT1L7WuceYL6d8jiURygADSoOeTe9xQjhxhw
	 pOO8Pk703erFw==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, horms@kernel.org, dsahern@kernel.org, idosch@nvidia.com,
 razor@blackwall.org, kuniyu@google.com, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To:  <20261019-bug-net-netns-move-rcu-barrier-v2-1-b6eb7780c492@gmail.com>
X-sashiko-severity: Medium
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