lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D2F2Y45Y1LQS.8GN3PG7ZYAPB@walle.cc>
Date: Tue, 02 Jul 2024 15:16:21 +0200
From: "Michael Walle" <michael@...le.cc>
To: "Aleksandr Mishin" <amishin@...rgos.ru>
Cc: "Andrew Lunn" <andrew@...n.ch>, "Heiner Kallweit"
 <hkallweit1@...il.com>, "Russell King" <linux@...linux.org.uk>, "David S.
 Miller" <davem@...emloft.net>, "Eric Dumazet" <edumazet@...gle.com>, "Jakub
 Kicinski" <kuba@...nel.org>, "Paolo Abeni" <pabeni@...hat.com>,
 <netdev@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
 <lvc-project@...uxtesting.org>
Subject: Re: [PATCH net v2] net: phy: mscc-miim: Validate bus frequency
 obtained from Device Tree

Hi,

Please post a new version of a patch at the earliest after 24 hours,
so reviewers got a chance to reply.

On Tue Jul 2, 2024 at 3:02 PM CEST, Aleksandr Mishin wrote:
> In mscc_miim_clk_set() miim->bus_freq is taken from Device Tree and can
> contain any value in case of any error or broken DT. A value of 2147483648
> multiplied by 2 will result in an overflow and division by 0.
>
> Add bus frequency value check to avoid overflow.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: bb2a1934ca01 ("net: phy: mscc-miim: add support to set MDIO bus frequency")
> Suggested-by: Michael Walle <michael@...le.cc>
> Signed-off-by: Aleksandr Mishin <amishin@...rgos.ru>
> ---
> v1->v2: Detect overflow event instead of using magic numbers as suggested by Michael
>
>  drivers/net/mdio/mdio-mscc-miim.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/mdio/mdio-mscc-miim.c b/drivers/net/mdio/mdio-mscc-miim.c
> index c29377c85307..b344d0b03d8e 100644
> --- a/drivers/net/mdio/mdio-mscc-miim.c
> +++ b/drivers/net/mdio/mdio-mscc-miim.c
> @@ -254,6 +254,11 @@ static int mscc_miim_clk_set(struct mii_bus *bus)
>  	if (!miim->bus_freq)
>  		return 0;
>  
> +	if (2 * miim->bus_freq == 0) {
> +		dev_err(&bus->dev, "Incorrect bus frequency\n");
> +		return -EINVAL;
> +	}

DRY. Save it in a variable and use it in DIV_ROUND_UP(). Also you
just check for the div-by-zero, but what if the value will overflow
beyond zero? The calculation will be wrong, right?

There's also check_mul_overflow() but not sure that's encouraged in
netdev.

-michael

> +
>  	rate = clk_get_rate(miim->clk);
>  
>  	div = DIV_ROUND_UP(rate, 2 * miim->bus_freq) - 1;


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ