[PATCH net 1/2] ipv4: route: fix use-after-free in ip_route_output_flow()

From: Zhou Qiuyue

Date: Fri Nov 27 2026 - 04:16:17 EST


ip_route_output_flow() drops the RCU read lock taken during route lookup
before reading rt->dst.dev->ifindex. The rtable remains referenced, but
route teardown can replace dst->dev with blackhole_netdev and drop its
reference to the old net_device.

A concurrent netdev_run_todo() can therefore free the old device after
the pointer is loaded and before its ifindex is read. KASAN reported the
resulting use-after-free twice while UDP sends raced with dummy-device
teardown.

Load and dereference the device through dst_dev_rcu() in an RCU read-side
critical section. This requires netdev_run_todo() to wait for RCU readers
after flushing routes; that fix is a prerequisite of this patch.

OpenAI Codex was used to analyze the supplied KASAN traces and reproducer
and to draft this patch and changelog.

Fixes: 95c47f9cf5e0 ("ipv4: call dst_dev_put() properly")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Zhou Qiuyue <n0ps1edzz@xxxxxxxxx>
---
net/ipv4/route.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index cd69242af..b16a9d05f 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2982,7 +2982,9 @@ struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4,
return rt;

if (flp4->flowi4_proto) {
- flp4->flowi4_oif = rt->dst.dev->ifindex;
+ rcu_read_lock();
+ flp4->flowi4_oif = dst_dev_rcu(&rt->dst)->ifindex;
+ rcu_read_unlock();
rt = dst_rtable(xfrm_lookup_route(net, &rt->dst,
flowi4_to_flowi(flp4),
sk, 0));
--
2.56.0