From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384283; b=lFUYSp2D352Fhjs/UrUg5OA40ymy+s7oAwbXacR35wawSp+0xe5SZ55+cWP5cpmHJJFj UsnsKrkUkHlhBEi1rqMdl+XLrSPqAeHvOYT6Ty9g8td4ckCmrBC2/TcZQYp5cXPOWScWG EOtcPrs6bXgJ8l856gmp/NAmyQ1ZLky8H7LW67YMWeH/TltAuIh6zwDzXoNRcHoZ3vH3j uFZheTD4FgfY6LdXkj4Mq5Rqd+l+sGlHWJgzDfsk2KmVYkKJoSjPpiINCzg72tNjQCz4v KWCGpc9kUrvdaH4/CNi+MDRCww9rrYqPY+XosX90dDPwBgclyCuVH6uq06StbD74/WQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384283; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=JCgtnXYNQtvzPfgrMwv8/jAVOtW9kuLegSwvVkyxbnk=; b=4EzDkqBnIhYYNdA8KiaAsXl9ZF6TM7WFD2DFXIs56YvjS8jp/XCeIdDxSpcb5ozNSrHY T0X3XzZhEu0EdFMSEkDlObpoTqqM/SfqeGSZoSvYoiVMS4R3h1BZJXy378nmpS7m+qAJD coFFEskJffcMCPeRnEYKCJHJBFwE0NIoFFU+Z8HI1iPzTyz66ZE9s0haqYtTT/Jvof1lV XzhcPIqoxIc1KrBY9Tt0sXqZWm0XVoraEOGEXSFW1EIoaP6svBZPyMdJLw1txpEZWSfcz tvDt0w3JaF27D7eLnYuB0HxxAQ+Be4cROtVJaUN0SB4lEdDrR8/LjWG7MunPL2inqZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mi0SGWMf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6490606A32F; Fri, 4 Dec 2026 11:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mi0SGWMf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DF441F00931; Fri, 4 Dec 2026 11:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384283; bh=JCgtnXYNQtvzPfgrMwv8/jAVOtW9kuLegSwvVkyxbnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mi0SGWMfqaZxDb6qFyoGawBtcdvI+aLfRYC208xropSS5wBXp4XyUtazyvUFwT6nN N3MDhjRCqSuOBAu+bGk1MpM4QoSKWVMbISte1ZFRfk61ZF4UhvgyrRscbScJt4CpyM ifk/MRPcpa0ckhinOaygcW01rkvKvhkPkP2+kVJQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.6 0068/1167] bpf: Reject non-IPv6 packets in BPF_LWT_ENCAP_SEG6 Date: Fri, 4 Dec 2026 18:51:35 +0900 Message-ID: <20261204100703.852478199@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason [ Upstream commit 58e39f8d58b141b96c030008a20dde9d625ec997 ] The mode BPF_LWT_ENCAP_SEG6 of bpf_lwt_push_encap() pushes an IPv6 header and an SRH, and it replaces the dst. The SRH says that IPv6 follows, and skb->protocol does not change. Thus the mode assumes an IPv6 packet, but an lwt_in prog also runs for IPv4 packets. After the prog, bpf_input() calls orig_input() of the old dst. This IPv4 handler reads the pushed headers as IPv4. It can write after the packet data, and the kernel crashes. after the push orig_input() expects --------------------- -------------------- skb->protocol ETH_P_IP ETH_P_IP dst rt6_info rtable packet | IPv6 | SRH | IPv4 | | IPv4 | The mode BPF_LWT_ENCAP_SEG6_INLINE returns -EBADMSG for non-IPv6 packets. Apply this check to both modes. End.BPF does not change, because seg6_local_input() drops non-IPv6 packets. Fixes: fe94cc290f53 ("bpf: Add IPv6 Segment Routing helpers") Signed-off-by: Chris Mason Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-17-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/filter.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/net/core/filter.c b/net/core/filter.c index 02419c79b3abb..50078e5549d79 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6461,11 +6461,15 @@ static int bpf_push_seg6_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len if (!seg6_validate_srh(srh, len, false)) return -EINVAL; + /* + * The encap mode names IPv6 as the inner protocol, and neither mode + * updates skb->protocol. + */ + if (skb->protocol != htons(ETH_P_IPV6)) + return -EBADMSG; + switch (type) { case BPF_LWT_ENCAP_SEG6_INLINE: - if (skb->protocol != htons(ETH_P_IPV6)) - return -EBADMSG; - err = seg6_do_srh_inline(skb, srh); break; case BPF_LWT_ENCAP_SEG6: -- 2.53.0