All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
@ 2020-10-03 21:19 ` Anant Thazhemadam
  0 siblings, 0 replies; 6+ messages in thread
From: Anant Thazhemadam @ 2020-10-03 21:19 UTC (permalink / raw)
  Cc: linux-kernel-mentees, joe, Anant Thazhemadam,
	syzbot+abbc768b560c84d92fd3, Petko Manolov, David S. Miller,
	Jakub Kicinski, linux-usb, netdev, linux-kernel

When get_registers() fails, in set_ethernet_addr(),the uninitialized
value of node_id gets copied as the address. This can be considered as
set_ethernet_addr() itself failing.

The return type of set_ethernet_addr() is modified to indicate if it
failed or not, and return values are appropriately checked by caller.

When set_ethernet_addr() fails, a randomly generated MAC address is set
as the MAC address instead.

On the other hand, for the case when get_registers() does succeed,
set_ethernet_addr() has been updated to use ether_addr_copy() to copy
the address, instead of memcpy().

Reported-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com
Tested-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com
Acked-by: Petko Manolov <petkan@nucleusys.com>
Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
---
Changes in v3:

	* Set a random MAC address to the device rather than making
	  the device not work at all in the even set_ethernet_addr()
	  fails. (Suggested by David Miller <davem@davemloft.net>)

	* Update set_ethernet_addr() to use ether_addr_copy() to copy 
	  the MAC Address (instead of using memcpy() for that same).
	  (Suggested by Joe Perches <joe@perches.com>)


Changes in v2:

	* Modified condition checking get_registers()'s return value to 
		ret == sizeof(node_id)
	  for stricter checking in compliance with the new usb_control_msg_recv()
	  API

	* Added Acked-by: Petko Manolov

 drivers/net/usb/rtl8150.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 733f120c852b..bbd49ebdf095 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -274,12 +274,17 @@ 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 bool set_ethernet_addr(rtl8150_t *dev)
 {
-	u8 node_id[6];
+	u8 node_id[ETH_ALEN];
+	int ret;
 
-	get_registers(dev, IDR, sizeof(node_id), node_id);
-	memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
+	ret = get_registers(dev, IDR, sizeof(node_id), node_id);
+	if (ret == sizeof(node_id)) {
+		ether_addr_copy(dev->netdev->dev_addr, node_id);
+		return true;
+	}
+	return false;
 }
 
 static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
@@ -909,7 +914,10 @@ static int rtl8150_probe(struct usb_interface *intf,
 		goto out1;
 	}
 	fill_skb_pool(dev);
-	set_ethernet_addr(dev);
+	if (!set_ethernet_addr(dev)) {
+		dev_err(&intf->dev, "assigining a random MAC address\n");
+		eth_hw_addr_random(dev->netdev);
+	}
 
 	usb_set_intfdata(intf, dev);
 	SET_NETDEV_DEV(netdev, &intf->dev);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Linux-kernel-mentees] [PATCH v3] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
@ 2020-10-03 21:19 ` Anant Thazhemadam
  0 siblings, 0 replies; 6+ messages in thread
From: Anant Thazhemadam @ 2020-10-03 21:19 UTC (permalink / raw)
  Cc: Anant Thazhemadam, Petko Manolov, syzbot+abbc768b560c84d92fd3,
	netdev, linux-usb, linux-kernel, joe, Jakub Kicinski,
	linux-kernel-mentees, David S. Miller

When get_registers() fails, in set_ethernet_addr(),the uninitialized
value of node_id gets copied as the address. This can be considered as
set_ethernet_addr() itself failing.

The return type of set_ethernet_addr() is modified to indicate if it
failed or not, and return values are appropriately checked by caller.

When set_ethernet_addr() fails, a randomly generated MAC address is set
as the MAC address instead.

On the other hand, for the case when get_registers() does succeed,
set_ethernet_addr() has been updated to use ether_addr_copy() to copy
the address, instead of memcpy().

Reported-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com
Tested-by: syzbot+abbc768b560c84d92fd3@syzkaller.appspotmail.com
Acked-by: Petko Manolov <petkan@nucleusys.com>
Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
---
Changes in v3:

	* Set a random MAC address to the device rather than making
	  the device not work at all in the even set_ethernet_addr()
	  fails. (Suggested by David Miller <davem@davemloft.net>)

	* Update set_ethernet_addr() to use ether_addr_copy() to copy 
	  the MAC Address (instead of using memcpy() for that same).
	  (Suggested by Joe Perches <joe@perches.com>)


Changes in v2:

	* Modified condition checking get_registers()'s return value to 
		ret == sizeof(node_id)
	  for stricter checking in compliance with the new usb_control_msg_recv()
	  API

	* Added Acked-by: Petko Manolov

 drivers/net/usb/rtl8150.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 733f120c852b..bbd49ebdf095 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -274,12 +274,17 @@ 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 bool set_ethernet_addr(rtl8150_t *dev)
 {
-	u8 node_id[6];
+	u8 node_id[ETH_ALEN];
+	int ret;
 
-	get_registers(dev, IDR, sizeof(node_id), node_id);
-	memcpy(dev->netdev->dev_addr, node_id, sizeof(node_id));
+	ret = get_registers(dev, IDR, sizeof(node_id), node_id);
+	if (ret == sizeof(node_id)) {
+		ether_addr_copy(dev->netdev->dev_addr, node_id);
+		return true;
+	}
+	return false;
 }
 
 static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
@@ -909,7 +914,10 @@ static int rtl8150_probe(struct usb_interface *intf,
 		goto out1;
 	}
 	fill_skb_pool(dev);
-	set_ethernet_addr(dev);
+	if (!set_ethernet_addr(dev)) {
+		dev_err(&intf->dev, "assigining a random MAC address\n");
+		eth_hw_addr_random(dev->netdev);
+	}
 
 	usb_set_intfdata(intf, dev);
 	SET_NETDEV_DEV(netdev, &intf->dev);
-- 
2.25.1

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
  2020-10-03 21:19 ` [Linux-kernel-mentees] " Anant Thazhemadam
@ 2020-10-03 21:35   ` Joe Perches
  -1 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2020-10-03 21:35 UTC (permalink / raw)
  To: Anant Thazhemadam
  Cc: linux-kernel-mentees, syzbot+abbc768b560c84d92fd3, Petko Manolov,
	David S. Miller, Jakub Kicinski, linux-usb, netdev, linux-kernel

On Sun, 2020-10-04 at 02:49 +0530, Anant Thazhemadam wrote:
> When get_registers() fails, in set_ethernet_addr(),the uninitialized
> value of node_id gets copied as the address. This can be considered as
> set_ethernet_addr() itself failing.
[]
> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
[]
> @@ -909,7 +914,10 @@ static int rtl8150_probe(struct usb_interface *intf,
>  		goto out1;
>  	}
>  	fill_skb_pool(dev);
> -	set_ethernet_addr(dev);
> +	if (!set_ethernet_addr(dev)) {
> +		dev_err(&intf->dev, "assigining a random MAC address\n");
> +		eth_hw_addr_random(dev->netdev);

4 things:

o Typo for assigning
o Reverse the assignment and message to show the new random MAC
o This should use netdev_<level>
o Is this better as error or notification?

	if (!set_ethernet_addr(dev)) {
		eth_hw_addr_random(dev->netdev);
		netdev_notice(dev->netdev, "Assigned a random MAC: %pM\n",
			      dev->netdev->dev_addr);
	}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v3] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
@ 2020-10-03 21:35   ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2020-10-03 21:35 UTC (permalink / raw)
  To: Anant Thazhemadam
  Cc: Petko Manolov, syzbot+abbc768b560c84d92fd3, netdev, linux-usb,
	linux-kernel, Jakub Kicinski, linux-kernel-mentees,
	David S. Miller

On Sun, 2020-10-04 at 02:49 +0530, Anant Thazhemadam wrote:
> When get_registers() fails, in set_ethernet_addr(),the uninitialized
> value of node_id gets copied as the address. This can be considered as
> set_ethernet_addr() itself failing.
[]
> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
[]
> @@ -909,7 +914,10 @@ static int rtl8150_probe(struct usb_interface *intf,
>  		goto out1;
>  	}
>  	fill_skb_pool(dev);
> -	set_ethernet_addr(dev);
> +	if (!set_ethernet_addr(dev)) {
> +		dev_err(&intf->dev, "assigining a random MAC address\n");
> +		eth_hw_addr_random(dev->netdev);

4 things:

o Typo for assigning
o Reverse the assignment and message to show the new random MAC
o This should use netdev_<level>
o Is this better as error or notification?

	if (!set_ethernet_addr(dev)) {
		eth_hw_addr_random(dev->netdev);
		netdev_notice(dev->netdev, "Assigned a random MAC: %pM\n",
			      dev->netdev->dev_addr);
	}

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
  2020-10-03 21:35   ` [Linux-kernel-mentees] " Joe Perches
@ 2020-10-03 21:45     ` Anant Thazhemadam
  -1 siblings, 0 replies; 6+ messages in thread
From: Anant Thazhemadam @ 2020-10-03 21:45 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-kernel-mentees, syzbot+abbc768b560c84d92fd3, Petko Manolov,
	David S. Miller, Jakub Kicinski, linux-usb, netdev, linux-kernel


On 04/10/20 3:05 am, Joe Perches wrote:
> On Sun, 2020-10-04 at 02:49 +0530, Anant Thazhemadam wrote:
>> When get_registers() fails, in set_ethernet_addr(),the uninitialized
>> value of node_id gets copied as the address. This can be considered as
>> set_ethernet_addr() itself failing.
> []
>> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
> []
>> @@ -909,7 +914,10 @@ static int rtl8150_probe(struct usb_interface *intf,
>>  		goto out1;
>>  	}
>>  	fill_skb_pool(dev);
>> -	set_ethernet_addr(dev);
>> +	if (!set_ethernet_addr(dev)) {
>> +		dev_err(&intf->dev, "assigining a random MAC address\n");
>> +		eth_hw_addr_random(dev->netdev);
> 4 things:
> .
> o Typo for assigning
Oh no. I'm sorry about that.
> o Reverse the assignment and message to show the new random MAC
Ah, okay. That would be more informative.
> o This should use netdev_<level>
Understood.
> o Is this better as error or notification?
>
> 	if (!set_ethernet_addr(dev)) {
> 		eth_hw_addr_random(dev->netdev);
> 		netdev_notice(dev->netdev, "Assigned a random MAC: %pM\n",
> 			      dev->netdev->dev_addr);
> 	}
I thought it might be an error since set_ethernet_addr() did fail after
all.  But making it info seems like a better idea, since technically speaking,
the device is still made accessible.

I'll wait for a day or two, to see if anybody else has any other comments,
and send in a v4 incorporating these changes.

Thanks,
Anant

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v3] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails
@ 2020-10-03 21:45     ` Anant Thazhemadam
  0 siblings, 0 replies; 6+ messages in thread
From: Anant Thazhemadam @ 2020-10-03 21:45 UTC (permalink / raw)
  To: Joe Perches
  Cc: Petko Manolov, syzbot+abbc768b560c84d92fd3, netdev, linux-usb,
	linux-kernel, Jakub Kicinski, linux-kernel-mentees,
	David S. Miller


On 04/10/20 3:05 am, Joe Perches wrote:
> On Sun, 2020-10-04 at 02:49 +0530, Anant Thazhemadam wrote:
>> When get_registers() fails, in set_ethernet_addr(),the uninitialized
>> value of node_id gets copied as the address. This can be considered as
>> set_ethernet_addr() itself failing.
> []
>> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
> []
>> @@ -909,7 +914,10 @@ static int rtl8150_probe(struct usb_interface *intf,
>>  		goto out1;
>>  	}
>>  	fill_skb_pool(dev);
>> -	set_ethernet_addr(dev);
>> +	if (!set_ethernet_addr(dev)) {
>> +		dev_err(&intf->dev, "assigining a random MAC address\n");
>> +		eth_hw_addr_random(dev->netdev);
> 4 things:
> .
> o Typo for assigning
Oh no. I'm sorry about that.
> o Reverse the assignment and message to show the new random MAC
Ah, okay. That would be more informative.
> o This should use netdev_<level>
Understood.
> o Is this better as error or notification?
>
> 	if (!set_ethernet_addr(dev)) {
> 		eth_hw_addr_random(dev->netdev);
> 		netdev_notice(dev->netdev, "Assigned a random MAC: %pM\n",
> 			      dev->netdev->dev_addr);
> 	}
I thought it might be an error since set_ethernet_addr() did fail after
all.  But making it info seems like a better idea, since technically speaking,
the device is still made accessible.

I'll wait for a day or two, to see if anybody else has any other comments,
and send in a v4 incorporating these changes.

Thanks,
Anant
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-10-04  0:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-03 21:19 [PATCH v3] net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails Anant Thazhemadam
2020-10-03 21:19 ` [Linux-kernel-mentees] " Anant Thazhemadam
2020-10-03 21:35 ` Joe Perches
2020-10-03 21:35   ` [Linux-kernel-mentees] " Joe Perches
2020-10-03 21:45   ` Anant Thazhemadam
2020-10-03 21:45     ` [Linux-kernel-mentees] " Anant Thazhemadam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.