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=1796379634; b=Y1KWCH56G3Y+1fTMjndnC6zAAyqnkwxQiZAxGh4YrG3LNKGejHa+vVhRcZw4hoWnz/DE sC+nemg+Do9XgaiepVfIemyyCmR+eElywKcVyMz7v9on+fLeFITNo+4wNgu2ovM5LHicr N+L1LNxslNB1Nq8zmx9ZE602GnzJnlpL7c6tuMkruiTmOiRs//O9Hg04l59xHpXMem/kf hLI5qtR8PUqmKfyFta4NmDK/RPctpZu9Ao+fculxyW8ILDR/mw6rkdA/dMGuo73k3qXea Mk/2KPk8lkgbO/rgquNRWyEO8sbHwLtj6qdUThFze//1FFLBrgKKCbbinAjKkEkAIVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379634; 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=072pGTDHBClxYzeYt5hwwiZSH3muz+6/r+R+uk3424A=; b=gJg/eWm5C6xSg5Hd6BrGM4+7KseDo8hHtNMnHkazwG7iQPsrhJo9GbGCGQivqOchAW8I gC8utKlDLw7kGd6neDcncXW1fJz3rqt2jcE/JKHmBq3MKXM5X6vZzVgESLE+dG2B+BgIr PfO+ahkO5C1dTEWczvmiYdl/sa5M5xBrvEk42IbfGn31IrxFSLrqxxLsVJJ9Z0B7G7dyo BPz+n3QssvK+UDLc/ZiyJ/myKj24FzgzDQERi6Ov/tsKqUDjkedU+Ayju//7ZvSL2MssY MYA5oPJGsaafV1kwiwIgD2u/xfdNxvmAo5AAeX7yjWEh9nL8nKUb84bW+CfNR1L7gaA== 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="vTxJlY/J"; 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 2F432606A322; Fri, 4 Dec 2026 10:20:33 +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=vTxJlY/J Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B9B21F000C2; Fri, 4 Dec 2026 10:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379633; bh=072pGTDHBClxYzeYt5hwwiZSH3muz+6/r+R+uk3424A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vTxJlY/JzIGsWSwjbjhxIPIAhGX79Ard7xV6qzb/Ly70RcdQMbNHiJzTC1RNh3ONb Pikg76ZM8anl+uO59gCiRwluE+Zv0jdN7AMeLRwLdkxoUfvM99jg9KhpdrViY7O1B4 MAyfKEnXwz5jtFDQqj5EUnmcOynpEryD1FCNH34E= 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.1 0047/1059] bpf: Reject non-IPv6 packets in BPF_LWT_ENCAP_SEG6 Date: Fri, 4 Dec 2026 18:52:58 +0900 Message-ID: <20261204100645.278781341@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 b3582a59e3dda..b480d4d17f47c 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6381,11 +6381,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