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=1796384566; b=PEbF4KRqX2wzAevbGuhA5HsG/+/PSS3nroWP2aZOwiuRLaWgi2Fu4oQgpsWfvPTzpSbh A3/qJVTMd9AwQwau8uuHH1Am5DYxbMKv2ZFcWQzOQlHYtkV9nGK3m74jxg4Yg+We/CYr1 P2x8lMVVlXNdZNMW6h0nN1P5JSZDfsneTp6Gexmf7j7RQe/OmsZsiPr5KK17nXvm0OzGI eN7/MJFYu0+MuMXRQ19tW1gYZcE8ZzuFHXFcP/vrT4XSaI1q8ZCYOw2hWNdb6EdO3IPGe PeVeHJSfOIAIhj5hlBP3rBqsfIBEioZIGD/xnjGEVrWrJ5HTRJm/BjDVLfKUqvlkonw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384566; 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=AEL3WxsjMQnIVBh704lRSdn5IPFTE4zvaSB7IOylATw=; b=TbEdEJs8YntX1jcbOsFNMjEj8DUm741GyLtsfL8rnAb7OiaMR3kRrL9ee93+Xf8Ty8yI vfe9n8iS3dXs4gvOvtIUn7ub3itO+Xgv81U131GUPVJyt/aImJ8TD2mJ9nskNb4+6j29s z8c2SLLC7n/wKqCwye4eKBLBVv+h+nWBxUtdckPA8RnmdCc1vwBjLcW2kTOpZ3BJycikW D+uKE6K/YyrbXUfeS1eMDLjOtqTWq9jUkztQu4YHdXArbUE0VZQRe1AFHgG5KjjMSp4KV whYI5jDdvGQO3e82RD0IM5n1rD9yhLLnHo6TUoVMym7tDxhA1TrS3RqO6xsYyTpE9tQ== 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=Um6JFpYS; 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 94106606A322; Fri, 4 Dec 2026 11:42:46 +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=Um6JFpYS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A1931F000C2; Fri, 4 Dec 2026 11:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384566; bh=AEL3WxsjMQnIVBh704lRSdn5IPFTE4zvaSB7IOylATw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Um6JFpYSlmFSAIoyEcm+t8KDBhGqo3HETu2WFbabb2bNpCCWyj26Ei3s7cxSVUD0t CcwMT3VH7CFEtNQ5KjKTJ2lph9UZUtcBUmFA0TlAE7FsnsC0z2WHfAgMbNh0vgc95Z jXDqPL/knb4ToqJdH9lcCRU/6UeG+W9h1rA68GLI= 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.6 0205/1167] ipv6: Check the Home Address option again before its address is used Date: Fri, 4 Dec 2026 18:53:52 +0900 Message-ID: <20261204100707.406807072@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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 9c56612c66211..135e90edbfedd 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 83d2a8be263fb..d4daadd2b72bf 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