In can_fixup_bittiming() the sum pf `bt->prop_seg + bt->phase_seg1` is calculated. These are user space supplied values, and the sum can overflow and still pass the following tseg1_min and tseg1_max checks. Refuse too high values for bt->prop_seg and bt->phase_seg1 by using check_add_overflow() to calculate the sum. Closes: https://sashiko.dev/#/bug/linux-afe8ea64-0e1f-42a4-a82c-6275ddeeaebc 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/bittiming.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/dev/bittiming.c b/drivers/net/can/dev/bittiming.c index 8f82418230ce..40a571f6f939 100644 --- a/drivers/net/can/dev/bittiming.c +++ b/drivers/net/can/dev/bittiming.c @@ -51,11 +51,17 @@ static int can_fixup_bittiming(const struct net_device *dev, struct can_bittimin const struct can_bittiming_const *btc, struct netlink_ext_ack *extack) { - const unsigned int tseg1 = bt->prop_seg + bt->phase_seg1; const struct can_priv *priv = netdev_priv(dev); + unsigned int tseg1; u64 brp64; int err; + if (check_add_overflow(bt->prop_seg, bt->phase_seg1, &tseg1)) { + NL_SET_ERR_MSG_FMT(extack, "prop-seg + phase-seg1: greater than tseg1-max: %u", + btc->tseg1_max); + return -EINVAL; + } + if (tseg1 < btc->tseg1_min) { NL_SET_ERR_MSG_FMT(extack, "prop-seg + phase-seg1: %u less than tseg1-min: %u", tseg1, btc->tseg1_min); -- 2.53.0