From: Hayes Wang <hidden> Date: 2021-05-21 09:08:33
PLA MCU clock speed down could only be enabled when tx/rx are disabled.
Otherwise, the packet loss may occur.
Signed-off-by: Hayes Wang <redacted>
---
drivers/net/usb/r8152.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
On Fri, May 21, 2021 at 05:07:34PM +0800, Hayes Wang wrote:
quoted hunk
Verify some fields of the USB descriptor to make sure the driver
could be used by the device.
BugLink: https://syzkaller.appspot.com/bug?id=912c9c373656996801b4de61f1e3cb326fe940aa
Reported-by: syzbot+95afd23673f5dd295c57@syzkaller.appspotmail.com
Fixes: c2198943e33b ("r8152: search the configuration of vendor mode")
Signed-off-by: Hayes Wang <redacted>
---
drivers/net/usb/r8152.c | 71 +++++++++++++++++++++++++++++++++++++++--
1 file changed, 69 insertions(+), 2 deletions(-)
@@ -8107,6 +8107,69 @@ static void r8156b_init(struct r8152 *tp)tp->coalesce=15000;/* 15 us */}+staticboolrtl_check_vendor_ok(structusb_interface*intf)+{+structusb_host_interface*alt=intf->cur_altsetting;+structusb_host_endpoint*in=NULL,*out=NULL,*intr=NULL;+unsignedintep;++if(alt->desc.bNumEndpoints<3){+dev_err(&intf->dev,"Unexpected bNumEndpoints %d\n",alt->desc.bNumEndpoints);+returnfalse;+}++for(ep=0;ep<alt->desc.bNumEndpoints;ep++){+structusb_host_endpoint*e;++e=alt->endpoint+ep;++/* ignore endpoints which cannot transfer data */+if(!usb_endpoint_maxp(&e->desc))+continue;++switch(e->desc.bmAttributes){+caseUSB_ENDPOINT_XFER_INT:+if(!usb_endpoint_dir_in(&e->desc))+continue;+if(!intr)+intr=e;+break;+caseUSB_ENDPOINT_XFER_BULK:+if(usb_endpoint_dir_in(&e->desc)){+if(!in)+in=e;+}elseif(!out){+out=e;+}+break;+default:+continue;+}+}++if(!in||!out||!intr){+dev_err(&intf->dev,"Miss Endpoints\n");+returnfalse;+}++if((in->desc.bEndpointAddress&USB_ENDPOINT_NUMBER_MASK)!=1){+dev_err(&intf->dev,"Invalid Rx Endpoints\n");+returnfalse;+}++if((out->desc.bEndpointAddress&USB_ENDPOINT_NUMBER_MASK)!=2){+dev_err(&intf->dev,"Invalid Tx Endpoints\n");+returnfalse;+}++if((intr->desc.bEndpointAddress&USB_ENDPOINT_NUMBER_MASK)!=3){+dev_err(&intf->dev,"Invalid interrupt Endpoints\n");+returnfalse;+}++returntrue;+}
We have a USB core function that does all of the above for you, why not
use that instead?
Look at usb_find_common_endpoints() and
usb_find_common_endpoints_reverse() and at the very least
usb_find_bulk_in_endpoint() and related functions. Please don't
open-code this type of logic, it's easy to get things wrong.
thanks,
greg k-h
From: Hayes Wang <hidden> Date: 2021-05-22 03:13:58
Greg KH [off-list ref]
Sent: Friday, May 21, 2021 5:43 PM
[...]
We have a USB core function that does all of the above for you, why not
use that instead?
Look at usb_find_common_endpoints() and
usb_find_common_endpoints_reverse() and at the very least
usb_find_bulk_in_endpoint() and related functions. Please don't
open-code this type of logic, it's easy to get things wrong.
From: Hayes Wang <hidden> Date: 2021-05-22 05:25:30
For RTL8153B with QFN32, disable test IO. Otherwise, it may cause
abnormal behavior for the device randomly.
Signed-off-by: Hayes Wang <redacted>
---
drivers/net/usb/r8152.c | 10 ++++++++++
1 file changed, 10 insertions(+)
On Sat, May 22, 2021 at 01:24:54PM +0800, Hayes Wang wrote:
Verify some fields of the USB descriptor to make sure the driver
could be used by the device.
Besides, remove the check of endpoint number in rtl8152_probe().
It has been done in rtl_check_vendor_ok().
BugLink: https://syzkaller.appspot.com/bug?id=912c9c373656996801b4de61f1e3cb326fe940aa
Reported-by: syzbot+95afd23673f5dd295c57@syzkaller.appspotmail.com
Fixes: c2198943e33b ("r8152: search the configuration of vendor mode")
Signed-off-by: Hayes Wang <redacted>
---
v2:
Use usb_find_common_endpoints() and usb_endpoint_num() to replace original
code.
Much better, just some tiny grammer changes below:
quoted hunk
remove the check of endpoint number in rtl8152_probe(). It has been done
in rtl_check_vendor_ok().
drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
"Invalid number of interrupt endpoints"
But really, this doesn't matter, all is good if you don't want to change
this :)
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
From: Johan Hovold <johan@kernel.org> Date: 2021-05-22 08:07:09
On Sat, May 22, 2021 at 09:32:58AM +0200, Greg Kroah-Hartman wrote:
On Sat, May 22, 2021 at 01:24:54PM +0800, Hayes Wang wrote:
quoted
Verify some fields of the USB descriptor to make sure the driver
could be used by the device.
Besides, remove the check of endpoint number in rtl8152_probe().
It has been done in rtl_check_vendor_ok().
BugLink: https://syzkaller.appspot.com/bug?id=912c9c373656996801b4de61f1e3cb326fe940aa
Reported-by: syzbot+95afd23673f5dd295c57@syzkaller.appspotmail.com
Fixes: c2198943e33b ("r8152: search the configuration of vendor mode")
Signed-off-by: Hayes Wang <redacted>
---
v2:
Use usb_find_common_endpoints() and usb_endpoint_num() to replace original
code.
Much better, just some tiny grammer changes below:
quoted
remove the check of endpoint number in rtl8152_probe(). It has been done
in rtl_check_vendor_ok().
drivers/net/usb/r8152.c | 44 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
"Miss" feels ackward, how about "Invalid number of endpoints"?
The helper also checks the type and direction so perhaps something like
"expected endpoints not found" (or just "missing endpoints") which is
more precise.
Here it is the endpoint number (address) that is being checked so
"number of" would be wrong.
That said, perhaps none of these checks are even needed a bit depending
on how the driver is implemented. That is, if it hardcodes the endpoint
addresses or uses the result from usb_find_common_endpoints() above
(which I realise now that it does not so these checks are probably still
needed).
Here it is the endpoint number (address) that is being checked so
"number of" would be wrong.
That said, perhaps none of these checks are even needed a bit depending
on how the driver is implemented. That is, if it hardcodes the endpoint
addresses or uses the result from usb_find_common_endpoints() above
(which I realise now that it does not so these checks are probably still
needed).
The purpose of the checks is to find out the fake devices. That is, even
the device supports in, out, and interrupt endpoints, it is treated as
fake or malicious device, if the addresses of these endpoints are wrong.
Therefore, I would keep the checks.
Best Regards,
Hayes
From: Hayes Wang <hidden> Date: 2021-05-24 06:50:46
For certain platforms, it causes USB reset periodically.
Signed-off-by: Hayes Wang <redacted>
---
drivers/net/usb/r8152.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
Here it is the endpoint number (address) that is being checked so
"number of" would be wrong.
That said, perhaps none of these checks are even needed a bit depending
on how the driver is implemented. That is, if it hardcodes the endpoint
addresses or uses the result from usb_find_common_endpoints() above
(which I realise now that it does not so these checks are probably still
needed).
The purpose of the checks is to find out the fake devices. That is, even
the device supports in, out, and interrupt endpoints, it is treated as
fake or malicious device, if the addresses of these endpoints are wrong.
Therefore, I would keep the checks.
Strictly, you need to check for bad input which could cause your driver
to crash or malfunction. Generally you don't need to verify endpoint
addresses unless the driver is hardcoding those. But since that is
precisely what this particular driver is doing, these checks indeed need
to stay.
Johan
From: Johan Hovold <johan@kernel.org> Date: 2021-05-24 08:00:45
On Mon, May 24, 2021 at 02:49:42PM +0800, Hayes Wang wrote:
quoted hunk
Verify some fields of the USB descriptor to make sure the driver
could be used by the device.
Besides, remove the check of endpoint number in rtl8152_probe().
usb_find_common_endpoints() includes it.
BugLink: https://syzkaller.appspot.com/bug?id=912c9c373656996801b4de61f1e3cb326fe940aa
Reported-by: syzbot+95afd23673f5dd295c57@syzkaller.appspotmail.com
Fixes: c2198943e33b ("r8152: search the configuration of vendor mode")
Signed-off-by: Hayes Wang <redacted>
---
v3:
Remove the check of endpoint number in rtl_check_vendor_ok().
Adjust the error message and ccommit message.
v2:
Use usb_find_common_endpoints() and usb_endpoint_num() to replace original
code.
remove the check of endpoint number in rtl8152_probe(). It has been done
in rtl_check_vendor_ok().
drivers/net/usb/r8152.c | 42 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 5 deletions(-)
@@ -8115,12 +8146,15 @@ static bool rtl_vendor_mode(struct usb_interface *intf)inti,num_configs;if(alt->desc.bInterfaceClass==USB_CLASS_VENDOR_SPEC)-returntrue;+returnrtl_check_vendor_ok(intf);/* The vendor mode is not always config #1, so to find it out. */udev=interface_to_usbdev(intf);c=udev->config;num_configs=udev->descriptor.bNumConfigurations;+if(num_configs<2)+returnfalse;+
Nit: This check looks unnecessary also as the driver can handle a single
configuration just fine, and by removing it you'd be logging "Unexpected
Device\n" below also in the single config case.
quoted hunk
for (i = 0; i < num_configs; (i++, c++)) {
struct usb_interface_descriptor *desc = NULL;
From: Hayes Wang <hidden> Date: 2021-05-24 08:55:09
Johan Hovold [off-list ref]
Sent: Monday, May 24, 2021 4:01 PM
[...]
quoted
/* The vendor mode is not always config #1, so to find it out. */
udev = interface_to_usbdev(intf);
c = udev->config;
num_configs = udev->descriptor.bNumConfigurations;
+ if (num_configs < 2)
+ return false;
+
Nit: This check looks unnecessary also as the driver can handle a single
configuration just fine, and by removing it you'd be logging "Unexpected
Device\n" below also in the single config case.
I just want to distinguish the devices.
It is acceptable if the device contains only one configuration.
A mistake occurs if the device has more configurations and
there is no expected one.
I would remove it if you think it is better.
Best Regards,
Hayes
From: Johan Hovold <johan@kernel.org> Date: 2021-05-24 09:13:48
On Mon, May 24, 2021 at 08:54:50AM +0000, Hayes Wang wrote:
Johan Hovold [off-list ref]
quoted
Sent: Monday, May 24, 2021 4:01 PM
[...]
quoted
quoted
/* The vendor mode is not always config #1, so to find it out. */
udev = interface_to_usbdev(intf);
c = udev->config;
num_configs = udev->descriptor.bNumConfigurations;
+ if (num_configs < 2)
+ return false;
+
Nit: This check looks unnecessary also as the driver can handle a single
configuration just fine, and by removing it you'd be logging "Unexpected
Device\n" below also in the single config case.
I just want to distinguish the devices.
It is acceptable if the device contains only one configuration.
A mistake occurs if the device has more configurations and
there is no expected one.
I would remove it if you think it is better.
I'm fine with keeping the check too (e.g. as an optimisation of sort),
it's just a bit inconsistent to not log an error in that one error path.
Johan
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
On Mon, 24 May 2021 14:49:42 +0800 you wrote:
Verify some fields of the USB descriptor to make sure the driver
could be used by the device.
Besides, remove the check of endpoint number in rtl8152_probe().
usb_find_common_endpoints() includes it.
BugLink: https://syzkaller.appspot.com/bug?id=912c9c373656996801b4de61f1e3cb326fe940aa
Reported-by: syzbot+95afd23673f5dd295c57@syzkaller.appspotmail.com
Fixes: c2198943e33b ("r8152: search the configuration of vendor mode")
Signed-off-by: Hayes Wang <redacted>
[...]