From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796455476; b=Nl5dk4iY7kX9LfOCeDWHSrFix4QEWPK+gQQKZXPeFEpYJNbNoXMn71EtDJzkBaB9wvjD /S23KKhb3sJGOi3ezchzlSvXR9YewBY7QAFtXRMRZ5bj/zFRqOFGDdR6vmo12wx/TUPdb y7MZyOqIlsseFdg/e0Atb/mhnhrnBgx2Q8vXxUZaB6ZE8Vbg7zRXXaobRHzna68TneKHU qMMvalFCSru0tuQWsh7Zqo5r8noD2WjAuRmMKyq26ch8SYXtWZwNtkVStyVpkzGK5XZoy Q63U0RJlOzyLSyacyqwyJrBR/frp26X12rYtDvpgF1hCDcpy/oxc8kNm/pWSJcHSWlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796455476; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Mime-Version:Content-Transfer-Encoding:Content-Type:Date:Message-Id: Cc:Subject:From:To:X-Mailer:References:In-Reply-To; bh=zr3e9QjVVDfrRiR4NuomLzU5dsi36M2uM2fiMNLGSXE=; b=tZHp3siua8usBZW4fHTjMZUBvAEph157/Tx71CDtTu2D/TNmwrTJ63GYGfw2nCyLGcfb DCjUu5v4W3sBdtBNCo6v8+zV/XFg7kT3s65daBLn02VcaMT+TqpMVReJpGO0MxYxJeRbK wNBydXB1eh44ocCJyGuCtaQugsSjqYX8lVZeeZnIWug8CGLoqyRAtxiIrtoJWi7wdu7qw S0jtTUJZd3CN1OwUl4eAkMKL0tCbUs3UYK4mHcxRRFCCaW1lMMLR84HgXAHnJhMtv2Iy7 Hy/7sXUSaC/RH0yGi8EaGbvCRFqcqNxCAIAOsS3GKB38B0jiNTWzP/e0S5oR1N8mGbQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wBJ8qkm7; arc=none smtp.remote-ip=209.85.215.176 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45F8D606A32F for ; Sat, 5 Dec 2026 07:24:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 45F8D606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=wBJ8qkm7 Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cdb75699c7cso658031a12.2 for ; Fri, 04 Dec 2026 23:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796455476; x=1797060276; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=zr3e9QjVVDfrRiR4NuomLzU5dsi36M2uM2fiMNLGSXE=; b=wBJ8qkm7CEuGiLsgE7iBPNnor5/mFiJXllEU6bTPb1Ii4nBU1yhaHw0IAz2gwd0anM /tvaw2eWLgC1bzI2RX7z6iInwzNTTTR8/D0aKzLHRUeLTmnYhjj/NHKoBOdpe8Lu9e8H 7Q4oa8As802HmwTPN+3M+O3y+qCVAlzgJ2/QMN8UsTTUiihq9h3LpCLnNz7z86lkKyKo a4l2aj0rjFpTAZ0oVFCDVqFOunqsbQRmWr2iwiMF0jGnaXSiUD2MgkdLIRq9SVO71Y4u etr7UxdzfajeRzhMXTkpvbnUWhQPa1X3vGXfLp/zj40WadJIw3Qt2Ix4HcZAsYqrC12i o9VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796455476; x=1797060276; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:content-transfer-encoding:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zr3e9QjVVDfrRiR4NuomLzU5dsi36M2uM2fiMNLGSXE=; b=U1I/S4oHGapLVl2XddL+56aY8tmQHTmG/MtKRoU88AmwTKZDMnPpMJsFG5CYDTK8A5 TB6D76M5TYOKjiiKssKL8LdiUBZ3osARH4Mf1LwyAKLJzvOLrqt4TElRWnel/ALHz9l8 ApV7pAKuhVgO360083Clodct5aQXIAYxiFWLuHE0mAkHN1VEVE5fz8kLrwYYn/w1FZHh vtnpquVXD4BfGZGLEvox9tnYGp13oB3jQIwRm1IkfboFuTwksL5cowRlwB+THRqzacGr N7Twp+EKuJWL9Tq1R2KHtr0nWjIrHxKmvo9+WWm3MJbIEYDbnBhezbmC1RcxAfPvOjrn OjpA== X-Forwarded-Encrypted: i=1; AL+hErFgEBithevyqDvFqhc1gl42ezxztPkIetib9vD7LHsx3GlSdBGUpPofdMBfbN43x0y4O3Q=@vger.kernel.org X-Gm-Message-State: APuU4Z9d1SO23Fuyiv0Hk7qfJzSnThvac1pyeEMegpTc6Myn/8y6rmDG sI9yhWrvNeEz+/L89wACUlip6CvAqkb/I5hL+//9jz3E8GxfVilp+ST6 X-Gm-Gg: AZFdTZfSIPL9X4ypvt/baENt4kgyOH9Baeiij0UABsKYF9b6mDmxi1m1SkR1yrf/0Xc OMGkSzYJPRi/Y8T4EWbbVMTlnMMWFcz8kEqKO4qTTaGcHDJnGsxR0u8G/IrUEQViaCDgYv4PDAx Gl0+WX6ThQDUiHw5hfrsWaD0p3yoLrQaG2io9bMDnMfar0pAapTr25PxOpaw2drWpRbX9fpPNRk sJ3URxdeb2bBlrnDgWuAk2k/oOq68j0gM2YOBaBe0z0WSBQ91FvhPZP3F3gtcofLnGioXjO2/Th hQsj67d2ysytUZPr8yViwSPPzJYJ35/2UOihk0chWt/6H7dqMZ+mQ0yzTabD/XLB/dCW7NZ+rWd QHbT9NAoX0pzAxAbXU+gv0CJP7DpDd6cOQwinccFsKShRRits4k7CJ7/nt3s1Ll6+HvgTE9b69b 0JMS/uPSOeI0vymo4D1VQJzpBlKQdYh3yhGOfCRLg0IcnLtCYshk4ZllMnhiCzyDRC5EX6iPolo dPUF4vjnit4frUT5xcms9JvWpIYdGDxXxzDmrcLNTxwX9+x+wMaHw5VHJUGAICyICKb7WF57RPU ln9j5XCSK9sFpW2kEAwBEzRcFOaDxqdKjUSzPUAcLbdNtBtcCwkV4pcFWrCip6tDzQIyutfsLI3 0RLmRYP5RvFiUqCKV3LDdPNvTGQE1tSLUFfI= X-Received: by 2002:a05:6a21:1f8d:b0:3f4:79fa:414 with SMTP id adf61e73a8af0-4156163d678mr4877487637.13.1796455475336; Fri, 04 Dec 2026 23:24:35 -0800 (PST) Received: from localhost ([153.61.198.251]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ce1234649eesm2689919a12.4.2026.12.04.23.24.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 23:24:34 -0800 (PST) X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 05 Dec 2026 07:24:33 +0000 Message-Id: Cc: "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Simon Horman" , "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "Ihor Solodrai" , "Shuah Khan" , "Fernando Fernandez Mancera" , "Junseo Lim" , "Xuanqiang Luo" , "Leon Hwang" , "Yuqiang Sun" , "Peter Oskolkov" , , Subject: Re: [PATCH bpf 1/2] bpf: lwt: fix NULL deref in IPv6 reroute From: "Alexei Starovoitov" To: "Jiayuan Chen" , X-Mailer: aerc 0.20.1-357-ga8fcb8d99360 References: <20261122041401.189733-1-jiayuan.chen@linux.dev> 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: > > 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 > > > 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 > --- > 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 =3D iph6->daddr; > fl6.saddr =3D iph6->saddr; > =20 > - dst =3D ip6_dst_lookup_flow(net, skb->sk, &fl6, NULL); > + if (ipv6_addr_any(&fl6.saddr) && > + sk && sk->sk_family !=3D AF_INET6) > + sk =3D NULL; > + > + dst =3D ip6_dst_lookup_flow(net, sk, &fl6, NULL); Is this still needed? Resend if necessary. pw-bot: cr