* [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