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=1796379641; b=j32/zSrGcFChcNk8xUsPmHN2VxQsaS6snlw4Wx+bqmrVAVjvxK6HQu/Itec0Gk7OvZAh NEBD39d6u1GiwtQFiKtfe5vnCkQMLey+wdio2UxyGZt8K2B4Nmd6BCaY4f+dsax+Gt5Z0 W4WrKNB/XDY3FW71lA/6eULDD6QgDZ+0/bKObqCC3P7MKjMrBks82kRQpURGXGnObMcni AYYF20P9VzvohMaWtIYgtvl9OzwYp3LpZ2n5ZOs1tvU2TrhTBDjSfjhukvUuV9+mjyDsr mNkwXwTRjI6dSaJ7uusKtGuUYdNxsBxqoOUk65Tj3WTDxDZpif+Uf7LtX76elXoQa+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379641; 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=jFC4471L6DYo9as2wkwb0YPStP2wW1f5sYpHyC7wEuY=; b=qEHxnhamqDaNi2ti53CsJ9fA64kZIjvk/qoNOaQIjzcZiJMhLnBOYhkXmfB5Eq1q6hPh 7DasNBm3ZXG2Bl9phpdGuqOKtRX41mIKxiFYqtglzk3BN2JfZX33IqZDjRkvwbHi9UePx +4IVGkSZaU9/w+cxuM4eNoyO0xPuIdxC5OMW0PkxqK7RZQ2LJegdusTcBoo+aAs9GX+NT Pw81jHWf99c8ZN+WvUtw4eXMuL2+2ZMRSJN/AJ5GlfQIgzNjDxZZSei7Cidl9q5k3fAOd v0rN88xnqqoYMT0x35Va1bYMPN14+oOHNHhaHXzowLQpeuBWyAkrx2OqASjnxnyER8g== 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=WcXbR0hg; 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 E92A2606A322; Fri, 4 Dec 2026 10:20:40 +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=WcXbR0hg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 654951F000CE; Fri, 4 Dec 2026 10:20:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379640; bh=jFC4471L6DYo9as2wkwb0YPStP2wW1f5sYpHyC7wEuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WcXbR0hgfmTBCTUB7kGvu9g4y6gAAaqky31n2CR5GHqVAY8AkT7CnWexMgBbYAfbk LNCAuET/EiBZKdKOW2woJUkP27J+Lb+44xIx1hfxuvBdbaO+ZpPbHo7gaTAIPxrIM9 bOw7opXo3+JeC/QSElcqaIWgdCjstxJIntwN+y2M= 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 0050/1059] bpf: Move the MAC header in bpf_lwt_seg6_adjust_srh() Date: Fri, 4 Dec 2026 18:53:01 +0900 Message-ID: <20261204100645.361475194@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: Chris Mason [ Upstream commit 0fcb3f11a93d740e7f9ae1aeb48fe4d25838be18 ] bpf_skb_net_hdr_push() and bpf_skb_net_hdr_pop() change skb->data and skb->mac_header by len. That is correct in a tc prog, where skb->data is the MAC header. But bpf_lwt_seg6_adjust_srh() calls them in an End.BPF prog, where skb->data is the network header. The MAC header does not move: before push | free | MAC header | IPv6 | SRH | payload ^ head ^ mac_header ^ data today | free | MAC h| IPv6 | SRH + len | payload ^ head ^ mac_header ^ data this patch | free | MAC header | IPv6 | SRH + len | payload ^ head ^ mac_header ^ data Users of skb_mac_header() get incorrect bytes until __dev_queue_xmit() sets skb->mac_header again. skb_cow_head() reserves only len bytes. Thus the 16-bit offset skb->mac_header can wrap. A push also changes the "not set" value. In both cases skb_mac_header() points after the skb. Move the MAC header too. Pass len + skb->mac_len to skb_cow_head(). Keep the "not set" value. The second Fixes tag is for this case. Since that commit an End.BPF prog can get an skb with skb->mac_header not set. Fixes: fe94cc290f53 ("bpf: Add IPv6 Segment Routing helpers") Fixes: 20a081b7984c ("seg6: add VRF support for SRv6 End.DT6 behavior") Signed-off-by: Chris Mason Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261101190535.1454146-21-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/filter.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index c3b8561433a85..bbf96dfbcb95b 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -6611,6 +6611,7 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, { struct seg6_bpf_srh_state *srh_state = this_cpu_ptr(&seg6_bpf_srh_states); + bool mac_set = skb_mac_header_was_set(skb); struct ipv6_sr_hdr *srh = srh_state->srh; void *srh_end, *srh_tlvs, *ptr; struct ipv6hdr *hdr; @@ -6635,20 +6636,38 @@ BPF_CALL_3(bpf_lwt_seg6_adjust_srh, struct sk_buff *, skb, u32, offset, if (unlikely(len > (U8_MAX << 3) - srh_state->hdrlen)) return -EFAULT; + /* + * skb->data is the network header here. The MAC header is in front of + * it, so bpf_skb_net_hdr_push() and bpf_skb_net_hdr_pop() do not move + * it with the other headers. + */ if (len > 0) { - ret = skb_cow_head(skb, len); + ret = skb_cow_head(skb, len + skb->mac_len); if (unlikely(ret < 0)) return ret; + /* The push can write over the MAC header, so move it first. */ + if (mac_set) + memmove(skb->data - len - skb->mac_len, + skb_mac_header(skb), skb->mac_len); ret = bpf_skb_net_hdr_push(skb, offset, len); } else { ret = bpf_skb_net_hdr_pop(skb, offset, -1 * len); + /* The pop has added -len to skb->mac_header. */ + if (likely(!ret) && mac_set) + memmove(skb->data - skb->mac_len, + skb_mac_header(skb) + len, skb->mac_len); } bpf_compute_data_pointers(skb); if (unlikely(ret < 0)) return ret; + if (mac_set) + skb_set_mac_header(skb, -skb->mac_len); + else + skb_unset_mac_header(skb); + hdr = (struct ipv6hdr *)skb->data; hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); -- 2.53.0