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 v3 5/6] can: bittiming: can_bittiming_const_valid(): reject unusable BRP bit timing constant
Date: Wed, 02 Dec 2026 02:07:57 +0000 [thread overview]
Message-ID: <179617727792.3142.16790870159500847336@kernel.org> (raw)
In-Reply-To: <20261130-bittiming-fix-conversion-v3-5-e61f92dc76d0@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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] The commit message understates the bug and lacks Fixes: and
Cc: stable tags.
--
can: bittiming: can_bittiming_const_valid(): reject unusable BRP bit timing constant
This commit caps brp_max at 65536 in can_bittiming_const_valid(). Drivers
that read their bit timing constants from a USB device can then no longer
register a brp_max large enough to overflow brp * can_bit_time() in
can_fixup_bittiming() and can_calc_bittiming().
> Controllers may read their bit timing constants via USB, limit `brp_max` to
> a sensible value to avoid overflows in `can_fixup_bittiming()` and
> `can_calc_bittiming()`.
[Severity: Medium]
Should the commit message say that this overflow ends in a divide by zero?
Should it also carry Fixes: and Cc: stable tags?
Before this patch, the only limit on brp_max was brp_min <= brp_max. gs_usb
and ucan take both brp_max and clock.freq from the device. The previous
patch limits the bit time to 1024 tq, but the u32 products used as divisors
can still wrap to 0.
In can_fixup_bittiming(), take clock.freq = 80 MHz, a user supplied tq of
52428800, brp_inc = 1 and a device reported brp_max >= 2^22. brp then ends
up as 2^22:
drivers/net/can/dev/bittiming.c:can_fixup_bittiming() {
...
bt->bitrate = priv->clock.freq / (bt->brp * can_bit_time(bt));
...
}
With a bit time of 1024, the divisor is 2^32, which wraps to 0.
In can_calc_bittiming(), take clock.freq = 0xFFFFFFFF, tseg1_max +
tseg2_max = 1023 and a requested bitrate of 1. On the first iteration
tsegall = 1024 and div = 1024, so brp = 0xFFFFFFFF / 1024 + 1 = 2^22:
drivers/net/can/dev/calc_bittiming.c:can_calc_bittiming() {
...
bitrate = priv->clock.freq / (brp * tsegall);
...
}
Here brp * tsegall also wraps to 0.
A CAP_NET_ADMIN user can reach both paths by sending IFLA_CAN_BITTIMING,
which goes through can_changelink() under RTNL. The new check limits the
product to 2^16 * 2^10, so the code change itself looks complete.
The previous patch in the series, "can: bittiming: register_candev():
reject unusable bit-timing constants", carries Fixes: d58ac89d0d38 and
Cc: stable. It also says such devices should "fail to probe instead of
taking the kernel down later".
If stable trees pick up only that patch, wouldn't this divide by zero
still be reachable there?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-bittiming-fix-conversion-v3-0-e61f92dc76d0%40pengutronix.de
next prev parent reply other threads:[~2026-12-02 2:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:06 [PATCH can-next v3 0/6] can: bittiming: fix defects in the userspace bit rate conversion and reject invalid timing constants Marc Kleine-Budde
2026-11-30 13:06 ` [PATCH can-next v3 1/6] can: bittiming: can_calc_bittiming(): fix potential divide-by-zero Marc Kleine-Budde
2026-12-02 2:07 ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 2/6] can: bittiming: can_calc_bittiming(): fix bitrate error calculation on unsigned operands Marc Kleine-Budde
2026-12-02 2:07 ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 3/6] can: bittiming: can_update_sample_point(): fix sample point " Marc Kleine-Budde
2026-12-02 2:07 ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 4/6] can: bittiming: register_candev(): reject unusable bit-timing constants Marc Kleine-Budde
2026-12-02 2:07 ` netdev-bot+sashiko
2026-11-30 13:06 ` [PATCH can-next v3 5/6] can: bittiming: can_bittiming_const_valid(): reject unusable BRP bit timing constant Marc Kleine-Budde
2026-12-02 2:07 ` netdev-bot+sashiko [this message]
2026-11-30 13:06 ` [PATCH can-next v3 6/6] can: bittiming: can_fixup_bittiming(): reject too high values for prop-seg/phase-seg1 Marc Kleine-Budde
2026-12-02 2:07 ` 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=179617727792.3142.16790870159500847336@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