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=1796356308; b=l1jff40bUu8MtqW5urwGCDrJwVmO8rUf6Opk5YpLI6cKpe19nB/OVnqLCo73iXwfPRFM IwB6WkkhO0KT+OM5iIVnewe9Kj+lP0aaSg85i1ksQ0E747aO7Wy38yADtTEq0QH/5Zh7t ZRhIS6F4HEP2UCkOLi/3fRcdAVlIfbrWJaheauF0mBwpVOwSPzsgIy2uNzO1gQ0bhBNAl QeqPIGuyEtrqjGBJZ+PS86Hqj7u0WrrmAL6QO8kSRiIzocbr3+HMVfWWz+S/biKnxj2h3 5szDLpbe2z5YibbeXuqsEaEvLSNpJdit6mU7iXLG43AFPJAXECiQ4eqZF0Ba85eB5RQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356308; 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=Yh+NMrhsMVzucZdielNyx6uDZOMSy52y74vlT3INJGA=; b=lWaKXJJsC+jPahk+eCb/oPRJo+l8ufUyKE8MZk4iQiMfv4N34igyufeXBqedaW2WL2oF XBNeiJh18fIDS4KhvP7FVs0cA09Cmw/X9ygz9ytDHBkG8hq96nX4OINDf1zahZ4fpgCNl GRHyPShDGpe6Ip6pGcL4LX/9JkcoKeEwywuF86PV0ayJusQFhteAhjTWDtKnKK3uaqXAq mVpwDSydDhMs7F8MfBdi06AsNb0W2CtXqkc2Leyq3Y8eYx2aDPDKfhFQdxyBvRhvr1N9A OVxQ1P2VQZyU/yfJc7ukann4qAqkI1xQdTvsEFfVUthbBCNeZk/wlfrCi9cF5n6khkw== 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=RETlh+Q7; 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 EC45C606A32D; Fri, 4 Dec 2026 03:51:47 +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=RETlh+Q7 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BD891F000CE; Fri, 4 Dec 2026 03:51:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796356307; bh=Yh+NMrhsMVzucZdielNyx6uDZOMSy52y74vlT3INJGA=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=RETlh+Q7oTBIH5Q9xu0HXg6MMOPYQ/ypwGtZQoT/C9zI6H5DAOk3ZGWgI+5UnxG2X bqPZ5IS763bRB6u9QJ5JNrjO8Ec3iePNWgmydGq9cevVzGQAcMY2KexIYc0hxVw49g dN0bWtM9bspxPY7p+DOqSsA4ATuRL7LnBlNf0z92V4WBSvsqw6xwPSgaXgzVfj8zoA ZT0e+txp3hO097Y3dxgRH0oh0t/8QcIRiP1b+aSX19yW6bMbIPMrYXwvOjBJEChLDH mHV2RI5AEnOU+zRSS0VwJNK0mst9F1d/3BcQo0XzeLJuFyd1omF/vyIfvETv1TeqCv 7OIQQ22vxDTZg== Subject: Re: [PATCH can-next v4 6/6] can: bittiming: register_candev(): reject unusable bit-timing constants 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: Fri, 04 Dec 2026 03:51:46 +0000 Message-ID: <179635630671.3142.14619902516001059445@kernel.org> In-Reply-To: <20261202-bittiming-fix-conversion-v4-6-fae7aaaf3191@pengutronix.de> References: <20261202-bittiming-fix-conversion-v4-6-fae7aaaf3191@pengutronix.de> X-sashiko-severity: Low Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: stable@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 more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin. Low priority / nit picks for your consideration: - [Low] can_pwm_const_valid() (drivers/net/can/dev/dev.c:643-659) checks `pwms_min + pwml_min` for overflow but puts no bound on `pwms_max +… Pre-existing issues: - [High] This problem wasn't introduced by this patch, but the patch hardens can_calc_pwm() against bad registered constants and leaves a… -- can: bittiming: register_candev(): reject unusable bit-timing constants This commit tightens can_bittiming_const_valid() so it rejects zero or inverted tseg and brp ranges, a zero brp_inc, bit times above CAN_BIT_TIME_TQ_MAX and a brp_max above CAN_BITTIMING_CONST_BRP_MAX. It also adds can_pwm_const_valid() for the CAN XL PWM constants. register_candev() now rejects a zero clock frequency and validates the constants along the CC -> FD -> XL -> PWM chain. > diff --git a/drivers/net/can/dev/dev.c b/drivers/net/can/dev/dev.c > index 3207c0e08712c..50fd17035d8f6 100644 > --- a/drivers/net/can/dev/dev.c > +++ b/drivers/net/can/dev/dev.c [ ... ] > @@ -595,15 +596,65 @@ static int can_get_termination(struct net_device *ndev) [ ... ] > +static bool > +can_pwm_const_valid(const struct can_pwm_const *pwm_const) > +{ > + u32 shortest_symbol; > + > + if (pwm_const->pwms_min > pwm_const->pwms_max || > + pwm_const->pwml_min > pwm_const->pwml_max || > + pwm_const->pwmo_min > pwm_const->pwmo_max) > + return false; [Severity: Low] Should the maxima be bounded here as well? Only pwms_min + pwml_min is checked for overflow. can_pwm_changelink() limits the PWMS and PWML values from user space only to [pwms_min, pwms_max] and [pwml_min, pwml_max], and then passes them to can_validate_pwm_bittiming(): drivers/net/can/dev/bittiming.c:can_validate_pwm_bittiming() { ... if (xl_bit_time_tqmin % (pwm->pwms + pwm->pwml) != 0) { ... } That sum is computed in u32. Take clock.freq = 1 GHz, pwms = 10 and pwml = 2^32 - 10. The earlier checks all pass: pwms_ns + pwml_ns wraps to 0, so it passes the CAN_PWM_NS_MAX check pwms_ns >= CAN_PWM_DECODE_NS pwms < pwml pwml_ns - pwms_ns = 2^32 - 20 >= 2 * CAN_PWM_DECODE_NS Then pwm->pwms + pwm->pwml wraps to 0. If a driver registers a pwm_const with pwms_max + pwml_max >= 2^32, can this divide by zero? No in-tree driver has such constants today. dummy_can is the only pwm_const user, and its values are small and static. Would it be enough to reject a pwms_max + pwml_max that overflows, or to cap each maximum at CAN_BIT_TIME_TQ_MAX * CAN_BITTIMING_CONST_BRP_MAX? > + > + /* can_calc_pwm() divides by the shortest PWM symbol. */ > + if (check_add_overflow(pwm_const->pwms_min, pwm_const->pwml_min, > + &shortest_symbol) || !shortest_symbol) > + return false; [Severity: High] This is a pre-existing issue, but this check is meant to protect the divisions in can_calc_pwm(), and that function has a second divisor that can still be zero: drivers/net/can/dev/calc_bittiming.c:can_calc_pwm() { u32 xl_tqmin = can_bit_time_tqmin(&priv->xl.data_bittiming); u32 xl_ns = can_tqmin_to_ns(xl_tqmin, priv->clock.freq); ... int pwm_per_bit_max = xl_tqmin / (pwm_const->pwms_min + pwm_const->pwml_min); ... for (pwm_per_bit = DIV_ROUND_UP(xl_ns, CAN_PWM_NS_MAX); pwm_per_bit <= pwm_per_bit_max; pwm_per_bit++) if (xl_tqmin % pwm_per_bit == 0) break; ... } Suppose priv->xl.data_bittiming is all zero while CAN_CTRLMODE_XL_TMS is set. Then xl_tqmin and xl_ns are both 0, so pwm_per_bit and pwm_per_bit_max both start at 0. The loop body then computes 0 % 0. Can that state be reached? With the interface down, can_ctrlmode_changelink() commits the new flags before any bit timing is validated: priv->ctrlmode &= ~cm->mask; priv->ctrlmode |= maskedflags; Take a changelink request with mask = flags = XL | XL_TMS, plus IFLA_CAN_BITTIMING and IFLA_CAN_XL_DATA_BITTIMING. If it later fails in can_get_bittiming() or in the XL can_dbt_changelink(), can_changelink() returns the error without rolling back ctrlmode. XL_TMS stays set and xl.data_bittiming stays zeroed. A second changelink can then carry an IFLA_INFO_DATA with no CTRLMODE, BITTIMING or XL_PWM attributes. That request reaches: can_changelink() can_pwm_changelink() can_calc_pwm() can_pwm_changelink() only checks XL_TMS and pwm_const before calling it: if (!(priv->ctrlmode & CAN_CTRLMODE_XL_TMS)) return 0; ... if (!pwm_nla) return can_calc_pwm(dev, extack); Triggering this needs CAP_NET_ADMIN and a driver that sets xl.pwm_const and supports XL_TMS, such as dummy_can in-tree. The divide error happens while RTNL is held. Should can_pwm_changelink() or can_calc_pwm() check that the XL data bit timing has been configured? Alternatively, should can_changelink() restore ctrlmode when a later step fails? > + > + return true; > } [ ... ] -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202-bittiming-fix-conversion-v4-0-fae7aaaf3191%40pengutronix.de