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=1796379652; b=SdXjU/zY2qR97dskGlccnYgt6HGpNbBZkkxqId/Y8zXWMTe/+QwarNxnXzHzfOcC75R0 x0jNY4jl/uCZAGncrE0mi4+ymrA/gi2OG7LMsKMvqAkglQFbuGvQZ1vWR7uqoLUYT/Vl6 w807x9+4T46Zjdvc/4R8A1+CI8Y8W9Tjbg36B+dDI+n+VCV4MrFO74EVlA5r2owYcps5B qV0oNeCeJoeRT37yV7NOY3mFfeDlg8D3kTC/Vv1BueDctjR1NWD/9xoAm12VUxRyg8vI0 4SXXF+PmfngogtiZ4nwPqOcPq7CbsmFlZndUTAW5SsXVZBLUGSwL0trxcHIDie4w2Rg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379652; 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=kZ4RjucLk/C9SqxzxAEJcugaw9ksqO0E1QdieciWClo=; b=c21hXjSfsRjdxL5gBljnNhrzqtFJNoqB+zexkyWVFQrridIMZloEjCitLpw1KCLjhI5n SrxMEFbW+QDvVOewpIC/TUkaZ57Lhfh/98I7qnergIgTXHEd92WhrrPsNiq96XaONbOc/ adNtfiV0sMNpGVqWRfTIgC1C1dr0BbOGJIDXY51g6t4Xnkq3X9+C1ErIfPDv0qVSyfvr7 d+bGaDjWP2UDhLr9dCtxYtnpy2LigAiDaRQ/9lXKhjkzKfHGbV4UOqe/xaM6FQeamD9g+ 2EZl84CHXoFGYK6xSC8IhXDm53hks2lciHIFoPl9Bf3wWoJVyvEEeznXVXQNFNTs2qw== 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=vNYe1wyb; 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 59CBF606A322; Fri, 4 Dec 2026 10:20:52 +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=vNYe1wyb Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8181F1F00897; Fri, 4 Dec 2026 10:20:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379651; bh=kZ4RjucLk/C9SqxzxAEJcugaw9ksqO0E1QdieciWClo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vNYe1wyb+/fiFbMdWLDMYvfBEm/bBXpHrfone5wQwgXyFQZ4cdIi0BlTLL2CVorkF gYnK5CArjje4XBcdX0kArT7q8m5rTwjxNNoS89N6W2QXbEfnKRshu010ntuLKzfk+E f4fF2qls0RU5fCabE023p/4V3tYoXepZLsnzJytY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0055/1059] bpf: Require BPF_LWT_REROUTE when an lwt_in prog changes the protocol Date: Fri, 4 Dec 2026 18:53:06 +0900 Message-ID: <20261204100645.503572802@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: patches@lists.linux.dev 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: Alexei Starovoitov [ Upstream commit d9618a6196953718f7470de5d2e84121bed063f7 ] When an lwt_in prog returns BPF_OK, bpf_input() calls orig_input(), the input handler of the route. This handler is for one IP version and needs a dst of the same family. But BPF_LWT_ENCAP_IP lets the prog push a header of the other IP version and thus change skb->protocol. Then the handler reads and changes a header of the other IP version. The push of an SRH also replaces the dst, because seg6_lookup_nexthop() puts an rt6_info into the skb. Then ip_forward() uses the rt6_info as a struct rtable. Drop the skb with -EINVAL when skb->protocol changes, as bpf_xmit() does. Drop it also when the family of the dst changes, because skb->protocol does not always show this change. Today no such skb leaves as the prog made it. A prog works as before if it returns BPF_LWT_REROUTE, or if it pushes an SRH on an IPv6 route. The commit in the first Fixes tag lets a prog change skb->protocol. The commit in the second tag adds the check to bpf_xmit() only. Fixes: 52f278774e79 ("bpf: implement BPF_LWT_ENCAP_IP mode in bpf_lwt_push_encap") Fixes: 3bd0b15281af ("bpf: add handling of BPF_LWT_REROUTE to lwt_bpf.c") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-24-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/lwt_bpf.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c index fde1b4a2f4aac..87fae6fdeeba8 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -157,6 +157,16 @@ static int bpf_input(struct sk_buff *skb) bpf_lwt_reset_cb(skb, proto); if (ret == BPF_LWT_REROUTE) return bpf_lwt_input_reroute(skb); + /* + * orig_input() is for the old protocol only, see bpf_xmit(). + * It also needs a dst of the old family. BPF_LWT_ENCAP_SEG6 + * puts an IPv6 dst into the skb. + */ + if (skb->protocol != proto || + skb_dst(skb)->ops->family != dst->ops->family) { + kfree_skb(skb); + return -EINVAL; + } } if (unlikely(!dst->lwtstate->orig_input)) { -- 2.53.0