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=1795618716; b=L9vJyH5QGJHOezyka2f7+aXv+uUY3eRVFUKzoTqpE7P0/sCmELmUSNocY8EJNHM12CKi hmRMkuTHnAsjjJwf6AnoSHWySSjuSyJwzrfTvC5m/Tp4eSmIVGGeQNGx/7cDjqJEjCLK/ zGj2r9Ez0Nf3tMkBeMOSTrNJnbdUfzHIo4vjh+Fyr2iAUct63YibZa6Y49HEVz/b+uySu 3qXxG7oNMuM0NO9gVtKdxg2tRYS8yG+feJY9lma+fBh7ojgGKdRZcIiYde2P37bhitmwq SjROst91k0NCD/xt5KaugsPN8F28If7JbOH0NFTZ32vv9PEnvXsVenq/xEA4UMp7b8g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795618716; 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=woXtNsCS/Hy9BZU7vE6fXrqwMI0D6hcmXXOZFehXf2Y=; b=NPZk/6qyIeLWRz8ZmyxV2BBHDtvMSlO4GbUknD9LvoXBzEtBItAiF5QaUwx/3pSSYCER CpLxgUZfW8X+CxF3gW7dkeluermAdnfXSBrpdU0mMHzE2mAIz6mWe6gHN6Q3eg7PGkhNL TaU6JOp2kZgZxpM/PQinLq1zaIybQb6LjlnXewmPas612LjEWsOltLTEXpDLcB6CY/3P4 c7OvflpAVj0zaXfHidpr5mo72LesAXID7l9AD9yxp3duf3i0BR325dsEzN1B8Y3SFgSdo oQAHXetTOIHU5nXtnOke6/a1Czq/QM1pDAVENVjwsaVTHR+w/iij6uy49m5g9Jj8SiQ== 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=gRC1jkOB; 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 1569C606A31E; Wed, 25 Nov 2026 14:58:36 +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=gRC1jkOB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65C291F000CA; Wed, 25 Nov 2026 14:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795618715; bh=woXtNsCS/Hy9BZU7vE6fXrqwMI0D6hcmXXOZFehXf2Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gRC1jkOBNZovqMn2198p1n/0o/vIQGbXFa9Dwpyb8EKYdTGnTT0Sx7rsMQNthNWWS 0loXLZTgB+1H/+B7zmkZQLgoZpLn8/Wk4tu9GqivNun6fi7UXvBk36iMHCRakyzsU5 mDgM0FkBKLgoE25DG9unDWlwu0rCiyilC/GmUshs= 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 7.3 0368/1005] ipv6: Check the Home Address option again before its address is used Date: Wed, 25 Nov 2026 15:28:26 +0100 Message-ID: <20261125143830.354872816@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143821.729802100@linuxfoundation.org> References: <20261125143821.729802100@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 7.3-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 a95b0351824f3..d8203ebad8827 100644 --- a/net/ipv6/icmp.c +++ b/net/ipv6/icmp.c @@ -343,7 +343,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