From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7E601D26F2; Tue, 8 Oct 2024 12:19:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728389994; cv=none; b=M83meJ6GkhBIEMACVFiFQ87FDscfWLbuq3nxT/k9Xayx6EK07uHzuxNI8NjMifJ6tCbzPDV7EWZnq/LDD/u+32LH6UNt9eOSmfYH3HrwaqFbEhRYOmTIyQinTt5DYF2BafgGsYaJRekk+ofGVInpo+WVJU1b/vqV2yt3PWqZLc8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728389994; c=relaxed/simple; bh=rAAFVVoI0mUr4qS62z7cZZZgVqbh6vTWg3igY38gPqs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C8RJQo5fVQx/8busVg43dt0fPL4RzqU7bIW7tx9AGsobrqoJRcot1d11P15pt67c3257hfTn1ynX0Q4xJtbx7cqLMM5snJH5bBtuJpBmWPRG8T/NLMpsIcRbcgD9K/e2PbSw4NO5C53R1NkyqJMaoz5GuwJbtEOqJVN1kdiuzjQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=igei3m+S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="igei3m+S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2BCAC4CEC7; Tue, 8 Oct 2024 12:19:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728389994; bh=rAAFVVoI0mUr4qS62z7cZZZgVqbh6vTWg3igY38gPqs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=igei3m+SaXAr0Wp+tRyR1M83qwXrWJ5x5fgMn4D2fubgxNqoPY8GgsYpbhjRsUkah 7OwoyodqS3yvh89xsiF29tGMlmZj8maglPtadKMxJq8mSQ8dS9KyNLOy6bt1fyXudR P+5cGgAa1Nr4AJjI15x4QcixrZBFNlfCubE3nDU4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Niklas=20S=C3=B6derlund?= , Florian Fainelli , Andrew Lunn , Yoshihiro Shimoda , Geert Uytterhoeven , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.10 127/482] net: phy: Check for read errors in SIOCGMIIREG Date: Tue, 8 Oct 2024 14:03:10 +0200 Message-ID: <20241008115653.302928313@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241008115648.280954295@linuxfoundation.org> References: <20241008115648.280954295@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Niklas Söderlund [ Upstream commit 569bf6d481b0b823c3c9c3b8be77908fd7caf66b ] When reading registers from the PHY using the SIOCGMIIREG IOCTL any errors returned from either mdiobus_read() or mdiobus_c45_read() are ignored, and parts of the returned error is passed as the register value back to user-space. For example, if mdiobus_c45_read() is used with a bus that do not implement the read_c45() callback -EOPNOTSUPP is returned. This is however directly stored in mii_data->val_out and returned as the registers content. As val_out is a u16 the error code is truncated and returned as a plausible register value. Fix this by first checking the return value for errors before returning it as the register content. Before this patch, # phytool read eth0/0:1/0 0xffa1 After this change, $ phytool read eth0/0:1/0 error: phy_read (-95) Signed-off-by: Niklas Söderlund Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn Reviewed-by: Yoshihiro Shimoda Tested-by: Yoshihiro Shimoda Reviewed-by: Geert Uytterhoeven Link: https://patch.msgid.link/20240903171536.628930-1-niklas.soderlund+renesas@ragnatech.se Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/phy/phy.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index c4236564c1cd0..8495b111a524a 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -342,14 +342,19 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) if (mdio_phy_id_is_c45(mii_data->phy_id)) { prtad = mdio_phy_id_prtad(mii_data->phy_id); devad = mdio_phy_id_devad(mii_data->phy_id); - mii_data->val_out = mdiobus_c45_read( - phydev->mdio.bus, prtad, devad, - mii_data->reg_num); + ret = mdiobus_c45_read(phydev->mdio.bus, prtad, devad, + mii_data->reg_num); + } else { - mii_data->val_out = mdiobus_read( - phydev->mdio.bus, mii_data->phy_id, - mii_data->reg_num); + ret = mdiobus_read(phydev->mdio.bus, mii_data->phy_id, + mii_data->reg_num); } + + if (ret < 0) + return ret; + + mii_data->val_out = ret; + return 0; case SIOCSMIIREG: -- 2.43.0