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=1796177275; b=eLw99x0WvgnKPu9fZbdoekoTNt6gAuOnt+eGiUagPimS+Cs+x9xlyBlPu5OljIrHfApe bG5mUlZ+7+up/q4bT4zoORgy3i1kplgojZt4jb/p99dhePNiQO+GuJgTA94vXabPSZSci pink63Jm10AY4PusMQgvYnLQRKwC8qGyVAaaZELY6RoGRqWNTz++d5At3Bo2jSqz87kkI p5PlDaOBzy0x3RGFnAW+eQfErMrmN4omzrS99wppXp6Co+k7AikfU1AufTIm8tItDEvl8 HyaLzqsS60yySKpjKj4vME2IfIVuLOWnI/1rfupS9yf2DkHfQ3R67Njzgd+SOGrtv8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796177275; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=dfPVgJKNiRaFsikFzbPsK26gwpaRgm/CeRJxIew4RDs=; b=pPIfffPSsmQOM0v7X+hY+X/uBsaPxIsHp7bff+tKuhxTscSFJ5QC19HeoCejRw+EU+Kx Dl/+WDWNQC9rtnawPO/sXfEy5ff7SrurHVEW0S7OzAJHCsuaKJ0LsvuCUwy3Mj1ntWtgb jGZs/A7qtt7bw57pRJXoTcs+ekZzpup7Pt5LwRZUA/lKgkJb1xlY0TwsSMFii2aOdN/Mj cgnyd4lQ4IsJqJYdyXwfNtbbctJ/QGF7xgIpvAb02F/zA4Kn5cVIYOXiXPiDtRQCyXUzR Job1xWau8kp/jjcb5xUa2e+2mNdPhzDEYs3thuNFgxzsC7RtANC74GEPB3mlcefua/Q== 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=gYMOWpww; 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 61F23606A327; Wed, 2 Dec 2026 02:07:55 +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=gYMOWpww Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97EFA1F000C1; Wed, 2 Dec 2026 02:07:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796177275; bh=dfPVgJKNiRaFsikFzbPsK26gwpaRgm/CeRJxIew4RDs=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=gYMOWpwwvnbBK2BnHphrv+DUaOwKUwNCisfQAW/ZcOUDmOvWpy4VZaBmyyyVYV8no XDuywtV8n1xNDVUwvHaf6JRRyUm+llS9uLAxQgmr6ZhcG6lW+Jz3fUpI9+v1w2lriH bTwVYexjpDqB8FuUlr2fqaThpiY5Zf0n4S8b+J+rGj+6acl/ehFnkO+kour0dJCAhz /f9sV9lNYFpeU6hlGPvG1Z7apzX4KnHZqGRL9Ho+1IPO0N3J/4bnO8FcIRWjVF7Xgm 4Bj5cndp9BE1zqbyujy7dEE7Mfq1Fo3YezAE2WX7o1DJa27QJSmkub1TCXsKgdCJcP 4fgQxwfkvh8ig== Subject: Re: [PATCH can-next v3 2/6] can: bittiming: can_calc_bittiming(): fix bitrate error calculation on unsigned operands From: netdev-bot+sashiko@kernel.org To: mkl@pengutronix.de Cc: mailhol@kernel.org, socketcan@hartkopp.net, wg@grandegger.com, davem@davemloft.net, kernel@pengutronix.de, linux-can@vger.kernel.org, 25031212351@stu.xidian.edu.cn, stable@vger.kernel.org, byu@xidian.edu.cn, wencheng@xidian.edu.cn, kuba@kernel.org Date: Wed, 02 Dec 2026 02:07:54 +0000 Message-ID: <179617727420.3142.17006311535952509360@kernel.org> In-Reply-To: <20261130-bittiming-fix-conversion-v3-2-e61f92dc76d0@pengutronix.de> References: <20261130-bittiming-fix-conversion-v3-2-e61f92dc76d0@pengutronix.de> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Medium] The commit message of "can: bittiming: can_calc_bittiming(): fix bitrate error calculation on unsigned operands" describes a user-… -- can: bittiming: can_calc_bittiming(): fix bitrate error calculation on unsigned operands This commit replaces abs(bt->bitrate - bitrate) with abs_diff(bt->bitrate, bitrate) in can_calc_bittiming(). The error between the requested and the computed bitrate is then calculated using only unsigned arithmetic. > Both operands are unsigned int, so the subtraction wraps instead of > becoming negative, and abs() resolves an unsigned int argument to its > int branch. A wrapped difference is therefore reinterpreted as a small > positive value instead of the large error it actually represents. > > A requested bitrate far above anything the controller can reach then > passes the CAN_CALC_MAX_ERROR gate. On a dummy_can device with a 160 MHz > clock, requesting 4294967294 bps reports an error of 0.01%, configures > 415584 bps and returns success to userspace, where -EINVAL is expected. [Severity: Medium] Does this reproducer still work on top of the previous patch in the series, "can: bittiming: can_calc_bittiming(): fix potential divide-by-zero"? That patch added this check in can_calc_bittiming(). It runs before brp, bitrate and bitrate_error are computed: drivers/net/can/dev/calc_bittiming.c:can_calc_bittiming() { ... if (check_mul_overflow(tsegall, bt->bitrate, &div)) continue; ... } dummy_can sets tseg1_min = 2 and tseg2_min = 2. The loop therefore only runs while tseg >= 8, so tsegall is always >= 5. Since 5 * 4294967294 overflows u32, every candidate takes the continue. best_bitrate_error then stays at UINT_MAX and the computed error is about 10000 (100%). That is above CAN_CALC_MAX_ERROR, so the function returns -EINVAL. The 415584 bps result (tsegall = 385, brp = 1) only seems reachable when the multiplication is allowed to wrap, which means without the previous patch. More generally, any iteration that reaches the abs_diff() line has tsegall >= 2, so bt->bitrate <= UINT_MAX / 2 = INT_MAX. The computed bitrate = freq / (brp * tsegall) is also <= INT_MAX. So the difference always lies within [-INT_MAX, INT_MAX]. In that range, abs() through its int branch already returns the exact magnitude, and abs_diff() gives the same result. The description of the mechanism also looks inverted. When the subtraction wraps (bitrate > bt->bitrate), abs() through int recovers the correct value. The failing case in the example (4294967294 vs 415584) is a difference that does not wrap. It is larger than INT_MAX, so it reads as a negative int, and abs() of that gives 415586. Could the commit message either say that the issue is only reachable without the overflow check from the previous patch, or describe this change as hardening on top of it? The Fixes: tag together with the current reproducer suggests a live userspace-visible bug in this tree. -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-bittiming-fix-conversion-v3-0-e61f92dc76d0%40pengutronix.de