From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C5652C2363 for ; Sat, 4 Jul 2026 03:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783136161; cv=none; b=ijd5N4ufdElcZQaqvLXhSVSrd082Ir95mJtrIq/Ix5FYBQlJygEzNxUNVXu0dl9tiFCg8+zteaI1UGRWo/xoW4jnh9AGzbkD2yO7ys2cnmegg6P8nFsDd6K7uXeVn5pB8Mcur9cnn0WeEp4a4GsLkVdHbSQloyyexFg/qIBA6DI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783136161; c=relaxed/simple; bh=ThuPvzUSoYy43zilZk9Przuhu7j/1v83Yf48qsTni30=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=U0qRpMG8Zr7Qjtv5KQI+kWcqxlfAIp4oz9ZNNvHpIZTyi+0cKHJPel99foc0NCWobkyLqwcwhBjYkKS4LNVr32MQiPbidfs380vDqDF48Nrzh45ATA5ZUd/hqACvIRSAhpuINR7E+SyyvzypGd4+PdzvM9w7C4MBs6cHfx3n9cQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=THW046e/; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="THW046e/" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-84780c95e2eso802167b3a.3 for ; Fri, 03 Jul 2026 20:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783136159; x=1783740959; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=troEzZKmFC4zyspQLdq3bYm3HWpLnTsTSmm94slF8L0=; b=THW046e/WRq56mbmEGdJWLfhVVqPPBVG4C8nsaSrpSgPLeXWyv4mexUyYGMjOnDs4U QQQW0YCX5Maiq9TCoKzETlAUjwEig1ZkvYjsAuBgyjigaLLa5CwIpB7OxLTQ6nLU7449 pxCZzsI30B+5BFm+aHlTEHA7X3KBBHgr2P3n1XZW5PE4QdXSbQEN8vY/0Khk2Paz2M9H 7CwmNpVT+JhqxZneq7R30nBTwUu5ZOySquhRLthVAwKFB1Bq08zWPI5NpXZH45cjjAUB ycOIeOs4Lu3doNysvUzKpxCQzjhKKRCFhFGoErzF1bWmzLfP/3L5pbA2HelD+lbd/5Jo 97jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783136159; x=1783740959; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=troEzZKmFC4zyspQLdq3bYm3HWpLnTsTSmm94slF8L0=; b=SSlZrvThzY1f6Ky8PdLhJC9+xFwEng8rNf9Gyco5063qJPtcR5AGP+Q++K8Gez8sus gWWAgmR9ub6dzqMxkfkdq8w/vsV2viRiNOzgJDGVa5Fwsx3gO9T9j+m64Yzb6TurtbI9 6ASRflQknMwfj+CnYL1ksJwHFQ/UOcxD44Guo/LGfQVuT9D9FQi+0U1WRI/Atk77AKex fj5BVC+raWXrreR+jrF048FvGp/SOxE60xMNfyvXmzRwstUQnI9IXmkD35X+OJGgxKhU Tiv/Fl3Mbydq1s5dxsDMH47JfyAryrTh8eOEmoMxNTNvW6OHseYIn5XBilBOeAg69qbn Se1Q== X-Forwarded-Encrypted: i=1; AFNElJ+hTcY82ZIA9jTvOy9YjCcvBlXWVRhNnpmRf0fV5Hok0tSqLGyWPadZXJvxsaMgLZ/b2dfNHMI=@vger.kernel.org X-Gm-Message-State: AOJu0YzBNt3zMHERq8p4pF9E7GAogbiHRScaaLVodvQyWh/i66OJjWbp r9G41mDYGJGtfCW+mxVPai4KfqZip9+x/nOaBjGCcIurPzBlJFyniUiF X-Gm-Gg: AfdE7cmQJsLGY/yzmp7qeZnNCcgYVqseWjpx78roQ0l64FqJkAu7u4aAFRm+6bJWJ5c 4pK+QeYzRrMveKZ0yZ4nvhe/8J8Ws4nm+wo2Wzgne9vvzLKVJTqCo2QcJ2zBcttW3V0p8OAVwcN JPykGRMrlSx4HeA1g3yjPtcifWREwNvgc6uKYemZIlyB34jdiIOxjuCa5ZHcr2fcauP26/vCxXc NtYrlH1B32s6MWHHlTyOSF/+VFMEL66OQU2Mo5goaNHkwtxOrnqDNXrngS6lIhzVwSnUZTtUIRC 4m9FmrIB7Fpbr+e+SjRofzU4YKiI7kjB/bqhOgM9/MOeTHzIg+hjuKwezWTjljYoXgm9kRlC/4j S96uSakbM1+HKT/jGuUmGHwB/cDAxKQ3/6xlewyk/B9FIIUHWRhCBH/31TQ9ufHa8RmUJU2/d2I F9I+vXKSzYz8XGiQXvhGGT8PslbXBvcsXNFAbDiPBeAOnqTWMpkwmyyCiWKw== X-Received: by 2002:a05:6a21:1507:b0:3bf:9fe1:c24 with SMTP id adf61e73a8af0-3c03e1eeaa7mr2184488637.2.1783136159260; Fri, 03 Jul 2026 20:35:59 -0700 (PDT) Received: from fx.tailc0aff1.ts.net ([206.206.192.132]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30f1595e912sm26868465eec.31.2026.07.03.20.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2026 20:35:58 -0700 (PDT) From: Weiming Shi To: linux-sctp@vger.kernel.org Cc: Marcelo Ricardo Leitner , Xin Long , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, Xiang Mei , Weiming Shi , stable@vger.kernel.org Subject: [PATCH net] sctp: validate STALE_COOKIE cause length before reading staleness Date: Fri, 3 Jul 2026 20:35:46 -0700 Message-ID: <20260704033545.2438373-2-bestswngs@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When an ERROR chunk with a STALE_COOKIE cause is received in the COOKIE_ECHOED state, sctp_sf_do_5_2_6_stale() reads the 4-byte Measure of Staleness that follows the cause header: err = (struct sctp_errhdr *)(chunk->skb->data); stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err))); err is the first cause in the chunk, not the STALE_COOKIE cause that caused the dispatch, and nothing guarantees the staleness field is present. sctp_walk_errors() only requires a cause to be as long as the 4-byte header, so for a STALE_COOKIE cause of length 4 the read runs past the cause, and for a minimal ERROR chunk past skb->tail. The value is echoed to the peer in the Cookie Preservative of the reply INIT, leaking uninitialized memory. sctp_sf_cookie_echoed_err() already walks to the STALE_COOKIE cause, so check its length there and pass it to sctp_sf_do_5_2_6_stale(), which reads that cause instead of the first one. A STALE_COOKIE cause too short to hold the staleness field is discarded. The read is reachable by any peer that can drive an association into COOKIE_ECHOED, including an unprivileged process using a raw SCTP socket in a user and network namespace. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Xiang Mei Assisted-by: Claude:claude-opus-4-8 Cc: stable@vger.kernel.org Signed-off-by: Weiming Shi --- net/sctp/sm_statefuns.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index d23d935e128e..3893b44448b3 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -74,7 +74,8 @@ static enum sctp_disposition sctp_sf_do_5_2_6_stale( const struct sctp_association *asoc, const union sctp_subtype type, void *arg, - struct sctp_cmd_seq *commands); + struct sctp_cmd_seq *commands, + struct sctp_errhdr *err); static enum sctp_disposition sctp_sf_shut_8_4_5( struct net *net, const struct sctp_endpoint *ep, @@ -2529,9 +2530,15 @@ enum sctp_disposition sctp_sf_cookie_echoed_err( * errors. */ sctp_walk_errors(err, chunk->chunk_hdr) { - if (SCTP_ERROR_STALE_COOKIE == err->cause) - return sctp_sf_do_5_2_6_stale(net, ep, asoc, type, - arg, commands); + if (err->cause != SCTP_ERROR_STALE_COOKIE) + continue; + /* The staleness is only meaningful if the cause is long + * enough to hold it; a shorter one is malformed. + */ + if (ntohs(err->length) < sizeof(*err) + sizeof(__be32)) + break; + return sctp_sf_do_5_2_6_stale(net, ep, asoc, type, + arg, commands, err); } /* It is possible to have malformed error causes, and that @@ -2573,13 +2580,13 @@ static enum sctp_disposition sctp_sf_do_5_2_6_stale( const struct sctp_association *asoc, const union sctp_subtype type, void *arg, - struct sctp_cmd_seq *commands) + struct sctp_cmd_seq *commands, + struct sctp_errhdr *err) { int attempts = asoc->init_err_counter + 1; - struct sctp_chunk *chunk = arg, *reply; struct sctp_cookie_preserve_param bht; struct sctp_bind_addr *bp; - struct sctp_errhdr *err; + struct sctp_chunk *reply; u32 stale; if (attempts > asoc->max_init_attempts) { @@ -2590,8 +2597,6 @@ static enum sctp_disposition sctp_sf_do_5_2_6_stale( return SCTP_DISPOSITION_DELETE_TCB; } - err = (struct sctp_errhdr *)(chunk->skb->data); - /* When calculating the time extension, an implementation * SHOULD use the RTT information measured based on the * previous COOKIE ECHO / ERROR exchange, and should add no -- 2.43.0