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=1795624039; b=c6uhM7L5abFsiZJxxfdXBM5EZ/AOjpHkyRDWV1HDVt8d85FNNOqKc8igAGxXNy8uRnCb DGrDRi4RpiKjCxrlVr3iXdUauRkP+e727pI5EhF9S1JwSQ8qryyupD5C4/hKA/eUGs7cy T3ByYnSlY06W/S3opLf7siyANvsmPwtyWTCf/lDX0cA7JfAAYoVoiXKR8JKHwgqf8mFYQ OOcBf16nrX8cxmkrBaGnMbfrjNLX97ENH/Wutwqv3tIzVhtlALWLaFRenWve88TIkRf9c 0vJu5PqyRct6oSeUCkgbabcNwaSI8SgDNKQFZo6CtvuZKc12kSW14/f34UBuFbfUdew== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624039; 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=5Lr/XnHGfzARulfEG8UNhyPTM5bWDTVs5tm7lHJw4Hc=; b=rbpiLHNCWG71auS5q7MbeCZwDqgdI+fpkFBE5yBmPhO9ARPjF8dIT8sLSmHnGEoT0VNP PW9E9mqstjkP17OnFVR5KFUR2btLCeP7kjAi71YCJiT4MHLrKX0SZcEjsdvrzHc+VnOdB WfwBN/NqXx69mdU2S71o9DsHRNyNSwWeAIM88e3b1gOZmEdip6scDZD4GX5jnzX0ir8T1 hhPLt6fEVIsAQOcRLdsoHoTciIrbIk/di1iBqWhV8M4HRN5ayhcLsWii+6KMpP3UJu1bC 23H3EzQIGbqxf7arRXb5xFyPb7QWhciuPW70W/9fyh6zHBtARgTB9QySKV5ei9h8IyQ== 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=JEueqrTO; 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 E1045606A323; Wed, 25 Nov 2026 16:27:18 +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=JEueqrTO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 043C41F000C0; Wed, 25 Nov 2026 16:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795624038; bh=5Lr/XnHGfzARulfEG8UNhyPTM5bWDTVs5tm7lHJw4Hc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JEueqrTO19A4bjJIRVGSrr/zylG7AcTJwgrmK1RFMrbX7TthflNQUWlxeg3hG73tQ UqggGebwmNRbJw2fq6Zm7bw+yQB0DgPCJljSq874z6aMx6jbhmamycEo8mwGHGCCyi se7APqVb5V3hsHbxbr0rsZUQR8YIopfBA622AnBE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hazley Samsudin , David Ahern , Hangbin Liu , Andrea Mayer , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12 065/816] seg6: fix transport header for inner IPv4 with IP options Date: Wed, 25 Nov 2026 15:26:53 +0100 Message-ID: <20261125143850.726144364@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143849.205329330@linuxfoundation.org> References: <20261125143849.205329330@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Mayer [ Upstream commit 5838f10563d58afca6711edb5e4eda968ca181d9 ] The End.DT4, End.DT46 (its IPv4 path only) and End.DX4 behaviors set the transport header of the decapsulated IPv4 packet at a fixed 20 bytes, the size of an IPv4 header without options. They do not validate the header length either. With options, the transport header points at the first option byte. The effects include: - ping -R sends an echo request with a 60-byte IPv4 header to a local address through an End.DT4 or an End.DX4 SID. Since icmp_rcv() computes the ICMP checksum from the first option byte, the request fails the check and is counted in IcmpInCsumErrors. - A UDP datagram can reach a port that an iptables rule drops. The rule checks the UDP header after the full IPv4 header, while the socket lookup reads it at the fixed 20-byte offset. - With an inbound AH state, ah_input() reads the AH header at the fixed 20-byte offset, but copies the IPv4 header over it with the length in the IHL field. A packet shorter than that length can make ah_input() write past the end of the data, into skb_shared_info when the skb has no tailroom. Validate the inner IPv4 header length with the new helper seg6_validate_iphdr_len() and set the transport header at that length. A packet that is not IPv4, whose header length field is below 5, or whose header is truncated, is dropped with a drop reason. The fix is limited to the header length, which the transport header relies on. Other checks done on IPv4 input, such as the header checksum, the total length and the IP options, are not addressed here. Found by code inspection while reviewing commit 44930446dde4 ("ipv6: seg6: clear IPv4 control block on IPIP decapsulation"), as a pre-existing issue that Sashiko also reported on v2 of that patch. Without this patch, a bpftrace probe on ah_input() shows the reporter's reproducer packet written into skb_shared_info. With it, that packet is dropped before ah_input(), ping -R no longer fails the ICMP checksum, the UDP datagram reaches its real port, and the SRv6 selftests still pass. These effects reproduce on an unmodified kernel, without error injection. Fixes: 891ef8dd2a8d ("ipv6: sr: implement additional seg6local actions") Fixes: 664d6f86868b ("seg6: add support for the SRv6 End.DT4 behavior") Reported-by: Hazley Samsudin Closes: https://lore.kernel.org/netdev/20260809221915.2ffc1ecd0f445fcb70270e31@uniroma2.it/ Reviewed-by: David Ahern Reviewed-by: Hangbin Liu Signed-off-by: Andrea Mayer Link: https://patch.msgid.link/20261028171511.35-1-andrea.mayer@uniroma2.it Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv6/seg6_local.c | 69 +++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index 9259b2d2da059..7c0d98a65c8b7 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -149,9 +149,7 @@ struct seg6_end_dt_info { int vrf_ifindex; int vrf_table; - /* tunneled packet family (IPv4 or IPv6). - * Protocol and header length are inferred from family. - */ + /* tunneled packet family (IPv4 or IPv6) */ u16 family; }; @@ -969,6 +967,40 @@ static int input_action_end_dx6(struct sk_buff *skb, return -EINVAL; } +/* Validate the length of the IPv4 header at skb->data (which must point to + * the network header) and report that length, options included. + * Only the version, the header length and the presence of the whole header + * are checked. + * The length is written only when SKB_NOT_DROPPED_YET is returned. + * + * skb pointers may change: after this call, the caller must evaluate again + * any pointer into the packet data. + */ +static enum skb_drop_reason +seg6_validate_iphdr_len(struct sk_buff *skb, int *hdrlen) +{ + enum skb_drop_reason reason; + const struct iphdr *iph; + int len; + + reason = pskb_may_pull_reason(skb, sizeof(struct iphdr)); + if (reason) + return reason; + + iph = ip_hdr(skb); + if (iph->version != 4 || iph->ihl < 5) + return SKB_DROP_REASON_IP_INHDR; + + len = ip_hdrlen(skb); + + reason = pskb_may_pull_reason(skb, len); + if (reason) + return reason; + + *hdrlen = len; + return SKB_NOT_DROPPED_YET; +} + static int input_action_end_dx4_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { @@ -998,14 +1030,18 @@ static int input_action_end_dx4_finish(struct net *net, struct sock *sk, static int input_action_end_dx4(struct sk_buff *skb, struct seg6_local_lwt *slwt) { + SKB_DR(reason); + int hdrlen; + if (!decap_and_validate(skb, IPPROTO_IPIP)) goto drop; - if (!pskb_may_pull(skb, sizeof(struct iphdr))) + reason = seg6_validate_iphdr_len(skb, &hdrlen); + if (reason) goto drop; skb->protocol = htons(ETH_P_IP); - skb_set_transport_header(skb, sizeof(struct iphdr)); + skb_set_transport_header(skb, hdrlen); nf_reset_ct(skb); if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) @@ -1015,7 +1051,7 @@ static int input_action_end_dx4(struct sk_buff *skb, return input_action_end_dx4_finish(dev_net(skb->dev), NULL, skb); drop: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return -EINVAL; } @@ -1150,16 +1186,24 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff *skb, struct seg6_end_dt_info *info = &slwt->dt_info; struct net_device *vrf; __be16 protocol; + SKB_DR(reason); int hdrlen; vrf = end_dt_get_vrf_rcu(skb, info); if (unlikely(!vrf)) goto drop; + if (unlikely(info->family != AF_UNSPEC && info->family != family)) { + pr_warn_once("seg6local: SRv6 End.DT* family mismatch"); + goto drop; + } + switch (family) { case AF_INET: protocol = htons(ETH_P_IP); - hdrlen = sizeof(struct iphdr); + reason = seg6_validate_iphdr_len(skb, &hdrlen); + if (unlikely(reason)) + goto drop; break; case AF_INET6: protocol = htons(ETH_P_IPV6); @@ -1171,11 +1215,6 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff *skb, goto drop; } - if (unlikely(info->family != AF_UNSPEC && info->family != family)) { - pr_warn_once("seg6local: SRv6 End.DT* family mismatch"); - goto drop; - } - skb->protocol = protocol; skb_dst_drop(skb); @@ -1186,7 +1225,7 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff *skb, return end_dt_vrf_rcv(skb, family, vrf); drop: - kfree_skb(skb); + kfree_skb_reason(skb, reason); return ERR_PTR(-EINVAL); } @@ -1199,9 +1238,7 @@ static int input_action_end_dt4(struct sk_buff *skb, if (!decap_and_validate(skb, IPPROTO_IPIP)) goto drop; - if (!pskb_may_pull(skb, sizeof(struct iphdr))) - goto drop; - + /* end_dt_vrf_core() validates the inner IPv4 header length */ skb = end_dt_vrf_core(skb, slwt, AF_INET); if (!skb) /* packet has been processed and consumed by the VRF */ -- 2.53.0