[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6307397bd43636fea2e7341d24417cbbc3aaf922.camel@perches.com>
Date: Sun, 11 Oct 2020 11:33:00 -0700
From: Joe Perches <joe@...ches.com>
To: Jakub Kicinski <kuba@...nel.org>,
Anant Thazhemadam <anant.thazhemadam@...il.com>
Cc: petkan@...leusys.com, davem@...emloft.net,
linux-usb@...r.kernel.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-kernel-mentees@...ts.linuxfoundation.org,
linux-next@...r.kernel.org, sfr@...b.auug.org.au
Subject: Re: [PATCH v2] net: usb: rtl8150: don't incorrectly assign random
MAC addresses
On Sun, 2020-10-11 at 10:59 -0700, Jakub Kicinski wrote:
> On Sun, 11 Oct 2020 23:00:30 +0530 Anant Thazhemadam wrote:
> > In set_ethernet_addr(), if get_registers() succeeds, the ethernet address
> > that was read must be copied over. Otherwise, a random ethernet address
> > must be assigned.
> >
> > get_registers() returns 0 if successful, and negative error number
> > otherwise. However, in set_ethernet_addr(), this return value is
> > incorrectly checked.
> >
> > Since this return value will never be equal to sizeof(node_id), a
> > random MAC address will always be generated and assigned to the
> > device; even in cases when get_registers() is successful.
> >
> > Correctly modifying the condition that checks if get_registers() was
> > successful or not fixes this problem, and copies the ethernet address
> > appropriately.
There are many unchecked uses of set_registers and get_registers
in this file.
If failures are really expected, then it might be better to fix
them up too.
$ git grep -w '[gs]et_registers' drivers/net/usb/rtl8150.c
drivers/net/usb/rtl8150.c:static int get_registers(rtl8150_t * dev, u16 indx, u16 size, void *data)
drivers/net/usb/rtl8150.c:static int set_registers(rtl8150_t * dev, u16 indx, u16 size, const void *data)
drivers/net/usb/rtl8150.c: set_registers(dev, PHYADD, sizeof(data), data);
drivers/net/usb/rtl8150.c: set_registers(dev, PHYCNT, 1, &tmp);
drivers/net/usb/rtl8150.c: get_registers(dev, PHYCNT, 1, data);
drivers/net/usb/rtl8150.c: get_registers(dev, PHYDAT, 2, data);
drivers/net/usb/rtl8150.c: set_registers(dev, PHYADD, sizeof(data), data);
drivers/net/usb/rtl8150.c: set_registers(dev, PHYCNT, 1, &tmp);
drivers/net/usb/rtl8150.c: get_registers(dev, PHYCNT, 1, data);
drivers/net/usb/rtl8150.c: ret = get_registers(dev, IDR, sizeof(node_id), node_id);
drivers/net/usb/rtl8150.c: set_registers(dev, IDR, netdev->addr_len, netdev->dev_addr);
drivers/net/usb/rtl8150.c: get_registers(dev, CR, 1, &cr);
drivers/net/usb/rtl8150.c: set_registers(dev, CR, 1, &cr);
drivers/net/usb/rtl8150.c: set_registers(dev, IDR_EEPROM + (i * 2), 2,
drivers/net/usb/rtl8150.c: set_registers(dev, CR, 1, &cr);
drivers/net/usb/rtl8150.c: set_registers(dev, CR, 1, &data);
drivers/net/usb/rtl8150.c: get_registers(dev, CR, 1, &data);
drivers/net/usb/rtl8150.c: set_registers(dev, RCR, 1, &rcr);
drivers/net/usb/rtl8150.c: set_registers(dev, TCR, 1, &tcr);
drivers/net/usb/rtl8150.c: set_registers(dev, CR, 1, &cr);
drivers/net/usb/rtl8150.c: get_registers(dev, MSR, 1, &msr);
drivers/net/usb/rtl8150.c: get_registers(dev, CR, 1, &cr);
drivers/net/usb/rtl8150.c: set_registers(dev, CR, 1, &cr);
drivers/net/usb/rtl8150.c: get_registers(dev, CSCR, 2, &tmp);
drivers/net/usb/rtl8150.c: set_registers(dev, IDR, 6, netdev->dev_addr);
drivers/net/usb/rtl8150.c: get_registers(dev, BMCR, 2, &bmcr);
drivers/net/usb/rtl8150.c: get_registers(dev, ANLP, 2, &lpa);
Powered by blists - more mailing lists