Re: [PATCH net v2] ipv6: raw: fix use-after-free in rawv6_send_hdrinc()
From: David Laight
Date: Fri Oct 30 2026 - 12:05:58 EST
On Mon, 26 Oct 2026 12:48:08 +0800
Zhou Qiuyue <n0ps1edzz@xxxxxxxxx> wrote:
> rawv6_send_hdrinc() caches the route before handing the skb to
> l3mdev_ip6_out(). The VRF output path may replace skb->dst and release
> the original route, leaving the cached pointer stale.
>
> The function later dereferences that pointer for statistics accounting
> and as the output device passed to NF_HOOK(). Its RCU read-side critical
> section starts after l3mdev_ip6_out(), so it cannot prevent the old route
> from being reclaimed in between.
Doesn't it also pass the wrong rt->dst.dev value to NF_HOOK() ?
> Reload the route from the current skb destination after
> l3mdev_ip6_out() returns.
Have you looked at just saving rt->rt6i_dev locally?
The rcu free of the temporary rt_info is expensive.
Last I looked it has to kmalloc() a little structure and later adds
latency to the softint code.
The thing is some applications can send a lot of packets through this path
(and I mean upwards of 50000 per second).
So even a kmalloc/kfree in this function would be better.
That might even save the rcu_read_lock() being needed.
David
>
> KASAN reports a slab-use-after-free in rawv6_sendmsg(), with the route
> allocated by ip6_dst_alloc(), freed by dst_destroy() from rcu_core(), and
> the related RCU callback queued from vrf_l3_out().
>
> Fixes: 4c1feac58e06 ("net: vrf: Flip IPv6 output path from FIB lookup hook to out hook")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Zhou Qiuyue <n0ps1edzz@xxxxxxxxx>
> ---
> Changes in v2:
> - Rebased onto the current net tree at 7076f684d513.
> - Regenerated the patch with git-format-patch so it applies cleanly.
> - Corrected the Fixes tag to the commit that made the IPv6 VRF path reachable.
> - Shortened the code comment and added the required recipients.
>
> v1: https://lore.kernel.org/r/6adad51d.8fc0b0c9.1ec657.1868@xxxxxxxxxxxxx
>
> Thank you to Hangbin Liu for reviewing v1 and pointing out the submission
> issues.
>
> net/ipv6/raw.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
> index b965258cf..bdea82543 100644
> --- a/net/ipv6/raw.c
> +++ b/net/ipv6/raw.c
> @@ -654,6 +654,9 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
> if (unlikely(!skb))
> return 0;
>
> + /* l3mdev_ip6_out() may have replaced the skb dst. */
> + rt = dst_rt6_info(skb_dst(skb));
> +
> /* Acquire rcu_read_lock() in case we need to use rt->rt6i_idev
> * in the error path. Since skb has been freed, the dst could
> * have been queued for deletion.
>
> base-commit: 7076f684d5132e6a6145e1da2fa74771ecd052e5