linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: max-3421: fix potential shift out-of-bounds in max3421_hub_control()
@ 2023-06-25 17:12 Zhang Shurong
  2023-06-26  6:16 ` Krzysztof Kozlowski
  0 siblings, 1 reply; 2+ messages in thread
From: Zhang Shurong @ 2023-06-25 17:12 UTC (permalink / raw)
  To: gregkh
  Cc: mark.tomlinson, krzysztof.kozlowski, linux-usb, linux-kernel,
	Zhang Shurong

Fix potential shift out-of-bounds in max3421_hub_control()
ClearPortFeature handling and SetPortFeature handling.

wValue may be greater than 32 which can not be used for shifting.

similar patch:
https://patchwork.kernel.org/patch/12162547

Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
---
 drivers/usb/host/max3421-hcd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
index d152d72de126..035cd6abc2f6 100644
--- a/drivers/usb/host/max3421-hcd.c
+++ b/drivers/usb/host/max3421-hcd.c
@@ -1688,6 +1688,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,
 						!pdata->vbus_active_level);
 			fallthrough;
 		default:
+			if (value >= 32)
+				goto error;
 			max3421_hcd->port_status &= ~(1 << value);
 		}
 		break;
@@ -1741,6 +1743,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,
 			max3421_reset_port(hcd);
 			fallthrough;
 		default:
+			if (value >= 32)
+				goto error;
 			if ((max3421_hcd->port_status & USB_PORT_STAT_POWER)
 			    != 0)
 				max3421_hcd->port_status |= (1 << value);
-- 
2.41.0


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

* Re: [PATCH] usb: max-3421: fix potential shift out-of-bounds in max3421_hub_control()
  2023-06-25 17:12 [PATCH] usb: max-3421: fix potential shift out-of-bounds in max3421_hub_control() Zhang Shurong
@ 2023-06-26  6:16 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 2+ messages in thread
From: Krzysztof Kozlowski @ 2023-06-26  6:16 UTC (permalink / raw)
  To: Zhang Shurong, gregkh; +Cc: mark.tomlinson, linux-usb, linux-kernel

On 25/06/2023 19:12, Zhang Shurong wrote:
> Fix potential shift out-of-bounds in max3421_hub_control()
> ClearPortFeature handling and SetPortFeature handling.
> 
> wValue may be greater than 32 which can not be used for shifting.

You need to use proper name after copying the commit msg...

> 
> similar patch:
> https://patchwork.kernel.org/patch/12162547

This does not belong to commit msg, but rather --- .

> 
> Signed-off-by: Zhang Shurong <zhang_shurong@foxmail.com>
> ---
>  drivers/usb/host/max3421-hcd.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/host/max3421-hcd.c b/drivers/usb/host/max3421-hcd.c
> index d152d72de126..035cd6abc2f6 100644
> --- a/drivers/usb/host/max3421-hcd.c
> +++ b/drivers/usb/host/max3421-hcd.c
> @@ -1688,6 +1688,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,
>  						!pdata->vbus_active_level);
>  			fallthrough;
>  		default:
> +			if (value >= 32)
> +				goto error;
>  			max3421_hcd->port_status &= ~(1 << value);
>  		}
>  		break;
> @@ -1741,6 +1743,8 @@ max3421_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index,
>  			max3421_reset_port(hcd);
>  			fallthrough;
>  		default:
> +			if (value >= 32)
> +				goto error;

I am not sure if performing first port reset and then validating the
arguments is the correct way.

>  			if ((max3421_hcd->port_status & USB_PORT_STAT_POWER)
>  			    != 0)
>  				max3421_hcd->port_status |= (1 << value);

Best regards,
Krzysztof


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

end of thread, other threads:[~2023-06-26  6:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-25 17:12 [PATCH] usb: max-3421: fix potential shift out-of-bounds in max3421_hub_control() Zhang Shurong
2023-06-26  6:16 ` Krzysztof Kozlowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).