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]
Date: Wed, 13 Dec 2023 16:12:24 +0000
From: "Russell King (Oracle)" <linux@...linux.org.uk>
To: Christian Marangi <ansuelsmth@...il.com>
Cc: Florian Fainelli <florian.fainelli@...adcom.com>,
	Broadcom internal kernel review list <bcm-kernel-feedback-list@...adcom.com>,
	Andrew Lunn <andrew@...n.ch>,
	Heiner Kallweit <hkallweit1@...il.com>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
	Vladimir Oltean <olteanv@...il.com>,
	David Epping <david.epping@...singlinkelectronics.com>,
	Harini Katakam <harini.katakam@....com>,
	Simon Horman <horms@...nel.org>, netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [net-next PATCH v6 1/3] net: phy: extend PHY package API to
 support multiple global address

On Wed, Dec 13, 2023 at 04:50:33PM +0100, Christian Marangi wrote:
> On Wed, Dec 13, 2023 at 03:45:24PM +0000, Russell King (Oracle) wrote:
> > On Wed, Dec 13, 2023 at 11:57:28AM +0100, Christian Marangi wrote:
> > > -static inline int phy_package_read(struct phy_device *phydev, u32 regnum)
> > > +static inline int phy_package_read(struct phy_device *phydev,
> > > +				   unsigned int addr_offset, u32 regnum)
> > >  {
> > >  	struct phy_package_shared *shared = phydev->shared;
> > > +	int addr = shared->base_addr + addr_offset;
> > >  
> > > -	if (!shared)
> > > +	if (addr >= PHY_MAX_ADDR)
> > >  		return -EIO;
> > 
> > If we're going to check the address, I think we should check it
> > properly, which means also checking whether it's become negative.
> > 
> > Alternatively, we could consider making "addr" and "base_addr"
> > unsigned types, since they should never be negative. However,
> > that probably should be done as a separate patch before this one.
> >
> 
> Maybe I'm confused but isn't already like that?
> On phy_package_join base_addr is already checked if it's negative (and
> rejected)
> 
> addr_offset is unsigned so it can't be negative.

True, but with base_addr being an int, addr_offset being unsigned int,
and addr being an int, if addr_offset is a very large number,
2-complement arithmetic will have the effect of treating it as a
negative number.

So, base_addr=0, addr_offset=~0 results in addr being -1.

If "addr" were unsigned int, and as we've already established,
"base_addr" can't be less than zero because of the checks already done
(thus it can also be unsigned int) then we'll end up with the checks
you're adding automatically doing the right thing, because...

base_addr=0, addr_offset=~0 results in addr being ~0 (a large
positive unsigned number).

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ