From: Hangbin Liu <hangbin.liu@linux.dev>
To: Zhou Qiuyue <n0ps1edzz@gmail.com>
Cc: netdev@vger.kernel.org, dsahern@kernel.org
Subject: Re: [PATCH] ipv6: raw: fix use-after-free in rawv6_send_hdrinc()
Date: Mon, 26 Oct 2026 11:11:14 +0800 [thread overview]
Message-ID: <at7E0uc5oU8AWZcD@fedora> (raw)
In-Reply-To: <6adad51d.8fc0b0c9.1ec657.1868@mx.google.com>
Hi Qiuyue,
On Thu, Oct 22, 2026 at 08:31:41PM -0700, Zhou Qiuyue wrote:
> rawv6_send_hdrinc() saves a pointer to the dst/rt6_info before calling
> l3mdev_ip6_out():
>
> skb_dst_set(skb, &rt->dst);
> *dstp = NULL;
> skb = l3mdev_ip6_out(sk, skb);
>
> When the egress device is enslaved to a VRF with a non-default qdisc
> (e.g. fq), l3mdev_ip6_out() takes the vrf_ip6_out_redirect() path,
> which does:
>
> skb_dst_drop(skb); // drops refcount on old dst -> call_rcu
> skb_dst_set(skb, dst); // installs VRF's own rt6
>
> The old dst entry (the one `rt` still points to) now has refcount 0 and
> is queued for RCU-deferred destruction via dst_destroy_rcu(). After
> l3mdev_ip6_out() returns, rawv6_send_hdrinc() continues to use the
> stale `rt` pointer:
>
> IP6_INC_STATS(net, rt->rt6i_idev, ...); // UAF read
> err = NF_HOOK(..., rt->dst.dev, ...); // UAF read
>
> With expedited RCU grace periods (rcupdate.rcu_expedited=1) and
> CONFIG_PREEMPT=y, the RCU callback fires quickly enough to free the
> object before the stale accesses, producing a slab-use-after-free
> detectable by KASAN.
>
> Fix this by reloading `rt` from skb_dst(skb) after l3mdev_ip6_out()
> returns, so subsequent code uses the (possibly replaced) dst entry.
>
> Fixes: a8e3e1a9f020 ("net: l3mdev: Add hook in output path")
> Signed-off-by: Zhou Qiuyue <n0ps1edzz@gmail.com>
You need add a target repo for patch subject. e.g. [PATCH net] ...
BTW, you patch doesn't apply to the current net tree.
Applying: ipv6: raw: fix use-after-free in rawv6_send_hdrinc()
Patch failed at 0001 ipv6: raw: fix use-after-free in rawv6_send_hdrinc()
error: corrupt patch at /net/.git/worktrees/tests/rebase-apply/patch:25
Please rebase you patch with latest code.
BTW, please remember cc all the needed maintainers with scripts/get_maintainer.pl.
> ---
> net/ipv6/raw.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
> index XXXXXXX..XXXXXXX 100644
> --- a/net/ipv6/raw.c
> +++ b/net/ipv6/raw.c
> @@ -648,6 +648,13 @@ static int rawv6_send_hdrinc(struct sock *sk, struct msghdr *msg, int length,
> if (unlikely(!skb))
> return 0;
>
> + /*
> + * l3mdev_ip6_out() may have replaced skb's dst via
> + * vrf_ip6_out_redirect(), in which case the original dst has been
> + * released and may be freed asynchronously. Reload rt from the
> + * current 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.
> --
> 2.43.0
The change looks good to me.
Thanks
Hangbin
prev parent reply other threads:[~2026-10-26 3:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 3:31 [PATCH] ipv6: raw: fix use-after-free in rawv6_send_hdrinc() Zhou Qiuyue
2026-10-23 7:48 ` Zhou Qiuyue
2026-10-26 3:11 ` Hangbin Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=at7E0uc5oU8AWZcD@fedora \
--to=hangbin.liu@linux.dev \
--cc=dsahern@kernel.org \
--cc=n0ps1edzz@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.