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=1795621770; b=gLqqSAapAQCzs5fPPtO8ICos2PArigB7evAplXicdCu7c9Y40DKdojISVB2g3yvG7DcG i6TnOvJ1oUgfc9dUWObdyeJHv3GLYRdUzZCKY5lG9L27n847Gf8lHvOIU0kE2ztcwnzM/ Uwr1fQ6qx99vLtAyZa05kH8CChk0ixXyhUpnYfUWWxhGLPACiOXXl9VKeaXPYfD4+v2S9 2GPXXa8l/dZ02FhMOXA1sO90HocPrc+pnHt8RVe1LQIC586XyuWLyV42dt8JhggKI2vfY lTuHlQel68DvXXNPSsaWoC/77AfMqPJdQc/5QDWsw2GilwnC/YflD3kR2oLh0zqh6fQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795621770; 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=/H6TyBUf1sr5pdyTM55B6GES0W4z/0G5Yzyt3Q5gZSI=; b=bYEkrZbmJQ+zMmkV/GyH86ZSpeYhgH1TC5/GfyNc5ITgJXnnqHY7dTYe1tVycEARGTw+ qbS6WSQiPzybRqj+qwJbOLW3iQQ1pFU0L4yyJpoxkp7ToT8/5bjdxhnymCT6QS8JWf91s CxuAIUIYW2756eT/wb2InrhbX1kBYSWxPQyTPoeOBzxH/G9I1d3c6dU8llfXuKtlAlqal snYM+JY1LlnlSp6IndpdLLJJaVyb6DT7pdwpr4cnNJP/0GP/zUKC5VrJ+hk17KV2Ed0nU /1RXduPZmpplgq44swHVlVq/MV9s6l/7KA5qPLWDJYNQ+XYDto0w4phM54JKhoO+QZQ== 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=WZayjszD; 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 886B4606A332; Wed, 25 Nov 2026 15:49:30 +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=WZayjszD Received: by smtp.kernel.org (Postfix) with ESMTPSA id A333C1F000E0; Wed, 25 Nov 2026 15:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795621770; bh=/H6TyBUf1sr5pdyTM55B6GES0W4z/0G5Yzyt3Q5gZSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WZayjszDbGLbceHq2KTxzbI9ZFG2FTZ/dehRJgn1RyooBbItYUKP/234SwrJgxJYO d6iCzKR/ezFWjzuzFzu0iBVLNsgDF0JiQw+UQoWIkD+S+7AvMOuNYIVbYjuZE2Bu7L AfTfjKE8Wdv0mLdlcUHRKcEYo4vMM+/Yndlc6EXI= 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.18 331/990] ipv6: Check the Home Address option again before its address is used Date: Wed, 25 Nov 2026 15:28:18 +0100 Message-ID: <20261125143829.840960351@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143822.072087159@linuxfoundation.org> References: <20261125143822.072087159@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.18-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 4a9748338cf40..764c694fb417a 100644 --- a/net/ipv6/exthdrs_core.c +++ b/net/ipv6/exthdrs_core.c @@ -138,9 +138,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; @@ -153,6 +150,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 9cf0557d0ed29..3164e7ddb6293 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -339,7 +339,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