From: sashiko-bot@kernel.org
To: "Marc Kleine-Budde" <mkl@pengutronix.de>
Cc: "Vincent Mailhol" <mailhol@kernel.org>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
linux-can@vger.kernel.org
Subject: Re: [PATCH net 03/14] can: bittiming: fix divide-by-zero in can_calc_bittiming()
Date: Thu, 27 Aug 2026 12:10:53 +0000 [thread overview]
Message-ID: <20260827121054.448991F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260826121036.2706424-4-mkl@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing bounds checking on `bittiming_const` parameters allows malicious USB devices to trigger divide-by-zero crashes or infinite loops in `can_calc_bittiming()`.
--
commit 0fc6576c2e9b35990a8bf86f43e72c0d477992ea
Author: Sureshkumar S <ssureshmsd7@gmail.com>
can: bittiming: fix divide-by-zero in can_calc_bittiming()
This commit prevents a divide-by-zero panic in can_calc_bittiming() when
evaluating prescalers for large bitrates. It does this by computing the
product of tsegall and bt->bitrate in 64 bits to avoid wrap-around.
Link: https://patch.msgid.link/20260803091426.29050-2-ssureshmsd7@gmail.com
> diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c
> index 42498e9d3f38d..4809f5e0c96e9 100644
> --- a/drivers/net/can/dev/calc_bittiming.c
> +++ b/drivers/net/can/dev/calc_bittiming.c
> @@ -119,8 +119,12 @@ int can_calc_bittiming(const struct net_device *dev, struct can_bittiming *bt,
> tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) {
[Severity: High]
This is a pre-existing issue, but if a malicious CAN USB device (such as one
using the gs_usb driver) provides a USB descriptor where btc->tseg1_min and
btc->tseg2_min are both 0, the unsigned loop condition (tseg >= 0) becomes
always true.
Could this result in an integer wrap-around and billions of loop iterations,
leading to a system freeze (soft lockup)?
Since can_bittiming_const_valid() in drivers/net/can/dev/dev.c validates these
constants, should it be updated to verify that tseg1_min and tseg2_min are
non-zero?
> tsegall = CAN_SYNC_SEG + tseg / 2;
>
> - /* Compute all possible tseg choices (tseg=tseg1+tseg2) */
> - brp = priv->clock.freq / (tsegall * bt->bitrate) + tseg % 2;
> + /* Compute all possible tseg choices (tseg=tseg1+tseg2).
> + * A 32 bit tsegall * bt->bitrate can wrap to zero for large
> + * userspace bitrates, so compute the product in 64 bit.
> + */
> + brp = div64_u64(priv->clock.freq,
> + mul_u32_u32(tsegall, bt->bitrate)) + tseg % 2;
>
> /* choose brp step which is possible in system */
> brp = (brp / btc->brp_inc) * btc->brp_inc;
[Severity: High]
This isn't a bug introduced by this patch, but if btc->brp_inc is 0 due to an
unvalidated value from the USB device, would this calculation cause an
immediate divide-by-zero panic?
Additionally, if btc->brp_min is 0, brp can evaluate to 0 in some loop
iterations. Looking further down in can_calc_bittiming():
bitrate = priv->clock.freq / (brp * tsegall);
Can this lead to another divide-by-zero in the same loop?
Similarly, if fclk_can (mapped to priv->clock.freq) is provided as 0 by the
device, would the following call near the end of can_calc_bittiming() also
result in a divide-by-zero panic?
do_div(v64, priv->clock.freq);
Would it make sense to enhance can_bittiming_const_valid() to ensure that
parameters like brp_inc, brp_min, and clock.freq are strictly greater than
zero before they are used here?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260826121036.2706424-1-mkl@pengutronix.de?part=3
next prev parent reply other threads:[~2026-08-27 12:10 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 12:02 [PATCH net 0/14] pull-request: can 2026-08-26 Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 01/14] can: dev: can_dropped_invalid_skb: drop CAN XL frames on non-CAN XL devices Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 02/14] can: convert unreliable ARPHRD_CAN type checks to robust can_get_ml_priv() Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot
2026-08-27 12:41 ` Oliver Hartkopp
2026-08-26 12:02 ` [PATCH net 03/14] can: bittiming: fix divide-by-zero in can_calc_bittiming() Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot [this message]
2026-08-27 19:44 ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 04/14] can: bittiming: fix bitrate error calculation on unsigned operands Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 05/14] can: rockchip_canfd: prevent TX stall on echo skb failure Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 06/14] can: rockchip_canfd: retry the outstanding TX buffer Marc Kleine-Budde
2026-08-27 19:44 ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 07/14] can: rockchip_canfd: serialize TX state and command writes Marc Kleine-Budde
2026-08-27 19:44 ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 08/14] can: skb: make echo skb freeing safe in any IRQ context Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot
2026-08-26 12:02 ` [PATCH net 09/14] can: skb: make CAN skb allocation failure paths IRQ-safe Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 10/14] can: dev: can_put_echo_skb(): free skb on invalid echo index Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot
2026-08-27 17:01 ` Oliver Hartkopp
2026-08-26 12:02 ` [PATCH net 11/14] can: kvaser_pciefd: fix use-after-free in bec poll timer Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot
2026-08-27 12:36 ` Marc Kleine-Budde
2026-08-27 12:55 ` Marc Kleine-Budde
2026-08-26 12:02 ` [PATCH net 12/14] can: kvaser_usb: validate command format before parsing in hydra receive path Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot
2026-08-27 12:57 ` Marc Kleine-Budde
2026-08-27 19:44 ` Jakub Kicinski
2026-08-26 12:02 ` [PATCH net 13/14] can: usb: f81604: fix struct f81604_int_data size mismatch Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot
2026-08-26 12:02 ` [PATCH net 14/14] can: hi311x: drop hi3110_lock before free_irq() on open failure Marc Kleine-Budde
2026-08-27 12:10 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260827121054.448991F00A3E@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox