linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] HID: playstation: fix array size comparison (off-by-one)
@ 2021-02-15 16:39 Colin King
  2021-02-17 20:04 ` Benjamin Tissoires
  0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2021-02-15 16:39 UTC (permalink / raw)
  To: Roderick Colenbrander, Jiri Kosina, Benjamin Tissoires,
	Barnabás Pőcze, linux-input
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The comparison of value with the array size ps_gamepad_hat_mapping
appears to be off-by-one. Fix this by using >= rather than > for the
size comparison.

Addresses-Coverity: ("Out-of-bounds read")
Fixes: bc2e15a9a022 ("HID: playstation: initial DualSense USB support.")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/hid/hid-playstation.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 408b651174cf..568a3a067c88 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -1064,7 +1064,7 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
 	input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz);
 
 	value = ds_report->buttons[0] & DS_BUTTONS0_HAT_SWITCH;
-	if (value > ARRAY_SIZE(ps_gamepad_hat_mapping))
+	if (value >= ARRAY_SIZE(ps_gamepad_hat_mapping))
 		value = 8; /* center */
 	input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x);
 	input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y);
-- 
2.30.0


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

* Re: [PATCH][next] HID: playstation: fix array size comparison (off-by-one)
  2021-02-15 16:39 [PATCH][next] HID: playstation: fix array size comparison (off-by-one) Colin King
@ 2021-02-17 20:04 ` Benjamin Tissoires
  0 siblings, 0 replies; 2+ messages in thread
From: Benjamin Tissoires @ 2021-02-17 20:04 UTC (permalink / raw)
  To: Colin King
  Cc: Roderick Colenbrander, Jiri Kosina, Barnabás Pőcze,
	open list:HID CORE LAYER, kernel-janitors, lkml

On Mon, Feb 15, 2021 at 5:39 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> The comparison of value with the array size ps_gamepad_hat_mapping
> appears to be off-by-one. Fix this by using >= rather than > for the
> size comparison.
>
> Addresses-Coverity: ("Out-of-bounds read")
> Fixes: bc2e15a9a022 ("HID: playstation: initial DualSense USB support.")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---

Good catch.

Applied to for-5.12/playstation-v2

Cheers,
Benjamin

>  drivers/hid/hid-playstation.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index 408b651174cf..568a3a067c88 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -1064,7 +1064,7 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
>         input_report_abs(ds->gamepad, ABS_RZ, ds_report->rz);
>
>         value = ds_report->buttons[0] & DS_BUTTONS0_HAT_SWITCH;
> -       if (value > ARRAY_SIZE(ps_gamepad_hat_mapping))
> +       if (value >= ARRAY_SIZE(ps_gamepad_hat_mapping))
>                 value = 8; /* center */
>         input_report_abs(ds->gamepad, ABS_HAT0X, ps_gamepad_hat_mapping[value].x);
>         input_report_abs(ds->gamepad, ABS_HAT0Y, ps_gamepad_hat_mapping[value].y);
> --
> 2.30.0
>


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

end of thread, other threads:[~2021-02-17 20:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 16:39 [PATCH][next] HID: playstation: fix array size comparison (off-by-one) Colin King
2021-02-17 20:04 ` Benjamin Tissoires

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).