๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23803

Re: [PATCH net v2 2/4] ipv4: route: fix use-after-free in ipv4_confirm_neigh()

#23803
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 06:42
116 lines
12516 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 0

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 fix makes ipv4_confirm_neigh() (net/ipv4/route.c) load the
  device with dst_dev_rcu() inside rcu_read_lock().

--

ipv4: route: fix use-after-free in ipv4_confirm_neigh()

This patch makes ipv4_confirm_neigh() hold rcu_read_lock() and load the
egress device with dst_dev_rcu() instead of dst_dev(). It relies on the
grace period in netdev_run_todo() to keep the old net_device alive after
a concurrent dst_dev_put() swaps dst->dev to blackhole_netdev.

Link: https://lore.kernel.org/netdev/20261123133000.2.n0ps1edzz@gmail.com/

> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index cd69242afab07..5ceea01f27b4e 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -441,19 +441,25 @@ static struct neighbour *ipv4_dst_neigh_lookup(const struct dst_entry *dst,
>  static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)
>  {
>  	const struct rtable *rt = container_of(dst, struct rtable, dst);
> -	struct net_device *dev = dst_dev(dst);
> +	struct net_device *dev;
>  	const __be32 *pkey = daddr;
>  
> +	rcu_read_lock();
> +	dev = dst_dev_rcu(dst);

[Severity: High]
The commit message says:

  The grace period added to netdev_run_todo() ensures that the
  device remains alive until the read-side critical section finishes.

Does that hold for dst->dev swaps done from RCU callbacks?

The synchronize_net() in netdev_run_todo() only covers dst_dev_put()
calls that finish before it starts. The commit in the Fixes tag also added
dst_dev_put() to rt_fibinfo_free_cpus() in net/ipv4/fib_semantics.c, which
works on per-CPU cached output routes. Those routes are not on
rt_uncached_list, so rt_flush_dev() never touches them.

For routes that use nexthop objects (ip nexthop add id N dev X; ip route
add ... nhid N), it looks like the teardown can be pushed past that grace
period:

  unregister (RTNL held)
    nexthop_flush_dev()->remove_nexthop()->nexthop_put()
      /* not the last ref, fi->nh holds one from fib_create_info() */
    fib_flush()->fib_release_info()->fib_info_put()->free_fib_info()
      call_rcu_hurry(free_fib_info_rcu)

  netdev_run_todo()
    rcu_barrier()
      free_fib_info_rcu()
        nexthop_put(fi->nh)
          call_rcu_hurry(&nh->rcu, nexthop_free_rcu)  /* chained */
    rt_flush_dev(NULL)
    rt6_uncached_list_flush_dev(NULL)
    synchronize_net()

  later, from the chained callback:
    nexthop_free_rcu()->nexthop_free_single()->fib_nh_release()
      ->fib_nh_common_release()->rt_fibinfo_free_cpus()
        ->dst_dev_put()
            rcu_assign_pointer(dst->dev_rcu, blackhole_netdev);
            netdev_ref_replace(dev, blackhole_netdev, ...);

rcu_barrier() does not wait for callbacks queued by the callbacks it
waited for. That means nexthop_free_rcu() can run during or after the new
synchronize_net().

After that, netdev_wait_allrefs_any() hands the device back as soon as
netdev_refcnt_read(dev) == 1. This can happen on its first check or right
after an rcu_barrier(), and neither of those implies a grace period after
the dst_dev_put() above. netdev_run_todo() then frees the device.

Here is the sequence I have in mind. A udp_sendmsg() caller using
MSG_CONFIRM|MSG_PROBE holds that per-CPU route. It enters rcu_read_lock()
here after the synchronize_net() has started. It loads the old device
through dst_dev_rcu() just before the swap. It is still inside the
read-side section when the device is freed.

Wouldn't __ipv4_confirm_neigh()->__ipv4_neigh_lookup_noref() then read
dev->flags from the freed net_device?

The same window seems to exist when a switchdev or offload driver (mlxsw,
prestera, rocker, mlx5 lag, netdevsim) holds a fib_info reference with
fib_info_hold() and drops it from a work item after netdev_run_todo() has
gone past its rcu_barrier() and synchronize_net().

Is another grace period needed between the last dst_dev_put() reference
drop and the free? One option would be a synchronize_net() after
netdev_wait_allrefs_any() sees the refcount reach 1.

> +
>  	if (rt->rt_gw_family == AF_INET) {
>  		pkey = (const __be32 *)&rt->rt_gw4;

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795754281.git.n0ps1edzz%40gmail.com
Technical Details
Message-ID: <179584815806.3135.2658352587378278244@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373037-linux-kernel-netdev=dewy.ru
References: <1a0a6b41df2422c4cea67f1571772b9d22ab200d.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!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373037-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 2/4] ipv4: route: fix use-after-free in ipv4_confirm_neigh()
Date: Sat, 28 Nov 2026 06:42:38 +0000
Organization: Usenet Network
Message-ID: <179584815806.3135.2658352587378278244@kernel.org>
References: <1a0a6b41df2422c4cea67f1571772b9d22ab200d.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="898913"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:TCKcyLdz3bd3PyWXNHFwE5i5+/o= sha256:g1hSrNBp6yAX2CB1C1AgiMyoHOdV3sBVg5A0qK5KAVg= sha1:qS7cjVoqG6iYdaRcjHHRdgdgUsA= sha256:/udhSmQAlUVHClXCAPsMd8caa2r4i9ZdxCWr6jNuZd8=
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 43A72125F72; Sat, 28 Nov 2026 09:42:55 +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 1s_LcoHWFzw6; Sat, 28 Nov 2026 09:42:52 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373037-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 9DC80125F6B; Sat, 28 Nov 2026 09:42:43 +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 8174C2B8FE; Sat, 28 Nov 2026 06:42:40 +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=1795848160; b=P+pbsiCQkmQlhe2HHDiOBE5eY1jjnzrsEPtMcp06X5B91PlsUrDMwU9WMmy2PM6oV4bA ReXm9JcOh2rP2V5HnjWiOW05SQmdD2xuXFaHgvMzc674/aWEfr/PEu+cLKY3dI0SlPEpf CbvebKLA+qmYRODZeZfJr5T5Tb/TLzjDKbp1Uz14HgmZjTyyxDAXrACqFQfK3+yEDUJSy /mVhZ3yKGZCt5rfx6FWKWJtOQKZTn7ITQs5iUBbYUWn48Da7mV+IMZOKyZ3kYAGHi+pET 6RpLTBpJUmsiSXqKSie/e9P9KzAcGQWFD9tIDCGNn5FhfNgB475t6i9mbgo051edddQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795848160; 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=l49AbvBiUeyoIZ4W5YDZD4tOl8C4Jc4U6WVcPXEZuec=; b=W7x3vKFmaTFkxzFXy4PjV/ieotIFWlL+O3j7he/4aJ/PKvWaFRf4Ks14dcjGcAf6agbA mROpt5rIB8JewPbYqOxu6l9HMhd1vWzspMzqd8EqydhD/3aU3Melp4BjK/HdaST/4/D8Z F0Jv4HfSjuUfAGTB5gOMzNTfxkgCYucMgzwo9j4f9GoSYtgDd6OBzxOgm1dq1mGTJSB+A U7p4Ui2EKRDkaMOOMtd00lm+DZhyfSNEMQJ/HQauiFuQxbQ10hVOmmnWxBEQNPIiCM2Dn 0ijjbwFakejPPJViZ6JNJAHL4zI9MkbFmoFJbYrUBENI7ax40ICKjVfl4AWWUTEtFCA==
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=iYgubF9L; 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 5A1DE606A31E; Sat, 28 Nov 2026 06:42:40 +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=iYgubF9L
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=1795848159; b=rJX2vYoX0cHg6wB9iPpKP4aRwT5VNWIRUxmcku8MQgBH3XHrzT4akMe2AN2Argr/+ctc mBhBWnJ1xbVTrMEuxk0j+Deo1nvt2qjWKFT1sgakMPcapePWrRF4E2S+InHoYDhe/TGX9 YS3Mjidvr1tW4I/5P4h04WkbiH1zwtgtdFs7TLCjgB6s9pDKuRcpdcEtQ91sOr8+EPOCu 8urtFMbJeRLHSj00WXgV5Ar0pcNqrOctgPMD6viItu9Q4SZOW5GHuq9IYMtFiWp+PwOCb cbC+19hVs/vYb8VmB84+xhPplG19Ij0ePOqzj0j7eD4yFnkNr5h5ONPJWINIRBypA1w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795848159; 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=l49AbvBiUeyoIZ4W5YDZD4tOl8C4Jc4U6WVcPXEZuec=; b=lbVkuG1D8OWmsVg7DrgvBn1QfHmLIGqjeVoxMW1kMUZ8pJtGY/+kSFWn2X74KhFXimXg jmQ3uvjigBYNxbp50xhUa5aBMIpwWL4uoLoUH8NQ6hAdzD+JG5JaRE0TDUVTHg/ErnlRQ f3XiIXgUgb54nfjU1iejLegvAmFzKZ3U2T43oJGx5IlD9VluhNu0sHbjE1WkC2VB6OWRB tF4r6U3ciwlqU3dodarw558ax9tL0cPcdVFHKly1h8I21BnuR4kxObwHChZSmwEaIbHHi /zxn8OmbSikVd9Ob6iN/CJ+/dJrXpjATB8hQmIKUgWXDo5sPCgNpEr3bpBaxDvRmFJA==
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=iYgubF9L; 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 7BFA9606A32A for <netdev@vger.kernel.org>; Sat, 28 Nov 2026 06:42:39 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F0721F000C1; Sat, 28 Nov 2026 06:42:38 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795848159; bh=l49AbvBiUeyoIZ4W5YDZD4tOl8C4Jc4U6WVcPXEZuec=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=iYgubF9L3DGaay4VLZN/DTmAcNGWsUQzo+hcplc/LaLfntN83IH9JbIPNuRJ2Cv6c L+yB/lbWfGFCbILU2W3S4xAGD4r3HLXuYqW1web3I9k3njtzOE6B/tRj/jNQQ/Rrj8 R4wmZNLPin5xVYJnCwHIdELvC4X8G4Ir3SvvcwPAjZ9E80R3WHwjJ9YQRJNI9icKxf hJThUU1ziIzPotzG/h+eVCW+1hT/ula3AVI0/1ZLbSy7LJmve7NWbZ/w7AzZPpxq4W pZhPRr4xv2MFUCwU2ynSoBqKWjsspQq9XlPgpbey6RiCzAepzd1SJG3//nnHpaUIna IA3wYaO3NwwAg==
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: <1a0a6b41df2422c4cea67f1571772b9d22ab200d.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