Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH can-next v4 0/6] can: bittiming: fix integer overflows in the userspace bit rate conversion and reject invalid timing constants
@ 2026-12-02 13:57 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
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Marc Kleine-Budde @ 2026-12-02 13:57 UTC (permalink / raw)
  To: Marc Kleine-Budde, Vincent Mailhol, Oliver Hartkopp,
	Wolfgang Grandegger, David S. Miller
  Cc: kernel, linux-can, Sureshkumar S, stable, YuanZhe Liu, Bin Yu,
	Cheng Wen

This series combines all bit timing relates fixes into one series.

Patch #1 by Sureshkumar S fixes a potential divide-by-zero in
can_calc_bittiming(). If the 32 bit `tsegall * bt->bitrate` product wraps
to zero for bit rates carrying enough factors of two, the following
division faults. A bit rate of 16777216 is already enough, which is below
the 20 Mbit/s CAN XL data bit rate ceiling.

Patch #2 by me fixes fixes a similar 32 bit multiplication overflow in
can_calc_bittiming() for `brp * tsegall`.

Patch #3 by Sureshkumar S hardens the candidate rating in
can_calc_bittiming(), which applies abs() to an unsigned subtraction. A
wrapped difference is read back as a small error, so a bit rate far outside
what the controller can reach passes the 5% gate and is silently accepted
instead of rejected.

Patch #4 by me applies the same hardening to an abs on an unsigned int
subtraction in can_update_sample_point().

Patch #5 (by me) rejects too high values for prop-seg/phase-seg1 in
can_fixup_bittiming().

Patch #6 (by YuanZhe Liu) reject unusable bit timing constants while
registering CAN interfaces with register_candev().

Sureshkumar S says:

Both problems were found with a netlink fuzzer against dummy_can and
verified under KASAN in QEMU. Testing covered the unpatched tree, patch #1
alone and the full series: bit rates from 125 kbit/s to 10 Mbit/s produce
byte-identical bittiming at every step, patch #1 alone removes the oops,
and patch #3 turns the silently accepted out-of-range bit rates into
-EINVAL.

---
Changes in v4:
- reordered patches
- patch #1: reworked patch description
- patch #2: new
- patch #3: reworked patch description
- patch #4: reworked patch description
- patch #5: reworked patch description + add Fixes tag + stable on Cc
- patch #6: reworked patch description + also check brp_max
- Link to v3: https://patch.msgid.link/20261130-bittiming-fix-conversion-v3-0-e61f92dc76d0@pengutronix.de

Changes in v3:
- patch #1: reject divisor exceeding 32 bit instead of using 64 bit math
- patch #4: rename constant
- patch #5: new
- patch #6: new
- Link to v2: https://patch.msgid.link/20261130-bittiming-fix-conversion-v2-0-36e8a0275923@pengutronix.de

---
Marc Kleine-Budde (3):
      can: bittiming: can_calc_bittiming(): catch brp * tsegall overflow
      can: bittiming: can_update_sample_point(): harden sample point error calculation on unsigned operands
      can: bittiming: can_fixup_bittiming(): reject too high values for prop-seg/phase-seg1

Sureshkumar S (2):
      can: bittiming: can_calc_bittiming(): fix potential divide-by-zero
      can: bittiming: can_calc_bittiming(): harden bitrate error calculation on unsigned operands

YuanZhe Liu (1):
      can: bittiming: register_candev(): reject unusable bit-timing constants

 drivers/net/can/dev/bittiming.c      |  8 +++-
 drivers/net/can/dev/calc_bittiming.c | 17 ++++++--
 drivers/net/can/dev/dev.c            | 85 ++++++++++++++++++++++++++++++++++--
 3 files changed, 101 insertions(+), 9 deletions(-)
---
base-commit: cb9006be6e667801260d6135696979c17a8e915d
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git main
change-id: 20261021-bittiming-fix-conversion-24a033ebf153

Best regards,
--  
Marc Kleine-Budde <mkl@pengutronix.de>


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-12-04  3:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-12-02 13:57 ` [PATCH can-next v4 3/6] can: bittiming: can_calc_bittiming(): harden bitrate error calculation on unsigned operands Marc Kleine-Budde
2026-12-04  3:51   ` netdev-bot+sashiko
2026-12-02 13:57 ` [PATCH can-next v4 4/6] can: bittiming: can_update_sample_point(): harden sample point " Marc Kleine-Budde
2026-12-04  3:51   ` netdev-bot+sashiko
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox