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=1795624701; b=xhsMjLXERKJqhcFfHz58LNmbLza4xDL6q1XnrweqsTyizb6eUST25XdtHzFSxVsuQogD XMo9sspcZK4BxD1TW3GjgdL9BghR86YSBfHPDfsVRwaYuIg+tXLL7pXJCx8rj4cdhQDBJ g+o3zEU5Gl/Q+FPbY7sPaW/AJBnHfw4gjb3MSQnr6nZd0WCpzAPPMmZsYSMnYPqWgxgFO I2ekwBft/TcozXtopC9oit8cFyFIVeWqCV1p9R4ry1ktQRvlJ+LLf+YJbLo/KlaULX9y1 JfpZq7Edy8H7efaslnTuifqKemPUuivN5ilGkvz1v4CthyV9fZ5Ppm6i/8ejyxUla9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795624701; 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=GjXRqf4DOBEvWrqM+e3IztIvS5Lz5yRAnAPaiaLByIQ=; b=YPMVYcLMU6pks4u1hcLiiO+HT2fTLKvLUC0PnJ82n6C5Co7G0NJF12m9b1XGKeJIfWSS c+sV1yQ05fMtDPSq5BwTy4DigaJQGhMDxdVKYQrzIol5Ed+noZ2ZX6/98HtD0bjYFv4Ky xguAxL6A4l5SD2ampQnjaa/HVvg8g5CAIrWIpuEE/0WNrA9svBYPI6zWn6zyfjd1ieSmi upWr+1Kb+LU26esuKLjNz+f7vyS9ks+vP9g/o8D/e04q9i78p4fgdApj38g03t8IqxeBn wzvMF0gYL1ZQOIKQKZH5uXfHyTw13bMcn9AnaW2+CW2DHWZWNDfnMYk3YzJQzcctiXw== 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=Eks5aUVx; 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 5E49F606A33B; Wed, 25 Nov 2026 16:38:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Eks5aUVx Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0B761F000C0; Wed, 25 Nov 2026 16:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795624701; bh=GjXRqf4DOBEvWrqM+e3IztIvS5Lz5yRAnAPaiaLByIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Eks5aUVxJK/SLseVe+pzOy0PTP9FbVQGxXXJUxDuMcJDIRcMslw2z39e95tjwAsRv wwfIO9+QKSCKshjnTLs50SiJDWH6+1x+OCairnUbSPGlr+BNkjLsMkJGwgPcbj4xFa vCQy2i1hTybCB9LKBs5fFFHkse8M7kK1lnbPLKf0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Ido Schimmel , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12 272/816] ipv6: Check the Home Address option again before its address is used Date: Wed, 25 Nov 2026 15:30:20 +0100 Message-ID: <20261125143855.507933766@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: Alexei Starovoitov [ Upstream commit 30c71476d842b094651bd7712f6c8ee8716147d0 ] ipv6_dest_hao() checks the Home Address option and sets IP6CB(skb)->dsthao to the offset of the destination options header. Later mip6_addr_swap() and mip6_destopt_reject() call ipv6_find_tlv() with that offset and use the 16 address bytes. They assume that the same header is still there. But the seg6 and ioam6 lwtunnels, the End.B6 actions, ipv6_rpl_srh_rcv() and BPF lwt progs move or rewrite the IPv6 headers and keep IP6CB(skb). Then ipv6_find_tlv() parses other bytes. It returns when the type matches, before it checks that the option is inside the header. Nobody checks the length of the option again. Thus mip6_addr_swap() can write after the data of the skb. mip6_destopt_reject() can copy that memory to an xfrm report. In ipv6_find_tlv(), check the length of an option before its type. The returned option is then inside the header, and the header is inside the linear data. In both callers, ignore an option with a length other than 16, as if ipv6_find_tlv() found none. Then the ICMPv6 error goes to the source address of the IPv6 header, and the xfrm report has no XFRMA_COADDR attribute. Nothing changes for a header that ip6_parse_tlv() accepted and that is still in its place. For the other callers an incomplete option is now absent: - ip6_find_1stfragopt() and mip6_rthdr_offset() can return another offset for the fragment header or the xfrm header, also in a forwarded packet. - calipso_skbuff_optptr() returns NULL. netlbl_skbuff_getattr() and netlbl_cache_add() then see no option. calipso_skbuff_delattr() returns 0 and the packet continues unchanged. Today it returns -EINVAL and SELinux drops the packet. It already returns 0 when an earlier option is incomplete. The receiver drops such a header in ip6_parse_tlv(). The code that moves the headers still does not reset the offset or the other fields of IP6CB(skb). If the bytes there look like a header with a Home Address option of length 16, both callers still use its address. The first tag also covers ipv6_find_tlv(), because its early return did no harm before mip6_addr_swap(). The second tag is for mip6_destopt_reject(). Fixes: 793832361fe7 ("[IPV6] MIP6: Revert address to send ICMPv6 error.") Fixes: 70182ed23d25 ("[IPV6] MIP6: Report to user-space when home address option is rejected.") Signed-off-by: Alexei Starovoitov Reviewed-by: Ido Schimmel Link: https://patch.msgid.link/20261102064922.2636027-1-alexei.starovoitov@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv6/exthdrs_core.c | 7 ++++--- net/ipv6/icmp.c | 7 ++++++- net/ipv6/mip6.c | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c index ce3724f49e33a..f5b6e25580e83 100644 --- a/net/ipv6/exthdrs_core.c +++ b/net/ipv6/exthdrs_core.c @@ -135,9 +135,6 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type) int opttype = nh[offset]; int optlen; - if (opttype == type) - return offset; - switch (opttype) { case IPV6_TLV_PAD1: optlen = 1; @@ -150,6 +147,10 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type) goto bad; break; } + /* Some callers read the option, so it must be in the header. */ + if (opttype == type) + return offset; + offset += optlen; len -= optlen; } diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c index 229ae205450d3..91fd25cff0ac0 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -345,7 +345,12 @@ static void mip6_addr_swap(struct sk_buff *skb, const struct inet6_skb_parm *opt if (likely(off >= 0)) { hao = (struct ipv6_destopt_hao *) (skb_network_header(skb) + off); - swap(iph->saddr, hao->addr); + /* + * The header can have moved or changed after + * ipv6_dest_hao() checked the length. + */ + if (hao->length == 16) + swap(iph->saddr, hao->addr); } } } diff --git a/net/ipv6/mip6.c b/net/ipv6/mip6.c index 6a16a5bd0d910..9615679724114 100644 --- a/net/ipv6/mip6.c +++ b/net/ipv6/mip6.c @@ -211,9 +211,16 @@ static int mip6_destopt_reject(struct xfrm_state *x, struct sk_buff *skb, if (likely(opt->dsthao)) { offset = ipv6_find_tlv(skb, opt->dsthao, IPV6_TLV_HAO); - if (likely(offset >= 0)) + if (likely(offset >= 0)) { hao = (struct ipv6_destopt_hao *) (skb_network_header(skb) + offset); + /* + * The header can have moved or changed after + * ipv6_dest_hao() checked the length. + */ + if (hao->length != 16) + hao = NULL; + } } stamp = skb_get_ktime(skb); -- 2.53.0