Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 1/4] net: wait for RCU readers after flushing routes
  2026-11-27  4:38 [PATCH net v2 0/4] net: fix dst->dev lifetime races Zhou Qiuyue
@ 2026-11-27  4:03 ` Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 2/4] ipv4: route: fix use-after-free in ipv4_confirm_neigh() Zhou Qiuyue
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Zhou Qiuyue @ 2026-11-27  4:03 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Willem de Bruijn,
	Kuniyuki Iwashima, Hangbin Liu

netdev_run_todo() waits for outstanding RCU callbacks before flushing
routes.  However, rt_flush_dev() and rt6_uncached_list_flush_dev() can
release the last reference held by a dst to an unregistering net_device.

A reader can load the old device from dst->dev under RCU before
dst_dev_put() replaces it with blackhole_netdev.  A route release from an
RCU callback can then drop the last reference while that newer reader is
still active.  The earlier rcu_barrier() does not wait for such a read-side
critical section, so netdev_run_todo() can proceed to free the device
underneath the reader.

Wait for pre-existing networking RCU read-side critical sections after
both route flushes and before freeing the devices.

Ido Schimmel identified this missing grace period during review.  The
lifetime was validated by source inspection; this specific window has not
been triggered independently at runtime.

Fixes: 4a6ce2b6f2ec ("net: introduce a new function dst_dev_put()")
Cc: stable@vger.kernel.org
Suggested-by: Ido Schimmel <idosch@nvidia.com>
Link: https://lore.kernel.org/netdev/20261125190113.GA421469@shredder/
Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
---
 net/core/dev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/core/dev.c b/net/core/dev.c
index cd0796a1d..2a9d9a06c 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;
-- 
2.56.1.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net v2 2/4] ipv4: route: fix use-after-free in ipv4_confirm_neigh()
  2026-11-27  4:38 [PATCH net v2 0/4] net: fix dst->dev lifetime races Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 1/4] net: wait for RCU readers after flushing routes Zhou Qiuyue
@ 2026-11-27  4:03 ` Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 3/4] ipv6: route: fix use-after-free in ip6_confirm_neigh() Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 4/4] ipv6: route: fix use-after-free in ip6_dst_neigh_lookup() Zhou Qiuyue
  3 siblings, 0 replies; 5+ messages in thread
From: Zhou Qiuyue @ 2026-11-27  4:03 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Willem de Bruijn,
	Kuniyuki Iwashima, Hangbin Liu

dst_confirm_neigh() is reachable from paths that do not hold an RCU read
lock, including udp_sendmsg() with MSG_CONFIRM and MSG_PROBE.

ipv4_confirm_neigh() loads the egress device with dst_dev().  Concurrent
route teardown can replace dst->dev with blackhole_netdev and drop the
route's reference to the old net_device.  The old device can then be freed
before ipv4_confirm_neigh() finishes using the pointer.

An AI-assisted source audit identified the unsafe load.  A delay inserted
after it to widen the race window reproduced the issue on v7.4-rc3 with
KASAN:

  BUG: KASAN: slab-use-after-free in ipv4_confirm_neigh+0xcc8/0xce0
  Read of size 8 ... by task confirm_race4/126

Hold the RCU read lock across the callback and use dst_dev_rcu() to load
the device.  The grace period added to netdev_run_todo() ensures that the
device remains alive until the read-side critical section finishes.

Fixes: 95c47f9cf5e0 ("ipv4: call dst_dev_put() properly")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/netdev/20261123133000.2.n0ps1edzz@gmail.com/
Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
---
 net/ipv4/route.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index cd69242af..5ceea01f2 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);
+
 	if (rt->rt_gw_family == AF_INET) {
 		pkey = (const __be32 *)&rt->rt_gw4;
 	} else if (IS_ENABLED(CONFIG_IPV6) && rt->rt_gw_family == AF_INET6) {
-		return __ipv6_confirm_neigh(dev, &rt->rt_gw6);
+		__ipv6_confirm_neigh(dev, &rt->rt_gw6);
+		goto out;
 	} else if (!daddr ||
 		 (rt->rt_flags &
 		  (RTCF_MULTICAST | RTCF_BROADCAST | RTCF_LOCAL))) {
-		return;
+		goto out;
 	}
 	__ipv4_confirm_neigh(dev, *(__force u32 *)pkey);
+out:
+	rcu_read_unlock();
 }
 
 /* Hash tables of size 2048..262144 depending on RAM size.
-- 
2.56.1.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net v2 3/4] ipv6: route: fix use-after-free in ip6_confirm_neigh()
  2026-11-27  4:38 [PATCH net v2 0/4] net: fix dst->dev lifetime races Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 1/4] net: wait for RCU readers after flushing routes Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 2/4] ipv4: route: fix use-after-free in ipv4_confirm_neigh() Zhou Qiuyue
@ 2026-11-27  4:03 ` Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 4/4] ipv6: route: fix use-after-free in ip6_dst_neigh_lookup() Zhou Qiuyue
  3 siblings, 0 replies; 5+ messages in thread
From: Zhou Qiuyue @ 2026-11-27  4:03 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Willem de Bruijn,
	Kuniyuki Iwashima, Hangbin Liu

dst_confirm_neigh() is reachable from paths that do not hold an RCU read
lock, including rawv6_sendmsg() with MSG_CONFIRM and MSG_PROBE.

ip6_confirm_neigh() loads the egress device with dst_dev().  Concurrent
route teardown can replace dst->dev with blackhole_netdev and drop the
route's reference to the old net_device.  The old device can then be freed
before ip6_confirm_neigh() finishes using the pointer.

An AI-assisted source audit identified the unsafe load.  A delay inserted
after it to widen the race window reproduced the issue on v7.4-rc3 with
KASAN:

  BUG: KASAN: slab-use-after-free in ip6_confirm_neigh+0x6a7/0xbd0
  Read of size 4 ... by task confirm_race/130

Hold the RCU read lock across the callback and use dst_dev_rcu() to load
the device.  The grace period added to netdev_run_todo() ensures that the
device remains alive until the read-side critical section finishes.

Fixes: 9514528d92d4 ("ipv6: call dst_dev_put() properly")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/netdev/20261123133000.1.n0ps1edzz@gmail.com/
Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
---
 net/ipv6/route.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 1b2dcc066..6bdd4423c 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -257,16 +257,21 @@ static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,
 static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
 {
 	const struct rt6_info *rt = dst_rt6_info(dst);
-	struct net_device *dev = dst_dev(dst);
+	struct net_device *dev;
+
+	rcu_read_lock();
+	dev = dst_dev_rcu(dst);
 
 	daddr = choose_neigh_daddr(rt6_nexthop(rt, &in6addr_any), NULL, daddr);
 	if (!daddr)
-		return;
+		goto out;
 	if (dev->flags & (IFF_NOARP | IFF_LOOPBACK))
-		return;
+		goto out;
 	if (ipv6_addr_is_multicast((const struct in6_addr *)daddr))
-		return;
+		goto out;
 	__ipv6_confirm_neigh(dev, daddr);
+out:
+	rcu_read_unlock();
 }
 
 static struct dst_ops ip6_dst_ops_template = {
-- 
2.56.1.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net v2 4/4] ipv6: route: fix use-after-free in ip6_dst_neigh_lookup()
  2026-11-27  4:38 [PATCH net v2 0/4] net: fix dst->dev lifetime races Zhou Qiuyue
                   ` (2 preceding siblings ...)
  2026-11-27  4:03 ` [PATCH net v2 3/4] ipv6: route: fix use-after-free in ip6_confirm_neigh() Zhou Qiuyue
@ 2026-11-27  4:03 ` Zhou Qiuyue
  3 siblings, 0 replies; 5+ messages in thread
From: Zhou Qiuyue @ 2026-11-27  4:03 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Willem de Bruijn,
	Kuniyuki Iwashima, Hangbin Liu

ip6_dst_neigh_lookup() can be called without an RCU read lock.  One such
caller is irdma_addr_resolve_neigh_ipv6(), after its route lookup.

The callback loads the egress device with dst_dev() and passes the pointer
to __ip6_dst_neigh_lookup().  On a neighbour-cache miss, that helper calls
ipv6_neigh_create(), which dereferences the device and can invoke its
operations.  Concurrent route teardown can replace dst->dev with
blackhole_netdev, drop the route's reference to the old net_device, and
free it while the lookup is still using the pointer.

Hold the RCU read lock across the lookup and use dst_dev_rcu() to load the
device, matching the protection in ipv4_dst_neigh_lookup().

Ido Schimmel identified this unprotected callback during review.  The
lifetime and non-RCU caller were validated by source inspection; this path
has not been triggered independently at runtime.

Fixes: 9514528d92d4 ("ipv6: call dst_dev_put() properly")
Cc: stable@vger.kernel.org
Suggested-by: Ido Schimmel <idosch@nvidia.com>
Link: https://lore.kernel.org/netdev/20261125190113.GA421469@shredder/
Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
---
 net/ipv6/route.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 6bdd4423c..a9f197bf5 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -249,9 +249,16 @@ static struct neighbour *ip6_dst_neigh_lookup(const struct dst_entry *dst,
 					      const void *daddr)
 {
 	const struct rt6_info *rt = dst_rt6_info(dst);
+	struct net_device *dev;
+	struct neighbour *n;
+
+	rcu_read_lock();
+	dev = dst_dev_rcu(dst);
+	n = __ip6_dst_neigh_lookup(rt6_nexthop(rt, &in6addr_any),
+				   dev, skb, daddr);
+	rcu_read_unlock();
 
-	return __ip6_dst_neigh_lookup(rt6_nexthop(rt, &in6addr_any),
-				      dst_dev(dst), skb, daddr);
+	return n;
 }
 
 static void ip6_confirm_neigh(const struct dst_entry *dst, const void *daddr)
-- 
2.56.1.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net v2 0/4] net: fix dst->dev lifetime races
@ 2026-11-27  4:38 Zhou Qiuyue
  2026-11-27  4:03 ` [PATCH net v2 1/4] net: wait for RCU readers after flushing routes Zhou Qiuyue
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Zhou Qiuyue @ 2026-11-27  4:38 UTC (permalink / raw)
  To: netdev
  Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Willem de Bruijn,
	Kuniyuki Iwashima, Hangbin Liu

The conversion of dst->dev to an RCU-protected pointer left two route
confirmation callbacks and the IPv6 neighbour lookup callback loading it
without RCU protection.  Also, netdev_run_todo() did not wait for readers
after flushing routes that can release the last dst-held device reference.

Patch 1 adds the teardown-side grace period after the route flushes.
Patches 2 and 3 protect the IPv4 and IPv6 confirmation callbacks.  Patch 4
protects the IPv6 neighbour lookup callback, matching its IPv4 counterpart.

Finding and validation:

- Patches 2 and 3 came from an AI-assisted source audit.  Delay-assisted
  KASAN runs on the exact v7.4-rc3 commit reproduced both bugs:

    BUG: KASAN: slab-use-after-free in ipv4_confirm_neigh+0xcc8/0xce0
    BUG: KASAN: slab-use-after-free in ip6_confirm_neigh+0x6a7/0xbd0

  The delay was debug-only window amplification and is not in this series.

- Ido identified the missing grace period in patch 1 and the unprotected
  lookup in patch 4 during review.  Both were validated by source inspection;
  those two windows have not been triggered independently at runtime.

Testing:

- KASAN reruns on v7.4-rc2 with the callback fixes corresponding to
  patches 2 and 3 completed without a report.  The IPv4 run made 392065
  callback calls across 110 dst_dev_put() calls and 48 device frees.  The
  IPv6 run made 13144 callback calls across 36 dst_dev_put() calls and 48
  device frees.
- On the current net tree base below, these objects built with W=1:
  net/core/dev.o, net/ipv4/route.o, and net/ipv6/route.o.
- A full allmodconfig or allyesconfig build and networking selftests were not
  run.

This is treated as a regular bug: the demonstrated teardown needs privileged
network-device administration, and no privilege-boundary crossing or exploit
has been demonstrated.

Changes since v1:

- Combine the separate IPv4 and IPv6 submissions into one series, as
  requested by Ido and Kuniyuki.
- Add the post-flush synchronize_net() patch suggested by Ido.
- Add the ip6_dst_neigh_lookup() patch suggested by Ido.
- Distinguish the dynamically reproduced findings from the source-inspection
  findings and document the validation limits.

v1 IPv6:
https://lore.kernel.org/netdev/20261123133000.1.n0ps1edzz@gmail.com/
v1 IPv4:
https://lore.kernel.org/netdev/20261123133000.2.n0ps1edzz@gmail.com/
Review:
https://lore.kernel.org/netdev/20261125190113.GA421469@shredder/

AI assistance disclosure: Codex was used for the source audit, test-harness
automation, patch drafting, and changelog drafting.  The runtime results above
come from the described QEMU/KASAN runs.  The Signed-off-by tags were added at
the submitter's explicit request.

Zhou Qiuyue (4):
  net: wait for RCU readers after flushing routes
  ipv4: route: fix use-after-free in ipv4_confirm_neigh()
  ipv6: route: fix use-after-free in ip6_confirm_neigh()
  ipv6: route: fix use-after-free in ip6_dst_neigh_lookup()

 net/core/dev.c   |  1 +
 net/ipv4/route.c | 12 +++++++++---
 net/ipv6/route.c | 24 ++++++++++++++++++------
 3 files changed, 28 insertions(+), 9 deletions(-)


base-commit: e1055cbfd6eb578417f3ce983cf44462e8465267
-- 
2.56.1.windows.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-27  5:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  4:38 [PATCH net v2 0/4] net: fix dst->dev lifetime races Zhou Qiuyue
2026-11-27  4:03 ` [PATCH net v2 1/4] net: wait for RCU readers after flushing routes Zhou Qiuyue
2026-11-27  4:03 ` [PATCH net v2 2/4] ipv4: route: fix use-after-free in ipv4_confirm_neigh() Zhou Qiuyue
2026-11-27  4:03 ` [PATCH net v2 3/4] ipv6: route: fix use-after-free in ip6_confirm_neigh() Zhou Qiuyue
2026-11-27  4:03 ` [PATCH net v2 4/4] ipv6: route: fix use-after-free in ip6_dst_neigh_lookup() Zhou Qiuyue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox