From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796037916; b=No96xFw3A29g+WhJL2y1EBTw14Wfg7UNFLDDwyvqNU5WVyil1ijil81ygYxzmcKUOJ+N K4gr+buB3qb377rQRMj+CKdEmM/RIQ46xVQo5aLxV1w7qzAGGW68jU2+sR8pqhe6gCkJD 6leBZ61ZfepDq5+zuBIDXY6dfGS765dytXQFWHhAsNjsUUQnGCuK3P1VjQ00TrkQwlRfH tCYoca2uypu8dL+3qrvaCTzUMFmlKLQxsEOmguBLuE+kkOObFrQInBGoRwscAZPqJPAhl q6jetmPk6teLLkrM6R9OIleNHv59SbjA5QGVc47LqzWYLlSCoe3spGVkus4kaQC7VHw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796037916; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=OdwSxWXEGJ8kmKOwh0VwZFcTS5KXn+utnfKqVIdaijM=; b=wPPCuvcSWGaCCuQMfu9zds9PBR1Qqxw9J5EGaRmBotzU+Z10qw++s7Ubat2yVRNvaKNu 6p/9LpeQUwgvG6929lvfK0AYkeM9dAV0bKIHyblws6OppTPay1REUkMUP2YKnD/CSZO7m gIn7+Lbw8XwnxMMFOkmKAA5bHccPu8s/y4OD1D0twbQ4X3KqwXzYPjePUqPRNV2o4UnW7 HQO/527/xmRabka+zD6lV6oEcdX18uVSXILDY8sBGLH/8ogHulPLLsTBQ+hNHswImu9WY PhSLl2s8qVBrtFedyGgH3J0vrGaPrteu7v8DQhZrU14qCIHsecOAtqNJWYCnzKp7WmA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QaPbk76X; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F281606A31C for ; Mon, 30 Nov 2026 11:25:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QaPbk76X Received: by smtp.kernel.org (Postfix) with ESMTPSA id 585C81F00897; Mon, 30 Nov 2026 11:25:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796037915; bh=OdwSxWXEGJ8kmKOwh0VwZFcTS5KXn+utnfKqVIdaijM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QaPbk76XASDI57G9Z1IirgaaaPx300os6ao0AQnb7gVd5aq1KmvEOpabkFLGqHpGQ hddL+Ei+R/R39XpczkwmulPKf9i/T7aSl9lB793a0CyX1+LiCcvOL/6pyKj701AsUZ 4S6j6HFlQVi8fcPbDEqWa5UzDUg+qr0VeQgy3kT0aPeX36R8znLptUaP7xke/Fbe7S uS1jVmH/2c/AHn/VzCe0cePfLL2mHTK6oVwe7zGn/ekyarwSkcujnE/LouOkZrGmhz PtYmWlqwQUA0qyTzOBDraxNBcAejnWlS055iQ+Pb/fpf7ne/s3c+5pPX7UKwQZcQiD HJDlo9WlE9Llw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH can-next v2 4/4] can: dev: reject unusable bit-timing constants Reply-To: sashiko-reviews@lists.linux.dev To: "Marc Kleine-Budde" Cc: linux-can@vger.kernel.org, "Oliver Hartkopp" , "Vincent Mailhol" , "Oleksij Rempel" In-Reply-To: <20261130-bittiming-fix-conversion-v2-4-36e8a0275923@pengutronix.de> References: <20261130-bittiming-fix-conversion-v2-0-36e8a0275923@pengutronix.de> <20261130-bittiming-fix-conversion-v2-4-36e8a0275923@pengutronix.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 11:25:14 +0000 X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] can: dev: unbounded brp_max in can_bittiming_const_valid() allows divide by zero -- commit 9ceb7855200a9a5490de6349f2c0c3b569976b84 Author: YuanZhe Liu <25031212351@stu.xidian.edu.cn> can: dev: reject unusable bit-timing constants This commit expands bit-timing, clock frequency, and PWM constant validation during CAN device registration to prevent divide-by-zero errors and unbounded loops when configuring bit-timing parameters. > diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c > index 3207c0e08712c..67cd0d29c5f23 100644 > --- a/drivers/net/can/dev/dev.c > +++ b/drivers/net/can/dev/dev.c [ ... ] > @@ -595,15 +596,55 @@ static int can_get_termination(struct net_device *n= dev) > return 0; > } > =20 > +/* Upper bound for the bit time in time quanta. The bit times of the > + * currently supported CAN controllers are well below it, the limit keep= s the > + * time segment scan in can_calc_bittiming() bounded. > + */ > +#define CAN_MAX_BIT_TIME_TQ 1024 > + > static bool > can_bittiming_const_valid(const struct can_bittiming_const *btc) > { > - if (!btc) > - return true; > + u32 bit_time; > + > + /* Controllers may read the bit timing constants via USB, check the > + * minimum/maximum values and avoid divide by zero in the calculation. > + */ > + if (!btc->tseg1_min || btc->tseg1_min > btc->tseg1_max) > + return false; > + > + if (!btc->tseg2_min || btc->tseg2_min > btc->tseg2_max) > + return false; > =20 > if (!btc->sjw_max) > return false; > =20 > + if (!btc->brp_min || btc->brp_min > btc->brp_max || !btc->brp_inc) > + return false; > + > + if (check_add_overflow(btc->tseg1_max, btc->tseg2_max, &bit_time) || > + check_add_overflow(bit_time, CAN_SYNC_SEG, &bit_time) || > + bit_time > CAN_MAX_BIT_TIME_TQ) > + return false; [Severity: Medium] Should can_bittiming_const_valid() also verify that bit_time * btc->brp_max does not overflow u32? Without an upper bound on btc->brp_max, a USB CAN device reporting a large brp_max (such as 0x10000000 with bit_time >=3D 16) still passes registratio= n. Both can_fixup_bittiming() and can_calc_bittiming() multiply the prescaler by the bit time in 32-bit unsigned arithmetic before dividing priv->clock.freq: drivers/net/can/dev/bittiming.c:can_fixup_bittiming() { ... if (bt->brp > btc->brp_max) { NL_SET_ERR_MSG_FMT(extack, "resulting brp: %u greater than brp-max: %u", bt->brp, btc->brp_max); return -EINVAL; } bt->bitrate =3D priv->clock.freq / (bt->brp * can_bit_time(bt)); ... } When a user with CAP_NET_ADMIN configures bit-timing parameters where bt->brp * can_bit_time(bt) (or brp * tsegall in can_calc_bittiming()) is a multiple of 2^32, the 32-bit product wraps to 0 and triggers a divide-by-zero fault under RTNL. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130-bittiming-= fix-conversion-v2-0-36e8a0275923@pengutronix.de?part=3D4