From: sashiko-bot@kernel.org
To: "Sureshkumar S" <ssureshmsd7@gmail.com>
Cc: "Oleksij Rempel" <o.rempel@pengutronix.de>,
linux-can@vger.kernel.org, "Vincent Mailhol" <mailhol@kernel.org>,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>
Subject: Re: [PATCH net 1/2] can: bittiming: fix divide-by-zero in can_calc_bittiming()
Date: Tue, 04 Aug 2026 09:15:02 +0000 [thread overview]
Message-ID: <20260804091502.A40441F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260803091426.29050-2-ssureshmsd7@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing validation for hardware-provided bit-timing constants `brp_inc` and `brp_min` allows malicious or misbehaving CAN devices to trigger divide-by-zero kernel panics.
- [High] A 32-bit integer overflow in the `brp * tsegall` calculation can wrap to zero, causing a divide-by-zero kernel panic.
--
--- Patch [1]: [PATCH net 1/2] can: bittiming: fix divide-by-zero in can_calc_bittiming() ---
commit 1d93cc0a0370ce5feb4636b0a8c6900dd609c628
Author: Sureshkumar S <ssureshmsd7@gmail.com>
can: bittiming: fix divide-by-zero in can_calc_bittiming()
This commit patches a potential divide-by-zero in can_calc_bittiming() when
calculating the prescaler. It uses 64-bit math to prevent the 32-bit integer
multiplication of tsegall and bitrate from wrapping to zero for large bitrates.
> 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--) {
> 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 is a pre-existing issue, but missing validation for hardware-provided
bit-timing constants might allow a divide-by-zero here.
If a misbehaving or malicious USB adapter (like gs_usb) provides 0 for
btc->brp_inc, won't this division directly panic the kernel when a user with
CAP_NET_ADMIN configures the interface?
> if (brp < btc->brp_min || brp > btc->brp_max)
> continue;
>
> bitrate = priv->clock.freq / (brp * tsegall);
[Severity: High]
This isn't a bug introduced by this patch, but doesn't this calculation have
the exact same 32-bit overflow vulnerability that the patch fixes above?
Since both brp and tsegall are 32-bit unsigned integers, couldn't their product
wrap to zero for large values derived from untrusted hardware limits, causing a
divide-by-zero panic on this line?
Additionally, if the hardware provides a btc->brp_min of 0, the bounds
check above allows brp to evaluate to 0. Wouldn't that also result in a
divide-by-zero here?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260803091426.29050-1-ssureshmsd7@gmail.com?part=1
next prev parent reply other threads:[~2026-08-04 9:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 9:14 [PATCH net 0/2] can: bittiming: fix two defects in the userspace bitrate conversion Sureshkumar S
2026-08-03 9:14 ` [PATCH net 1/2] can: bittiming: fix divide-by-zero in can_calc_bittiming() Sureshkumar S
2026-08-04 9:15 ` sashiko-bot [this message]
2026-08-03 9:14 ` [PATCH net 2/2] can: bittiming: fix bitrate error calculation on unsigned operands Sureshkumar S
2026-08-04 9:15 ` 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=20260804091502.A40441F00A3A@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 \
--cc=ssureshmsd7@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.