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=1796387728; b=RvfTu1463kt3o8T0/OTNyt8luAF2sUHHHfSZLbSLxyTfi56UbNd4J0yKK4hzL4dUouh5 ipjo33Arj2iKgY8prXo4Zw9ibU6HmWXOVi7fuWRnidQooJP8wcvb/C3yp9FI1V7096d/J UsZBk1Dagesdbiq8D4HnqXzvigguisrrNmVbNphSx2rNOqB5G0bZ2ApMOOu7gCyMww34g O3CMOYDLMeMItgMMbkxhPA3fH9MxBFq4ebiQcykSt0jwc2N9Kde2xra53DSxC9JN3oWhE i331fr/86y16TYxdbiqCyhGtCZX09/yGXK/frfizWjX8w2E565iA7p2pgyqIRYPxWig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387728; 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=tW9kcjzREf8zkENAN44wOTjGNjdKyTDDnICOuj5qeVA=; b=HqABHt3sifCPc9RDcIKS+cTKc+5KoiJb7DfXypI4bAtbZG6TAr3udKfM5E2Ir2OmYWMu N/pS63ncxaLS2105Cy0MTn0hPfUQmw3gw/CBB7P/O7fh0IOM1L8LYQNQG7WElpv2XD4Wv CbevcNzv3WXtHvmxkKSbbc8qqemO4pZQQR7maGUcDgRpDb0i4Owcm6pwCuAv7QqspqrrE t6PtX/OG6VXMX99N0xXpZZXuUJEZ2vbMc7DIS45RvNwrhSEEJovgNEOKfVC5PMtGXfEc/ ZWLsn63xevE82jUN0smuwfb7qszWCq5II2CaXCUjP5YMChwscRG14z7CmQOl2yaQufA== 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=ZydiDyUN; 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 08CFC606A322; Fri, 4 Dec 2026 12:35:28 +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=ZydiDyUN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 216041F000CE; Fri, 4 Dec 2026 12:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387727; bh=tW9kcjzREf8zkENAN44wOTjGNjdKyTDDnICOuj5qeVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZydiDyUNTqUrn9NizrlLFYXR7HG3+suvioSFzSB3KTofJOLAuzoUu/YU4z2diyy8k R7Ss5zUEHWNYHW6Teee7MxJL3eYnP+8irJM3S/jKqzmlMUOssEu2E6F6B6I9injg6o HJHmYhlFQAdGrSfL7PhoEo4oRwDSMCpmM6eU8XTE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuya Kusakabe , Andrea Mayer , Paolo Abeni , Sasha Levin Subject: [PATCH 6.1 0324/1059] seg6: fix HMAC validation when an extension header precedes the SRH Date: Fri, 4 Dec 2026 18:57:35 +0900 Message-ID: <20261204100652.661416137@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: Yuya Kusakabe [ Upstream commit f9cb4d296d81adb0923546ca5d54fae57a81af52 ] seg6_hmac_validate_skb() derived the SRH from skb_transport_header(). That only holds while the two coincide, which is not true on the seg6_local input path. ip6_rcv_core() leaves the transport header just past the IPv6 header. A Hop-by-Hop options header is consumed before the route lookup and advances it, but a Destination Options header is not: the seg6_local lwtunnel is entered through an input redirect from the route lookup, which bypasses the extension header handlers. The transport header then still points at the Destination Options header while seg6_get_srh() has located the real SRH further down the chain. The HMAC is therefore computed over the Destination Options header, and a packet carrying a valid HMAC TLV is dropped when seg6_require_hmac is set. Such a packet is legitimate: RFC 8200 allows Destination Options before a routing header, and get_srh() has walked the header chain since commit 5829d70b0b6c ("ipv6: sr: fix get_srh() to comply with IPv6 standard "RFC 8200""). With a Fragment or an Authentication header in front of the SRH, the same mistake also reads past the data pulled by seg6_get_srh(). This happens before seg6_require_hmac is read, so the default configuration is affected. Reproduce by giving a node a seg6local End SID with net.ipv6.conf..seg6_require_hmac=1 and a key installed with "ip sr hmac set sha1", then sending IPv6 -> Destination Options -> SRH (carrying a valid HMAC TLV) -> payload to that SID: it is dropped, while the same packet without the Destination Options header passes. Fixes: 5829d70b0b6c ("ipv6: sr: fix get_srh() to comply with IPv6 standard "RFC 8200"") Assisted-by: LLM Signed-off-by: Yuya Kusakabe Reviewed-by: Andrea Mayer Link: https://patch.msgid.link/20260926-b4-seg6-hmac-transport-header-v2-1-8087b76f6375@gmail.com Signed-off-by: Paolo Abeni [ sashal: Dropped the end_flv8986_core() call-site hunk since that function doesn't exist here, and took this tree's seg6_local.c, changing only the two existing seg6_hmac_validate_skb() calls. ] Signed-off-by: Sasha Levin --- include/net/seg6_hmac.h | 3 ++- net/ipv6/exthdrs.c | 2 +- net/ipv6/seg6_hmac.c | 5 +---- net/ipv6/seg6_local.c | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/net/seg6_hmac.h b/include/net/seg6_hmac.h index 24f733b3e3fe9..0544e0595ff5d 100644 --- a/include/net/seg6_hmac.h +++ b/include/net/seg6_hmac.h @@ -48,7 +48,8 @@ extern int seg6_hmac_info_add(struct net *net, u32 key, extern int seg6_hmac_info_del(struct net *net, u32 key); extern int seg6_push_hmac(struct net *net, struct in6_addr *saddr, struct ipv6_sr_hdr *srh); -extern bool seg6_hmac_validate_skb(struct sk_buff *skb); +extern bool seg6_hmac_validate_skb(struct sk_buff *skb, + struct ipv6_sr_hdr *srh); #ifdef CONFIG_IPV6_SEG6_HMAC extern int seg6_hmac_init(void); extern void seg6_hmac_exit(void); diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c index d7e307aa6b020..523190563d94c 100644 --- a/net/ipv6/exthdrs.c +++ b/net/ipv6/exthdrs.c @@ -393,7 +393,7 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev) } #ifdef CONFIG_IPV6_SEG6_HMAC - if (!seg6_hmac_validate_skb(skb)) { + if (!seg6_hmac_validate_skb(skb, hdr)) { kfree_skb(skb); return -1; } diff --git a/net/ipv6/seg6_hmac.c b/net/ipv6/seg6_hmac.c index e784f539194ad..6e6a7fec872f2 100644 --- a/net/ipv6/seg6_hmac.c +++ b/net/ipv6/seg6_hmac.c @@ -234,21 +234,18 @@ EXPORT_SYMBOL(seg6_hmac_compute); * * called with rcu_read_lock() */ -bool seg6_hmac_validate_skb(struct sk_buff *skb) +bool seg6_hmac_validate_skb(struct sk_buff *skb, struct ipv6_sr_hdr *srh) { u8 hmac_output[SEG6_HMAC_FIELD_LEN]; struct net *net = dev_net(skb->dev); struct seg6_hmac_info *hinfo; struct sr6_tlv_hmac *tlv; - struct ipv6_sr_hdr *srh; struct inet6_dev *idev; idev = __in6_dev_get(skb->dev); if (!idev) return false; - srh = (struct ipv6_sr_hdr *)skb_transport_header(skb); - tlv = seg6_get_tlv_hmac(srh); /* mandatory check but no tlv */ diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index 5b1418f7c062c..7f56f9ad1317d 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -209,7 +209,7 @@ static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb) return NULL; #ifdef CONFIG_IPV6_SEG6_HMAC - if (!seg6_hmac_validate_skb(skb)) + if (!seg6_hmac_validate_skb(skb, srh)) return NULL; #endif @@ -226,7 +226,7 @@ static bool decap_and_validate(struct sk_buff *skb, int proto) return false; #ifdef CONFIG_IPV6_SEG6_HMAC - if (srh && !seg6_hmac_validate_skb(skb)) + if (srh && !seg6_hmac_validate_skb(skb, srh)) return false; #endif -- 2.53.0