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>] [day] [month] [year] [list]
Message-ID: <Y4ETXbZn3wSnZbfh@lunn.ch>
Date:   Fri, 25 Nov 2022 20:11:25 +0100
From:   Andrew Lunn <andrew@...n.ch>
To:     Daniil Tatianin <d-tatianin@...dex-team.ru>
Cc:     netdev@...r.kernel.org, Michal Kubecek <mkubecek@...e.cz>,
        yc-core@...dex-team.ru, lvc-project@...uxtesting.org
Subject: Re: [PATCH v1 3/3] net/ethtool/ioctl: correct & simplify
 ethtool_get_phy_stats if checks

On Fri, Nov 25, 2022 at 07:49:13PM +0300, Daniil Tatianin wrote:
> ops->get_ethtool_phy_stats was getting called in an else branch
> of ethtool_get_phy_stats() unconditionally without making sure
> it was actually present.
> 
> Refactor the if checks so that it's more obvious what's going on and
> avoid accidental NULL derefs.
> 
> Found by Linux Verification Center (linuxtesting.org) with the SVACE
> static analysis tool.
> 
> Signed-off-by: Daniil Tatianin <d-tatianin@...dex-team.ru>
> ---
>  net/ethtool/ioctl.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
> index f83118c68e20..2b01e0042e6e 100644
> --- a/net/ethtool/ioctl.c
> +++ b/net/ethtool/ioctl.c
> @@ -2076,25 +2076,27 @@ static int ethtool_get_phy_stats(struct net_device *dev, void __user *useraddr)
>  {
>  	const struct ethtool_phy_ops *phy_ops = ethtool_phy_ops;
>  	const struct ethtool_ops *ops = dev->ethtool_ops;
> +	bool has_phy_stats_ops = ops->get_ethtool_phy_stats != NULL;
>  	struct phy_device *phydev = dev->phydev;
>  	struct ethtool_stats stats;
>  	u64 *data;
>  	int ret, n_stats;
>  
> -	if (!phydev && (!ops->get_ethtool_phy_stats || !ops->get_sset_count))
> -		return -EOPNOTSUPP;
> +	if (!phydev || !phy_ops) {
> +		if (!ops->get_sset_count)
> +			return -EOPNOTSUPP;
>  
> -	if (phydev && !ops->get_ethtool_phy_stats &&
> -	    phy_ops && phy_ops->get_sset_count)
> -		n_stats = phy_ops->get_sset_count(phydev);
> -	else
>  		n_stats = ops->get_sset_count(dev, ETH_SS_PHY_STATS);
> +	} else {
> +		n_stats = phy_ops->get_sset_count(phydev);
> +		has_phy_stats_ops |= phy_ops->get_stats != NULL;

I'm not sure this is actually any clearer. You are mixing together
ethtool ops and phy ops.

This is part of why i suggested splitting phydev and !phydev into
helpers. The tests become a lot simpler. Please try it and see what
the resulting code looks like.

    Andrew

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ