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=1795026340; b=C7iVs3IYxvDsyc5toXXJKgoMPSuJEKRuvzXIYdD/rLv6PJglZGURti54GR6K2eWFfLP+ 2wWnkEsXo+4mVybGfKSlmSoaUhE9oJUlw86NRmK/IGrwlI8LtvD83GmV8cbWjLXeyqjv1 8JqTMC4yaF6Ob5eyAB8zHp/1KlQpYy+lr+361B3ImYFeT1AOlEUxcRi1PhFu9246/+JNk VPetMbdfFW4g07w+FbC4LkgioWETyENouXn6dFABgM8kA7GXwam9oqzoMp6b0Yizoe9/I 2kIM/i7ZqR1TOwuXQTNGOl3N8jQa5YY68KbioaY0A8y+SAG+pnPyOVRiSvcw4J9XIqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795026340; 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=54bHMUZ/jVcP2XI8wU9fCf3ybDwZDs3GQ29bT8wkVl8=; b=ehddmIS9FaoIwQMDM/FFfCqyjPfvBiGJTsgSFw8jr7wMAeROMH3QPZQb99ezGaruspH3 vQRcmQjIKMNc04PYuyacwYF+HG1WlC6yt6kxCkRScGm+WT4e7aREBFEXirg1IZpM2oAAU KdzxW43Y308bXVJVR/xYN5THbSM1tKhYNWg9QlZq2UfyDul+26eEstEwJLjPinSekwPrh fgmZCo9wKCpnDgP0ovSFQt6s0Qb2j5/3+pYBWjzYhgKOyNdAglOgncmiFf9muNe+XgeOS FApcDAXpm3IY7Hf/BsM5N2Nbr+5T77HzZ4FjtvHZ8XJMjVp/crLosAVwoiaXxP7h9aQ== 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=hVCrMC7m; 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 29877606A32A; Wed, 18 Nov 2026 18:25:40 +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=hVCrMC7m Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F3131F000C6; Wed, 18 Nov 2026 18:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795026340; bh=54bHMUZ/jVcP2XI8wU9fCf3ybDwZDs3GQ29bT8wkVl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hVCrMC7m9UxKDCaB3ts7mzzBOWjrvawo4B1oOmFJmJj6Te2O008KrMSkHM/OCNHjZ QaDiY7F0CFBZVMO7E5HrwILeUzfttuEGaCi+QpkBtV29uhTFitjajxCVD2KcuCRMID B2wIDnQaGAVNevgukegQeoxXtUIO4bDRrP8JRvv0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Jiayuan Chen , Paolo Abeni , Sasha Levin Subject: [PATCH 6.18 1400/2151] tcp_cubic: fix divide by zero and endless loop on bad module params Date: Wed, 18 Nov 2026 15:52:15 +0100 Message-ID: <20261118150212.991639159@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@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: Jiayuan Chen [ Upstream commit 7d52b5d16afc1cf8484ae321658e217a80e3ff4d ] beta_scale and cube_factor are computed once at module init, and beta == 1024 or bic_scale == 0 is a divide by zero right there. Other out of range values give garbage: negative beta can make beta_scale 0, and bic_scale * 10 can overflow. Reject them. Read beta once, as it can be written through sysfs before the init function runs. A small beta also gives a small beta_scale, and (cwnd * beta_scale) >> 3 truncates to 0 for a tiny cwnd, so the TCP friendliness loop never ends. Rather than testing delta on every ACK, make sure beta_scale is at least 8 at init, so delta is >= 1 within the cwnd < 1 million packets limit this code is designed for. This slows the TCP friendly estimate for beta < 512, a backoff harder than Reno's 0.5, which is not a setting anyone should use. Fixes: df3271f3361b ("[TCP] BIC: CUBIC window growth (2.0)") Suggested-by: Eric Dumazet Reviewed-by: Eric Dumazet Signed-off-by: Jiayuan Chen Link: https://patch.msgid.link/20261008092641.140777-4-jiayuan.chen@linux.dev Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/ipv4/tcp_cubic.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_cubic.c b/net/ipv4/tcp_cubic.c index f891e8d1e5458..bfc18a10b5605 100644 --- a/net/ipv4/tcp_cubic.c +++ b/net/ipv4/tcp_cubic.c @@ -503,16 +503,26 @@ static const struct btf_kfunc_id_set tcp_cubic_kfunc_set = { static int __init cubictcp_register(void) { + int b = READ_ONCE(beta); int ret; BUILD_BUG_ON(sizeof(struct bictcp) > ICSK_CA_PRIV_SIZE); + if (b < 0 || b >= BICTCP_BETA_SCALE || + bic_scale <= 0 || bic_scale > INT_MAX / 10) { + pr_err("tcp_cubic: invalid beta %d or bic_scale %d\n", + b, bic_scale); + return -EINVAL; + } + /* Precompute a bunch of the scaling factors that are used per-packet * based on SRTT of 100ms */ - beta_scale = 8*(BICTCP_BETA_SCALE+beta) / 3 - / (BICTCP_BETA_SCALE - beta); + beta_scale = 8 * (BICTCP_BETA_SCALE + b) / 3 + / (BICTCP_BETA_SCALE - b); + /* bictcp_update() needs (cwnd * beta_scale) >> 3 to be >= 1 */ + beta_scale = max(beta_scale, 8U); cube_rtt_scale = (bic_scale * 10); /* 1024*c/rtt */ -- 2.53.0