Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH can-next v3 0/6] can: bittiming: fix defects in the userspace bit rate conversion and reject invalid timing constants
@ 2026-11-30 13:06 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
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Marc Kleine-Budde @ 2026-11-30 13:06 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 and #2 are by Sureshkumar S, they say:

can_calc_bittiming() converts a userspace supplied bit rate into hardware
timing parameters. Two defects in that conversion are fixed here, both
reachable through IFLA_CAN_BITTIMING on any CAN device that provides a
bittiming_const, and both caused by 32 bit arithmetic on a value that
userspace fully controls.

Patch #1 fixes a potential divide-by-zero. 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 fixes the candidate rating, 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.

Both 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 #2
turns the silently accepted out-of-range bit rates into -EINVAL.

In addition to Sureshkumar S's patches fix another abs() on an unsigned
subtraction in patch #3,

YuanZhe Liu's patch #4 rejects unusable bit timing constants.

---
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_update_sample_point(): fix sample point error calculation on unsigned operands
      can: bittiming: can_bittiming_const_valid(): reject unusable BRP bit timing constant
      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(): fix 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 | 12 ++++--
 drivers/net/can/dev/dev.c            | 82 ++++++++++++++++++++++++++++++++++--
 3 files changed, 94 insertions(+), 8 deletions(-)
---
base-commit: 81159a672c331993566a12ad8e07532b38355cba
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git master
change-id: 20261021-bittiming-fix-conversion-24a033ebf153

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


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

end of thread, other threads:[~2026-12-02  2:08 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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