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=1796288250; b=laok2BjagDqbs07g++Tu3HD5h9QhagDYg5507HUZDghDnYWQbKehv/BGrvZTH8SenK70 2p2fK5CdqbFXxGDdU4dsNfbG1CdjRcve/qCbltn2qcspbT/DjTTwz7ApDsnydxuc72p5O zVxWDCPVBOR2QDqJWqjAtk5uYWG0+g2u+zYNvQ2ir1X+zgaNXxF6kpRNiHvdGuZJ71ev9 wS8x7kFzXX+K9nv6hngxOwaHjWXYBDodSgqR90VSweU8dmJWtLALGJMcAKHKqustcW6WK CcYeTGJZVL8sdQpzG1/D0Dq1qzXUwf+GcpeK0RCAQZATp743t8WXn0uX+674dGcCcCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288250; 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=YOAvfZVUIYNHZuvrMFUf/mRTcAfOIP3f2HB6WBjyr98=; b=QF0lf4SfMqrhZxwyZCKdAOZzoSZjgZs/YPbpSrkWP/kfiTaofJ19JWWCIsWvEjmAcbeJ QM6KO9r5yP7FnSI4HCPtAIPAddOLZqWiTHdA6Mas5p/yW5KeCH1sFH3Pu5MERpNB/eUpi 4H/m9rM/Eu/9Smyknp9zTHfAyBSwgaGgv3QhQGrtRsaDs+X50nulDcLAcx7KZTYNvy+Ch 1z/MvMOK6zwUhyMTB4jhlGayfokR7OupqXDrdEa3C2OZo86/eE0y43h84dQnoRepQOm5B 9Clcm3rv+wfYcWVxXB5Q/vBvYHMWR3foo4ZcZMraNiOtDRgdbfinlK9GNDiUnj1mRJA== 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=Lzxq8Q2V; 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 B719F606A32C; Thu, 3 Dec 2026 08:57:30 +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=Lzxq8Q2V Received: by smtp.kernel.org (Postfix) with ESMTPSA id 046431F000C1; Thu, 3 Dec 2026 08:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796288250; bh=YOAvfZVUIYNHZuvrMFUf/mRTcAfOIP3f2HB6WBjyr98=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Lzxq8Q2VO+vSa4MZM4w2MHnVBgoRxAQ+ggYyfvXD6Izn4up1WVjbPe5ICW5e+GXkl FBLD8/2FFjc7N6bsm4yKYTqL9qX4k8l4YNHVpHcTc74hA3fQ4ttzWWVQYluzHIpGSD VzTcVeg+UR33UfjrD9GCuqsKa8jPXtWpB7BpWXQuJBMsB/W1vraGz6fVNtcAwJDw76 pOltoBTN+xoGAS5jvL3wshhDjwFtsBH1sVes7gsSoSjCjs6E616y+j4QRIgmWBWEpi Tq0YD6bRM/kh8KSxR2vXBCrHKKa4c3fzGVZiMzFnCgxXZJdXGJY3F2A8YTZV61fCdF jtaOvtjxhKCXw== Subject: Re: [PATCH net-next v18 2/6] net: dsa: motorcomm: use max_ports in series for port bounds checking From: netdev-bot+sashiko@kernel.org To: kyle.switch@motor-comm.com Cc: andrew@lunn.ch, olteanv@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mmyangfl@gmail.com, horms@kernel.org, linux@armlinux.org.uk, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, david.laight.linux@gmail.com, ming.xu@motor-comm.com, xiaolin.xu@motor-comm.com, jianmin.wang@motor-comm.com, wei.zhang@gl-inet.com, sijia.huang@gl-inet.com Date: Thu, 03 Dec 2026 08:57:28 +0000 Message-ID: <179628824852.3146.765398832831553826@kernel.org> In-Reply-To: <20261202084022.3716891-3-kyle.switch@motor-comm.com> References: <20261202084022.3716891-3-kyle.switch@motor-comm.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@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 2 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · Low: 1 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] yt921x_mbus_int_init() in drivers/net/dsa/motorcomm/mdio_bus.c leaks the mii_bus on the new max_ports error path. - [Low] The commit message says the patch will "Validate max_ports against the size of priv->ports (and the u32 width of phy_mask) before… -- net: dsa: motorcomm: use max_ports in series for port bounds checking This commit replaces the hardcoded YT921X_PORT_NUM with the per-series max_ports field. The field is now used in the internal MDIO bus read and write bounds checks and in the phy_mask setup in yt921x_mbus_int_init(). It also adds a validation of max_ports before it is used in GENMASK(). > Validate max_ports against the size of priv->ports (and the u32 > width of phy_mask) before using it in GENMASK(). [Severity: Low] Does the code in yt921x_mbus_int_init() actually check the u32 width of phy_mask? The only check is: if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) { Nothing compares max_ports against 32 or BITS_PER_TYPE(u32). There is also no static_assert() or BUILD_BUG_ON() that ties ARRAY_SIZE(priv->ports) to the width of mbus->phy_mask. The u32 bound only holds because struct yt921x_priv still declares: struct yt921x_port ports[YT921X_PORT_NUM]; If priv->ports ever grew past 32 entries, GENMASK(max_ports - 1, 0) would get an out-of-range shift that this check would not catch. The commit message also says this "removes family-specific constants from the common code path". The new bound is still YT921X_PORT_NUM through ARRAY_SIZE(priv->ports), so a family with more than 11 ports would be rejected rather than supported. Could the message be reworded, or an explicit check be added for the u32 width? > diff --git a/drivers/net/dsa/motorcomm/mdio_bus.c b/drivers/net/dsa/motorcomm/mdio_bus.c > index a4062e6b0f000..a06e2cc94a3e2 100644 > --- a/drivers/net/dsa/motorcomm/mdio_bus.c > +++ b/drivers/net/dsa/motorcomm/mdio_bus.c [ ... ] > @@ -155,6 +155,7 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) > { > struct device *dev = yt921x_priv_to_device(priv); > struct mii_bus *mbus; > + u32 max_ports; > int res; > > mbus = mdiobus_alloc(); > @@ -167,7 +168,12 @@ int yt921x_mbus_int_init(struct yt921x_priv *priv, struct device_node *mnp) > mbus->read = yt921x_mbus_int_read; > mbus->write = yt921x_mbus_int_write; > mbus->parent = dev; > - mbus->phy_mask = (u32)~GENMASK(YT921X_PORT_NUM - 1, 0); > + max_ports = priv->series->max_ports; > + if (max_ports == 0 || max_ports > ARRAY_SIZE(priv->ports)) { > + dev_err(dev, "Invalid max_ports: %u\n", max_ports); > + return -EINVAL; ^^^^ [Severity: Medium] Does this early return leak the mii_bus allocated by mdiobus_alloc() just above? mdiobus_alloc() is not devm-managed. priv->mbus_int is only set on success, so the caller has no pointer it could free: drivers/net/dsa/motorcomm/chip.c:yt921x_dsa_setup() { ... res = yt921x_mbus_int_init(priv, child); of_node_put(child); if (res) return res; ... } The of_mdiobus_register() failure path later in the same function does call mdiobus_free(mbus) before returning. The leak is also still there after the later patch in this series, "net: dsa: motorcomm: use GENMASK_U32() for mbus phy_mask". That patch only changes the phy_mask line. Could the max_ports check be moved before mdiobus_alloc()? Alternatively, mdiobus_free(mbus) could be called before returning -EINVAL. > + } > + mbus->phy_mask = (u32)~GENMASK(max_ports - 1, 0); > > res = of_mdiobus_register(mbus, mnp); > if (res) { -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202084022.3716891-1-kyle.switch%40motor-comm.com