All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Jiayuan Chen" <jiayuan.chen@linux.dev>, <bpf@vger.kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Martin KaFai Lau" <martin.lau@linux.dev>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Shuah Khan" <shuah@kernel.org>,
	"Fernando Fernandez Mancera" <fmancera@suse.de>,
	"Junseo Lim" <zirajs7@gmail.com>,
	"Xuanqiang Luo" <luoxuanqiang@kylinos.cn>,
	"Leon Hwang" <leon.hwang@linux.dev>,
	"Yuqiang Sun" <izaiahsun@gmail.com>,
	"Peter Oskolkov" <posk@google.com>, <netdev@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH bpf 1/2] bpf: lwt: fix NULL deref in IPv6 reroute
Date: Sat, 05 Dec 2026 07:24:33 +0000	[thread overview]
Message-ID: <DNCMBFMJW17C.36HNP6GCWA26K@gmail.com> (raw)
In-Reply-To: <20261122041401.189733-1-jiayuan.chen@linux.dev>

On Sun Nov 22, 2026 at 4:13 AM UTC, Jiayuan Chen wrote:
> After an lwt prog pushed an IPv6 header, bpf_lwt_xmit_reroute() hands
> skb->sk to ip6_dst_lookup_flow(). When the flow has no source address,
> the lookup reads inet6_sk(sk)->srcprefs, and inet6_sk() is NULL for
> example when:
>
>  - skb->sk is a request_sock, e.g. for a SYN-ACK.
>  - skb->sk is an IPv4 socket, the IPv6 header was pushed on an IPv4
>    packet.
>
> KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047]
> RIP: 0010:ip6_route_output_flags+0x279/0x4c0
> Call Trace:
>  <TASK>
>  ip6_dst_lookup_tail.constprop.0+0x26e/0x1050
>  ip6_dst_lookup_flow+0x101/0x1e0
>  bpf_lwt_xmit_reroute+0xc18/0x18b0
>  bpf_xmit+0x28f/0x400
>  lwtunnel_xmit+0x2a7/0x620
>  ip_finish_output2+0xa67/0x1f80
>  __ip_finish_output+0x510/0x7e0
>  ip_finish_output+0x2f/0x320
>  ip_output+0x171/0x3e0
>  ip_push_pending_frames+0x200/0x260
>  raw_sendmsg+0x114c/0x3680
>  inet_sendmsg+0xdf/0x100
>  __sys_sendto+0x3ef/0x500
>  __x64_sys_sendto+0xe0/0x1b0
>  x64_sys_call+0x1375/0x27e0
>  do_syscall_64+0xe7/0x630
>  entry_SYSCALL_64_after_hwframe+0x76/0x7e
>  </TASK>
>
> Pass the full socket, and no socket if it is not an IPv6 one while the
> flow has no source address.
>
> Fixes: 3bd0b15281af ("bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c")
> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
> ---
>  net/core/lwt_bpf.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c
> index 72c86ff2a847..33f710d92106 100644
> --- a/net/core/lwt_bpf.c
> +++ b/net/core/lwt_bpf.c
> @@ -278,7 +278,11 @@ static int bpf_lwt_xmit_reroute(struct sk_buff *skb)
>  		fl6.daddr = iph6->daddr;
>  		fl6.saddr = iph6->saddr;
>  
> -		dst = ip6_dst_lookup_flow(net, skb->sk, &fl6, NULL);
> +		if (ipv6_addr_any(&fl6.saddr) &&
> +		    sk && sk->sk_family != AF_INET6)
> +			sk = NULL;
> +
> +		dst = ip6_dst_lookup_flow(net, sk, &fl6, NULL);

Is this still needed? Resend if necessary.

pw-bot: cr

      parent reply	other threads:[~2026-12-05  7:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  4:13 [PATCH bpf 1/2] bpf: lwt: fix NULL deref in IPv6 reroute Jiayuan Chen
2026-11-22  4:13 ` [PATCH bpf 2/2] selftests/bpf: test lwt_xmit reroute of an IPv4-in-IPv6 encap Jiayuan Chen
2026-12-05  7:24 ` Alexei Starovoitov [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=DNCMBFMJW17C.36HNP6GCWA26K@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=fmancera@suse.de \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=izaiahsun@gmail.com \
    --cc=jiayuan.chen@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=kuba@kernel.org \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luoxuanqiang@kylinos.cn \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=posk@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    --cc=zirajs7@gmail.com \
    /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.