Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
From: Petko Manolov <petkan@nucleusys.com>
To: Joe Perches <joe@perches.com>
Cc: Jakub Kicinski <kuba@kernel.org>,
	Anant Thazhemadam <anant.thazhemadam@gmail.com>,
	davem@davemloft.net, linux-usb@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-next@vger.kernel.org, sfr@canb.auug.org.au
Subject: Re: [PATCH v2] net: usb: rtl8150: don't incorrectly assign random MAC addresses
Date: Sun, 11 Oct 2020 22:31:19 +0300
Message-ID: <20201011193119.GA4061@p310> (raw)
In-Reply-To: <6307397bd43636fea2e7341d24417cbbc3aaf922.camel@perches.com>

On 20-10-11 11:33:00, Joe Perches wrote:
> 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.

Checking the return value of each get/set_registers() is going to be a PITA and
not very helpful.  Doing so when setting the MAC address _does_ make sense as in
that case it is not a hard error.

In almost all other occasions if usb_control_msg_send/recv() return an error i'd
rather dump an error message (from within get/set_registers()) and let the user
decide whether to get rid of this adapter or start debugging it.


cheers,
Petko


> $ 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);
> 
> 
> 

  reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-10  6:44 [PATCH] " Anant Thazhemadam
2020-10-10 16:59 ` Jakub Kicinski
2020-10-10 18:04   ` Anant Thazhemadam
2020-10-10 18:16     ` Jakub Kicinski
2020-10-10 18:44       ` Anant Thazhemadam
2020-10-10 19:20         ` Jakub Kicinski
2020-10-11 17:30 ` [PATCH v2] " Anant Thazhemadam
2020-10-11 17:59   ` Jakub Kicinski
2020-10-11 18:33     ` Joe Perches
2020-10-11 19:31       ` Petko Manolov [this message]
2020-10-11 20:14         ` Joe Perches
2020-10-11 22:14   ` Stephen Rothwell
2020-10-15 21:59     ` Stephen Rothwell
2020-10-15 22:24       ` Jakub Kicinski
2020-10-15 22:37         ` Jakub Kicinski
2020-10-18 19:54           ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201011193119.GA4061@p310 \
    --to=petkan@nucleusys.com \
    --cc=anant.thazhemadam@gmail.com \
    --cc=davem@davemloft.net \
    --cc=joe@perches.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git