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=1796385236; b=NXA5ey/ggE9qA6obYRAtjd835x1UlBuhZXpCRTiKLMCfL4F9NYjMXhR9Th2KfQF1BvY1 QjxeiIBjTSQB61L4aeyPOMn4rbgSzSlA39oKyPqXB/vKblfYN11UN8P81GYCIkdLWaSOm /hqQ5rU8SV31HqtBV+TeRBogRRtqlWaTEEYj8z3gLyuhmxIYnF6hJpxOFJfOqiTYlhczj vgsE/MZlaBNxQ0bCBk4Ylon1ECRZO+qsYrtb2roP018/++XteWL9V8vliI+znkVfk6VkG 3Z7/lr0QusmzTcti4NLfXE7kiETSwV1CetkRarlpH62lTfFeTWm6fbX599K3BUgtasA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385236; 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=FwdGLeesJ9O8nmU/I4pNVQVVWWqy1SqTVzPUT4O5IK4=; b=YxibhZ/QGrkoX+xtqcuBkTV8CR0ZNznc+79dXQPlm5HJD7WjK8o1PH1FRFokdydBQnNI 4lWXyGSuicj0fkbvRUgpnxw7xbrEoqf6fEncAxK4i/K4UE63dcsa8JL2WNQ66J5Uk7w0x ghSIVjgYRTJYPllLhqOtnD7dyCqvFydO4UHe8UcMNyQqSN+GsMz1KsCgufooy7vIGfJm8 xJC60tRgRCcwlpPzvq442JFqmP6S7oV6ZQL9pDGUjdDAI905LT5jkog4sRG/Ee4e8AdWO 9tRje2Nwx9fy5+mqoLAscNPanqpf4qCWkAHLnecSexyXnDey5XEDzi+UWLRKujHHMBQ== 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=pxCCDWNB; 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 402C4606A322; Fri, 4 Dec 2026 11:53:56 +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=pxCCDWNB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 701DF1F00934; Fri, 4 Dec 2026 11:53:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385235; bh=FwdGLeesJ9O8nmU/I4pNVQVVWWqy1SqTVzPUT4O5IK4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pxCCDWNBU1RPW5dwIo/DNa2OJDJEuTgw5XVhBc2bRFXovhwvYL29UiNekjPSpEQ+0 V9ZjlVWY6uUEFdo6+y9ZWh3pDzh/hVc5phsEM6KS5Q0j/Rb85tbkbwFEGiz69GqVgY DBW7iD2uxTqdfYSDs/lNpwplAHOqaxWrgF3icx44= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xingyuan Mo , Xin Long , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0457/1167] sctp: reject forged cookie peer_addr with unknown address family Date: Fri, 4 Dec 2026 18:58:04 +0900 Message-ID: <20261204100713.919753951@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: Xingyuan Mo [ Upstream commit 9802123ceca818aa69284c615114ca55b9cc94a1 ] When cookie authentication is disabled, COOKIE-ECHO peer_addr is attacker-controlled. An invalid sa_family made sctp_get_af_specific() return NULL and crash in sctp_transport_init() on af_specific->sockaddr_len. Validate it with af->addr_valid() in sctp_unpack_cookie(), which also rejects a mismatched family, e.g. an AF_INET6 peer_addr on an IPv4 socket that would later crash in sctp_v6_get_dst() on inet6_sk(sk)->opt. Validate a copy of peer_addr, since addr_valid() rewrites a v4-mapped v6 address in place and the cookie still lives in the received skb, which is not guaranteed to be unshared. Store the validated copy in the new association and pass it to sctp_process_init() instead of the raw cookie, so a v4-mapped v6 address is normalised to AF_INET before the association and its primary transport are built from it. For that, sctp_v6_addr_valid() has to return 0 for a non-v4-mapped address when it is called with a socket that is not PF_INET6, so that IPv6 addresses are never used on IPv4 sockets. The check is done after the v4-mapped handling, so v4-mapped addresses passed to an IPv4 socket through the socket API keep being accepted. As addr_valid() now also checks sk_family and ipv6_only_sock, simplify the address handling in sctp_process_param() with it, as it additionally filters out non-unicast addresses. As a side effect, a v4-mapped address in an IPv6 address parameter is now normalised to AF_INET before the transport is created, matching what the socket API paths already do. Also add the missing !af check in sctp_process_init(), as sctp_get_af_specific(AF_INET6) returns NULL on CONFIG_IPV6=n builds. BUG: KASAN: null-ptr-deref in sctp_transport_new+0xa7/0x350 Read of size 4 at addr 00000000000000b4 by task poc/682 Call Trace: sctp_transport_new+0xa7/0x350 sctp_assoc_add_peer+0x153/0x850 sctp_process_init+0xf9/0x1180 sctp_sf_do_5_1D_ce+0x464/0xbc0 sctp_do_sm+0x114/0x2990 sctp_endpoint_bh_rcv+0x280/0x430 sctp_inq_push+0xdd/0x100 sctp_rcv+0x17f5/0x1ae0 sctp4_rcv+0x2b/0x40 ip_protocol_deliver_rcu+0x25b/0x270 ip_local_deliver+0xd1/0xe0 Kernel panic - not syncing: Fatal exception in interrupt Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Xingyuan Mo Acked-by: Xin Long Link: https://patch.msgid.link/20261019073747.178626-1-hdthky0@gmail.com Signed-off-by: Jakub Kicinski [ sashal: adjusted the sctp_unpack_cookie() local declarations to fit this tree's existing digest variable and ordering, adding only paddr and af; all other hunks apply unchanged. ] Signed-off-by: Sasha Levin --- net/sctp/ipv6.c | 6 +++++- net/sctp/sm_make_chunk.c | 24 +++++++++++++----------- net/sctp/sm_statefuns.c | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c index 4f0647e60dae4..819930cc4207c 100644 --- a/net/sctp/ipv6.c +++ b/net/sctp/ipv6.c @@ -725,7 +725,8 @@ static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp) * SCTP. * * Output: - * Return 0 - If the address is a non-unicast or an illegal address. + * Return 0 - If the address is a non-unicast or an illegal address, + * or a non-v4-mapped address on a non-PF_INET6 socket. * Return 1 - If the address is a unicast. */ static int sctp_v6_addr_valid(union sctp_addr *addr, @@ -749,6 +750,9 @@ static int sctp_v6_addr_valid(union sctp_addr *addr, if (!(ret & IPV6_ADDR_UNICAST)) return 0; + if (sp && sctp_opt2sk(sp)->sk_family != PF_INET6) + return 0; + return 1; } diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index c1a5384eed75f..aec4c04793d9a 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1759,8 +1759,10 @@ struct sctp_association *sctp_unpack_cookie( struct sctp_cookie *bear_cookie; __u8 *digest = ep->digest; struct sctp_chunkhdr *ch; + union sctp_addr paddr; enum sctp_scope scope; unsigned int len, chlen; + struct sctp_af *af; ktime_t kt; /* Header size is static data prior to the actual cookie, including @@ -1880,6 +1882,11 @@ struct sctp_association *sctp_unpack_cookie( goto fail; } + paddr = bear_cookie->peer_addr; + af = sctp_get_af_specific(paddr.sa.sa_family); + if (!af || !af->addr_valid(&paddr, sctp_sk(ep->base.sk), NULL)) + goto malformed; + /* Make a new base association. */ scope = sctp_scope(sctp_source(chunk)); retval = sctp_association_new(ep, ep->base.sk, scope, gfp); @@ -1896,6 +1903,7 @@ struct sctp_association *sctp_unpack_cookie( /* Populate the association from the cookie. */ memcpy(&retval->c, bear_cookie, sizeof(*bear_cookie)); + retval->c.peer_addr = paddr; if (sctp_assoc_set_bind_addr_from_cookie(retval, bear_cookie, GFP_ATOMIC) < 0) { @@ -2420,8 +2428,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, (param.p->type == SCTP_PARAM_IPV4_ADDRESS || param.p->type == SCTP_PARAM_IPV6_ADDRESS)) { af = sctp_get_af_specific(param_type2af(param.p->type)); - if (!af->from_addr_param(&addr, param.addr, - chunk->sctp_hdr->source, 0)) + if (!af || !af->from_addr_param(&addr, param.addr, + chunk->sctp_hdr->source, 0)) continue; if (sctp_cmp_addr_exact(sctp_source(chunk), &addr)) src_match = 1; @@ -2593,17 +2601,11 @@ static int sctp_process_param(struct sctp_association *asoc, */ switch (param.p->type) { case SCTP_PARAM_IPV6_ADDRESS: - if (PF_INET6 != asoc->base.sk->sk_family) - break; - goto do_addr_param; - case SCTP_PARAM_IPV4_ADDRESS: - /* v4 addresses are not allowed on v6-only socket */ - if (ipv6_only_sock(asoc->base.sk)) - break; -do_addr_param: af = sctp_get_af_specific(param_type2af(param.p->type)); - if (!af->from_addr_param(&addr, param.addr, htons(asoc->peer.port), 0)) + if (!af || !af->from_addr_param(&addr, param.addr, + htons(asoc->peer.port), 0) || + !af->addr_valid(&addr, sctp_sk(asoc->base.sk), NULL)) break; scope = sctp_scope(peer_addr); if (sctp_in_scope(net, &addr, scope)) diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index 0b54e45f241c6..c5562d10d5657 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -813,7 +813,7 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, * effects--it is safe to run them here. */ if (!sctp_process_init(new_asoc, chunk, - &chunk->subh.cookie_hdr->c.peer_addr, + &new_asoc->c.peer_addr, peer_init, GFP_ATOMIC)) goto nomem_init; -- 2.53.0