[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c93d120c850c5fecadaea845517f0fdbfd9a61c7.camel@perches.com>
Date: Mon, 12 Oct 2020 12:11:18 -0700
From: Joe Perches <joe@...ches.com>
To: Sasha Levin <sashal@...nel.org>, linux-kernel@...r.kernel.org,
stable@...r.kernel.org
Cc: Anant Thazhemadam <anant.thazhemadam@...il.com>,
syzbot+abbc768b560c84d92fd3@...kaller.appspotmail.com,
Petko Manolov <petkan@...leusys.com>,
"David S . Miller" <davem@...emloft.net>,
linux-usb@...r.kernel.org, netdev@...r.kernel.org
Subject: Re: [PATCH AUTOSEL 5.8 18/24] net: usb: rtl8150: set random MAC
address when set_ethernet_addr() fails
On Mon, 2020-10-12 at 15:02 -0400, Sasha Levin wrote:
> From: Anant Thazhemadam <anant.thazhemadam@...il.com>
>
> [ Upstream commit f45a4248ea4cc13ed50618ff066849f9587226b2 ]
>
> When get_registers() fails in set_ethernet_addr(),the uninitialized
> value of node_id gets copied over as the address.
> So, check the return value of get_registers().
>
> If get_registers() executed successfully (i.e., it returns
> sizeof(node_id)), copy over the MAC address using ether_addr_copy()
> (instead of using memcpy()).
>
> Else, if get_registers() failed instead, a randomly generated MAC
> address is set as the MAC address instead.
This autosel is premature.
This patch always sets a random MAC.
See the follow on patch: https://lkml.org/lkml/2020/10/11/131
To my knowledge, this follow-ob has yet to be applied:
> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
[]
> @@ -274,12 +274,20 @@ static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)
> return 1;
> }
>
> -static inline void set_ethernet_addr(rtl8150_t * dev)
> +static void set_ethernet_addr(rtl8150_t *dev)
> {
> - u8 node_id[6];
> + u8 node_id[ETH_ALEN];
> + int ret;
> +
> + ret = get_registers(dev, IDR, sizeof(node_id), node_id);
>
> - get_registers(dev, IDR, sizeof(node_id), node_id);
> - memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
> + if (ret == sizeof(node_id)) {
So this needs to use
if (!ret) {
or
if (ret < 0)
and reversed code blocks
> + ether_addr_copy(dev->netdev->dev_addr, node_id);
> + } else {
> + eth_hw_addr_random(dev->netdev);
> + netdev_notice(dev->netdev, "Assigned a random MAC address: %pM\n",
> + dev->netdev->dev_addr);
> + }
> }
>
> static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
Powered by blists - more mailing lists