diff mbox

HID: roccat: prevent an out of bounds read in kovaplus_profile_activated()

Message ID 20180110093903.yyoknoi7oc2cd5iy@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter Jan. 10, 2018, 9:39 a.m. UTC
We get the "new_profile_index" value from the mouse device when we're
handling raw events.  Smatch taints it as untrusted data and complains
that we need a bounds check.  This seems like a reasonable warning
otherwise there is a small read beyond the end of the array.

Fixes: 0e70f97f257e ("HID: roccat: Add support for Kova[+] mouse")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Silvan Jegen Jan. 15, 2018, 8:21 p.m. UTC | #1
Hi

On Wed, Jan 10, 2018 at 12:39:03PM +0300, Dan Carpenter wrote:
> We get the "new_profile_index" value from the mouse device when we're
> handling raw events.  Smatch taints it as untrusted data and complains
> that we need a bounds check.  This seems like a reasonable warning
> otherwise there is a small read beyond the end of the array.
> 
> Fixes: 0e70f97f257e ("HID: roccat: Add support for Kova[+] mouse")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Looks good to me.

Acked-by: Silvan Jegen <s.jegen@gmail.com>


> diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c
> index 43617fb28b87..317c9c2c0a7c 100644
> --- a/drivers/hid/hid-roccat-kovaplus.c
> +++ b/drivers/hid/hid-roccat-kovaplus.c
> @@ -37,6 +37,8 @@ static uint kovaplus_convert_event_cpi(uint value)
>  static void kovaplus_profile_activated(struct kovaplus_device *kovaplus,
>  		uint new_profile_index)
>  {
> +	if (new_profile_index >= ARRAY_SIZE(kovaplus->profile_settings))
> +		return;
>  	kovaplus->actual_profile = new_profile_index;
>  	kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level;
>  	kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x;
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiri Kosina Jan. 23, 2018, 2:47 p.m. UTC | #2
On Wed, 10 Jan 2018, Dan Carpenter wrote:

> We get the "new_profile_index" value from the mouse device when we're
> handling raw events.  Smatch taints it as untrusted data and complains
> that we need a bounds check.  This seems like a reasonable warning
> otherwise there is a small read beyond the end of the array.
> 
> Fixes: 0e70f97f257e ("HID: roccat: Add support for Kova[+] mouse")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied, thanks.
diff mbox

Patch

diff --git a/drivers/hid/hid-roccat-kovaplus.c b/drivers/hid/hid-roccat-kovaplus.c
index 43617fb28b87..317c9c2c0a7c 100644
--- a/drivers/hid/hid-roccat-kovaplus.c
+++ b/drivers/hid/hid-roccat-kovaplus.c
@@ -37,6 +37,8 @@  static uint kovaplus_convert_event_cpi(uint value)
 static void kovaplus_profile_activated(struct kovaplus_device *kovaplus,
 		uint new_profile_index)
 {
+	if (new_profile_index >= ARRAY_SIZE(kovaplus->profile_settings))
+		return;
 	kovaplus->actual_profile = new_profile_index;
 	kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level;
 	kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x;