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=1796356304; b=atvSKHdiO+aO6fSxiNSoEBJqVl/bRhVaK8mJ/bnbiBoslcJWJMh8LQAgJZsKsTWsSW8J gVpRax8Au7DBxcpM8jAWqt2dPJ/oPmOanHokHm/Xob1vM//7At+h77h19C6Z3Ia70dEBj pKPlCXxApvb7qUsILoZ5Hrq0Z7ljGZ4g69Xe3nC4rYUwCujIdo68Gko2jy5Mr9mO/p0No lhMI5OwYPMhrO01rG/r7awzLFdHFdL3xNB3D7xebFNOl7vDOGdMbsnYsA5IOlWJ/Yxhe4 IKNULmjLShLsLgBp70/Tbp2h2saYYKKRoqnPymzYZENexjLb3NgJQTAeHJXu34bTY1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356304; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=zqnuteVey356G3Tn4dMGAmydg1oMYSJfkrA+V3zwNFQ=; b=kssfWh2nLaqskKrWMVD0K4REKK1YCdHRHWY1NTrAqu623+ASjpVVk6VJl1BAbaPWBFCr 4c3SLZA1K5UpWx86LuHROKTzArBUkgyafVoY8a6chf29esGcjgeiY3AostBmOWaFAfhku ierY2Di5u/jL0ovCboORFdDTpvrIcYsCGimLJaEofAreAhMw5OZONEd/cGNo/IdTtvwza po3S3JVTNzYaCt+KaNEZtyQ/cPh0KjsfWlbhyA01T5POArIGGyphdEWVvgZ7QpIFfvom8 tmq4e/yKgBjfR1iXDI0pev9MbFeVcdcu3/0Ml9ScLkgtbrjUInUzzpK9pjsBHhKFbdg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b6WQzoth; 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 591CB606A322; Fri, 4 Dec 2026 03:51:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b6WQzoth Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AA001F0092C; Fri, 4 Dec 2026 03:51:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796356304; bh=zqnuteVey356G3Tn4dMGAmydg1oMYSJfkrA+V3zwNFQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=b6WQzoth7+vSwL7FZ2ItAFHQmya4j9A5TazxIIgKJHK5Gz+i/A4rXYBvHLJvdPavQ lKzzyWP4PoGQ4q+hXZioI5RUKBEW/wegkLLHN5R4MoF1GMhhl82EDdceweVZAE2+pW jY6oY8jYH0Vhj8SCXJ5NC0EBowm1NCxX7UGVT9+R7RqQ3wYS1l+HeznFME9rai3/0o b2hSATAOPhn85s6OFIqhyuN12XAGi9gNcpQbf/WphnApHXfSY/AU5JASIJBySMEaSx 4YT5gE/JhEf/0sakmjdZli/xbyt7w2kwnYYxQwzRzaoTSYbv6/bV37YaAg7FzdPWMA 1T4gdlC5/yigQ== Subject: Re: [PATCH can-next v4 2/6] can: bittiming: can_calc_bittiming(): catch brp * tsegall overflow From: netdev-bot+sashiko@kernel.org To: mkl@pengutronix.de Cc: mailhol@kernel.org, socketcan@hartkopp.net, wg@grandegger.com, davem@davemloft.net, kernel@pengutronix.de, linux-can@vger.kernel.org, 25031212351@stu.xidian.edu.cn, stable@vger.kernel.org, byu@xidian.edu.cn, wencheng@xidian.edu.cn, kuba@kernel.org Date: Fri, 04 Dec 2026 03:51:43 +0000 Message-ID: <179635630301.3142.7923136246459818126@kernel.org> In-Reply-To: <20261202-bittiming-fix-conversion-v4-2-fae7aaaf3191@pengutronix.de> References: <20261202-bittiming-fix-conversion-v4-2-fae7aaaf3191@pengutronix.de> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 2 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] In can_calc_bittiming() (drivers/net/can/dev/calc_bittiming.c), the new… - [Medium] can_fixup_bittiming() (drivers/net/can/dev/bittiming.c:106 at this commit) computes 'priv->clock.freq / (bt->brp *… -- can: bittiming: can_calc_bittiming(): catch brp * tsegall overflow This patch replaces the unchecked brp * tsegall multiplication in can_calc_bittiming() with check_mul_overflow(). Any time segment combination whose product does not fit in an unsigned int is now skipped. The brp and tsegall limits come from the CAN controller, and some devices report them over USB. > diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c > index 8889d55fea652..cf8310537df23 100644 > --- a/drivers/net/can/dev/calc_bittiming.c > +++ b/drivers/net/can/dev/calc_bittiming.c > @@ -133,7 +133,10 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt, > if (brp < btc->brp_min || brp > btc->brp_max) > continue; > > - bitrate = priv->clock.freq / (brp * tsegall); > + if (check_mul_overflow(brp, tsegall, &div)) > + continue; > + > + bitrate = priv->clock.freq / div; [Severity: Medium] Can div still be zero at this division? check_mul_overflow() only catches products that wrap. A product of zero that does not overflow still passes. Take an even tseg where tsegall * bt->bitrate is larger than priv->clock.freq. Earlier in the loop, brp then comes out as zero: brp = priv->clock.freq / div + tseg % 2; If the device reports brp_min == 0, the range check above does not reject brp == 0: if (brp < btc->brp_min || brp > btc->brp_max) continue; In that case check_mul_overflow(0, tsegall, &div) returns false with div == 0, and priv->clock.freq / div divides by zero. gs_usb and ucan copy brp_min from the device without validating it. For example, gs_make_candev() does: dev->bt_const.brp_min = le32_to_cpu(bt_const.brp_min); A CAP_NET_ADMIN user who sets a high enough bitrate reaches this path through can_changelink()->can_get_bittiming()->can_calc_bittiming() with RTNL held. The last commit in this series, "can: bittiming: register_candev(): reject unusable bit-timing constants", appears to fix this. Its can_bittiming_const_valid() rejects !btc->brp_min at registration, so the division can only fault at commits before that one. This patch is marked for stable. Would it be worth also skipping div == 0 here, or moving the registration check ahead of this patch in the series? > bitrate_error = abs(bt->bitrate - bitrate); > > /* tseg brp biterror */ [Severity: Medium] This guards the brp * tsegall product in can_calc_bittiming(). Does can_fixup_bittiming() in drivers/net/can/dev/bittiming.c have the same unchecked 32-bit multiplication? drivers/net/can/dev/bittiming.c:can_fixup_bittiming() { ... bt->bitrate = priv->clock.freq / (bt->brp * can_bit_time(bt)); ... } bt->brp comes from the user-supplied tq and is bounded only by the device's brp_min and brp_max. can_bit_time() is bounded only by the device's tseg1_max and tseg2_max. Suppose a gs_usb or ucan device reports a large brp_max, for example 2^28 or more. With a bit time of 16 the product wraps to exactly 2^32, which makes the divisor 0. A device brp_min of 0 would also allow bt->brp == 0. can_get_bittiming() reaches this function when the user sets tq and leaves bitrate at 0: if (bt->tq && !bt->bitrate && btc) return can_fixup_bittiming(dev, bt, btc, extack); Later commits in the series seem to fix this. "can: bittiming: register_candev(): reject unusable bit-timing constants" requires brp_min >= 1, brp_max <= 65536 and tseg1_max + tseg2_max + 1 <= 1024. "can: bittiming: can_fixup_bittiming(): reject too high values for prop-seg/phase-seg1" also stops the prop_seg + phase_seg1 sum from wrapping. Together they keep the product between 1 and 2^26. Should this patch also guard the division in can_fixup_bittiming(), so the stable backport covers both places? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-bittiming-fix-conversion-v4-0-fae7aaaf3191%40pengutronix.de