can_calc_bittiming() scans the possible time segment combinations and computes the bit rate for each of them as: bitrate = priv->clock.freq / (brp * tsegall) The threshold values for brp and tsegall are set by the CAN controller. On some controllers, these values are read via USB. `brp * tsegall` is a 32 bit multiplication, so the product may overflow or wraps to zero. Check whether `brp * tsegall` exceeds the value of an unsigned int, and abort the calculation for this value if this is the case. Fixes: 39549eef3587 ("can: CAN Network device driver and Netlink interface") Cc: stable@vger.kernel.org Signed-off-by: Marc Kleine-Budde --- drivers/net/can/dev/calc_bittiming.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/dev/calc_bittiming.c b/drivers/net/can/dev/calc_bittiming.c index 8889d55fea65..cf8310537df2 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; bitrate_error = abs(bt->bitrate - bitrate); /* tseg brp biterror */ -- 2.53.0