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
Subject: Re: [PATCH can-next v4 2/6] can: bittiming: can_calc_bittiming(): catch brp * tsegall overflow
Date: Fri, 04 Dec 2026 03:51:43 +0000 [thread overview]
Message-ID: <179635630301.3142.7923136246459818126@kernel.org> (raw)
In-Reply-To: <20261202-bittiming-fix-conversion-v4-2-fae7aaaf3191@pengutronix.de>
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
next prev parent reply other threads:[~2026-12-04 3:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:57 [PATCH can-next v4 0/6] can: bittiming: fix integer overflows in the userspace bit rate conversion and reject invalid timing constants Marc Kleine-Budde
2026-12-02 13:57 ` [PATCH can-next v4 1/6] can: bittiming: can_calc_bittiming(): fix potential divide-by-zero Marc Kleine-Budde
2026-12-02 13:57 ` [PATCH can-next v4 2/6] can: bittiming: can_calc_bittiming(): catch brp * tsegall overflow Marc Kleine-Budde
2026-12-04 3:51 ` netdev-bot+sashiko [this message]
2026-12-02 13:57 ` [PATCH can-next v4 5/6] can: bittiming: can_fixup_bittiming(): reject too high values for prop-seg/phase-seg1 Marc Kleine-Budde
2026-12-02 13:57 ` [PATCH can-next v4 6/6] can: bittiming: register_candev(): reject unusable bit-timing constants Marc Kleine-Budde
2026-12-04 3:51 ` netdev-bot+sashiko
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=179635630301.3142.7923136246459818126@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=25031212351@stu.xidian.edu.cn \
--cc=byu@xidian.edu.cn \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=socketcan@hartkopp.net \
--cc=stable@vger.kernel.org \
--cc=wencheng@xidian.edu.cn \
--cc=wg@grandegger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox