From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D5734CA789; Mon, 31 Aug 2026 14:04:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788185098; cv=none; b=mOSO/7p9UoNgOc4PwcVJW/dGwD9TQPj1Y4mXXvno96g2UbNxevbwnWrCq7oPRskzEHXISUpLBHLDhDAwa7G1IjJpQ9RkaQ2DrCR46gb+SsGOo1vQvwj7xLLn0VTPuJYQbtMet/TnIZYTjFKB9VZzZzJhb7lnDZ3G1rbSlDhAkAU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788185098; c=relaxed/simple; bh=iEZ2PudzzcgMeyh4X7/TO3PSTZds6G3sYgtl4xBVggY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C0gTISlmv/VodYGlVGjrqHa8YPXxyU3DPk/JI6avgBYRg1JGDfCfIKjsuld4rrUpcgYnJbLsIkk8MiNUk+n1VYeXrrazC9n/1RdcB9h23HX96SdEgDGIivPWypGPZ6gEx7Gb9WYQhc1xKD5MRxZBbckAg9b5LcaEIwkjpyCWmZs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BoOk/Ta9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="BoOk/Ta9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 784DE1F000E9; Mon, 31 Aug 2026 14:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788185096; bh=3Qp1pwB3aAE3EN0So9VGq4Ab2k2OXrKNoAP8L5NEOdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BoOk/Ta9FV4GqHFmoONv6l/qqNjnSP97IUKygHUsx1wm2oIVlTIwfi1FOE78a7r6D TCmOL032sEJ05ZbKVj7QU8nHYoGt66mqOAP0BOaGzXqX/pGmTiL5W6ZO4NzUYmM6w5 hV+iie6XAZtWhwbFYstd9wbPlOPLMc3kzeSIAogk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Asim Viladi Oglu Manizada , Steffen Klassert Subject: [PATCH 5.15 52/69] xfrm: ah6: validate routing header segments_left Date: Mon, 31 Aug 2026 15:35:25 +0200 Message-ID: <20260831133401.293039666@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260831133358.601894154@linuxfoundation.org> References: <20260831133358.601894154@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Asim Viladi Oglu Manizada commit 7bad4bda74dc4713f398d3b7624ff05478e3a568 upstream. AH6 rearranges routing-header addresses before computing or verifying the ICV. ipv6_rearrange_rthdr() assumes that segments_left is not larger than the number of addresses described by the routing header's hdrlen field. That assumption does not hold for raw IPv6 HDRINCL packets. A packet with hdrlen equal to 2 describes one address, but can carry an arbitrary segments_left value. With segments_left equal to 255, the function moves its address pointer 4,064 bytes backwards and passes a 4,064-byte length to memmove(), resulting in an out-of-bounds access. Validate the invariant locally before modifying the routing header or performing any address-pointer arithmetic, and propagate malformed-header errors to the existing AH6 input and output error paths. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: avom-custom-harness:gpt-5.5-qwen3.6-mod-mix Signed-off-by: Asim Viladi Oglu Manizada Signed-off-by: Steffen Klassert Signed-off-by: Greg Kroah-Hartman --- net/ipv6/ah6.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) --- a/net/ipv6/ah6.c +++ b/net/ipv6/ah6.c @@ -235,26 +235,28 @@ static void ipv6_rearrange_destopt(struc * Rearrange the destination address in @iph and the addresses in @rthdr * so that they appear in the order they will at the final destination. * See Appendix A2 of RFC 2402 for details. + * + * Return: 0 on success, -EINVAL if segments_left exceeds the number of + * addresses described by hdrlen. */ -static void ipv6_rearrange_rthdr(struct ipv6hdr *iph, struct ipv6_rt_hdr *rthdr) +static int ipv6_rearrange_rthdr(struct ipv6hdr *iph, struct ipv6_rt_hdr *rthdr) { - int segments, segments_left; + unsigned int segments, segments_left; struct in6_addr *addrs; struct in6_addr final_addr; segments_left = rthdr->segments_left; if (segments_left == 0) - return; - rthdr->segments_left = 0; + return 0; - /* The value of rthdr->hdrlen has been verified either by the system - * call if it is locally generated, or by ipv6_rthdr_rcv() for incoming - * packets. So we can assume that it is even and that segments is - * greater than or equal to segments_left. - * - * For the same reason we can assume that this option is of type 0. + /* Raw locally generated packets can reach AH6 without the invariant + * required by the rt0-style address rearrangement below. */ segments = rthdr->hdrlen >> 1; + if (segments_left > segments) + return -EINVAL; + + rthdr->segments_left = 0; addrs = ((struct rt0_hdr *)rthdr)->addr; final_addr = addrs[segments - 1]; @@ -264,6 +266,8 @@ static void ipv6_rearrange_rthdr(struct addrs[0] = iph->daddr; iph->daddr = final_addr; + + return 0; } static int ipv6_clear_mutable_options(struct ipv6hdr *iph, int len, int dir) @@ -276,6 +280,7 @@ static int ipv6_clear_mutable_options(st } exthdr = { .iph = iph }; char *end = exthdr.raw + len; int nexthdr = iph->nexthdr; + int err; exthdr.iph++; @@ -295,7 +300,9 @@ static int ipv6_clear_mutable_options(st break; case NEXTHDR_ROUTING: - ipv6_rearrange_rthdr(iph, exthdr.rth); + err = ipv6_rearrange_rthdr(iph, exthdr.rth); + if (err) + return err; break; default: