Re: [PATCH net] ipv4: route: fix use-after-free in ipv4_confirm_neigh()
From: Ido Schimmel
Date: Wed Nov 25 2026 - 14:04:20 EST
On Mon, Nov 23, 2026 at 01:30:00PM +0800, Zhou Qiuyue wrote:
>
> ipv4_confirm_neigh() loads dst->dev with dst_dev() and hands the
> resulting net_device to the neighbour lookup. The load is outside any
> RCU read-side section: __ipv4_confirm_neigh() does take rcu_read_lock(),
> but only after the pointer has been read, which is too late to protect
> it. The load is only a READ_ONCE(); it does not pin the device.
> udp_sendmsg(), raw_sendmsg() and ping_v4_sendmsg() reach
> dst_confirm_neigh() when sendmsg() is issued with MSG_CONFIRM and
> MSG_PROBE, without holding RCU or a net_device reference.
>
> The first stale field read is dev_net(dev) in arp_table(), reached from
> the neighbour lookup. Route teardown drops the reference the dst held on
> the device: dst_dev_put() does it for dsts removed from the fib tree, and
> rt_flush_dev() does it for uncached routes. Both replace dst->dev with
> blackhole_netdev, so a reader that loaded the old pointer just before the
> replacement can dereference a freed net_device.
>
> Take rcu_read_lock(), load the device with dst_dev_rcu(), and keep the
> section through the gateway dispatch and __ipv4_confirm_neigh().
[...]
> Fixes: 95c47f9cf5e0 ("ipv4: call dst_dev_put() properly")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Zhou Qiuyue <n0ps1edzz@xxxxxxxxx>
Should be posted together with the IPv6 patches:
https://lore.kernel.org/netdev/20261125190113.GA421469@shredder/
pw-bot: cr