Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: typec: ucsi: Add bounds check for enum array index
@ 2026-06-30 11:31 DongliLiu
  2026-06-30 14:17 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: DongliLiu @ 2026-06-30 11:31 UTC (permalink / raw)
  To: linux-usb

From: DongliLiu <dongli.liu@outlook.com>
Date: Mon, 30 Jun 2026 19:30:00 +0800
Subject: [PATCH] usb: typec: ucsi: Add bounds check for enum array index

The 'sop' parameter is a C enum that can hold any integer value, not
just the defined enum constants. Using it directly as an array index
without bounds checking can lead to undefined behavior if an out-of-range
value is passed.

Add an explicit ARRAY_SIZE() check before accessing altmode->plug[sop]
to ensure the index is within bounds.

Signed-off-by: DongliLiu <dongli.liu@outlook.com>
---
  drivers/usb/typec/ucsi/ucsi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index xxxxxxx..yyyyyyy 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -xxx,yyy @@@ static void some_function(struct typec_altmode *altmode, 
enum typec_plug_role sop)
      ...

-    if (!altmode->plug[sop])
+    if (sop >= ARRAY_SIZE(altmode->plug) || !altmode->plug[sop])
          ...
-- 
2.40.0


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

* Re: [PATCH] usb: typec: ucsi: Add bounds check for enum array index
  2026-06-30 11:31 [PATCH] usb: typec: ucsi: Add bounds check for enum array index DongliLiu
@ 2026-06-30 14:17 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-06-30 14:17 UTC (permalink / raw)
  To: DongliLiu; +Cc: linux-usb

On Tue, Jun 30, 2026 at 07:31:29PM +0800, DongliLiu wrote:
> From: DongliLiu <dongli.liu@outlook.com>
> Date: Mon, 30 Jun 2026 19:30:00 +0800
> Subject: [PATCH] usb: typec: ucsi: Add bounds check for enum array index
> 
> The 'sop' parameter is a C enum that can hold any integer value, not
> just the defined enum constants. Using it directly as an array index
> without bounds checking can lead to undefined behavior if an out-of-range
> value is passed.
> 
> Add an explicit ARRAY_SIZE() check before accessing altmode->plug[sop]
> to ensure the index is within bounds.
> 
> Signed-off-by: DongliLiu <dongli.liu@outlook.com>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index xxxxxxx..yyyyyyy 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -xxx,yyy @@@ static void some_function(struct typec_altmode *altmode,
> enum typec_plug_role sop)
>      ...
> 
> -    if (!altmode->plug[sop])
> +    if (sop >= ARRAY_SIZE(altmode->plug) || !altmode->plug[sop])
>          ...
> -- 
> 2.40.0

Same here, stop making fake patches.

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

end of thread, other threads:[~2026-06-30 14:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30 11:31 [PATCH] usb: typec: ucsi: Add bounds check for enum array index DongliLiu
2026-06-30 14:17 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox