linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] HID: roccat: potential out of bounds in pyra_sysfs_write_settings()
@ 2015-01-09 12:32 Dan Carpenter
  2015-01-09 13:42 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2015-01-09 12:32 UTC (permalink / raw)
  To: Stefan Achatz; +Cc: Jiri Kosina, linux-input, kernel-janitors

This is a static checker fix.  We write some binary settings to the
sysfs file.  One of the settings is the "->startup_profile".  There
isn't any checking to make sure it fits into the
pyra->profile_settings[] array in the profile_activated() function.

I added a check to pyra_sysfs_write_settings() in both places because
I wasn't positive that the other callers were correct.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/hid/hid-roccat-pyra.c b/drivers/hid/hid-roccat-pyra.c
index 1a07e07..47d7e74 100644
--- a/drivers/hid/hid-roccat-pyra.c
+++ b/drivers/hid/hid-roccat-pyra.c
@@ -35,6 +35,8 @@ static struct class *pyra_class;
 static void profile_activated(struct pyra_device *pyra,
 		unsigned int new_profile)
 {
+	if (new_profile >= ARRAY_SIZE(pyra->profile_settings))
+		return;
 	pyra->actual_profile = new_profile;
 	pyra->actual_cpi = pyra->profile_settings[pyra->actual_profile].y_cpi;
 }
@@ -257,9 +259,11 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
 	if (off != 0 || count != PYRA_SIZE_SETTINGS)
 		return -EINVAL;
 
-	mutex_lock(&pyra->pyra_lock);
-
 	settings = (struct pyra_settings const *)buf;
+	if (settings->startup_profile >= ARRAY_SIZE(pyra->profile_settings))
+		return -EINVAL;
+
+	mutex_lock(&pyra->pyra_lock);
 
 	retval = pyra_set_settings(usb_dev, settings);
 	if (retval) {

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

* Re: [patch] HID: roccat: potential out of bounds in pyra_sysfs_write_settings()
  2015-01-09 12:32 [patch] HID: roccat: potential out of bounds in pyra_sysfs_write_settings() Dan Carpenter
@ 2015-01-09 13:42 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2015-01-09 13:42 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Stefan Achatz, linux-input, kernel-janitors

On Fri, 9 Jan 2015, Dan Carpenter wrote:

> This is a static checker fix.  We write some binary settings to the
> sysfs file.  One of the settings is the "->startup_profile".  There
> isn't any checking to make sure it fits into the
> pyra->profile_settings[] array in the profile_activated() function.
> 
> I added a check to pyra_sysfs_write_settings() in both places because
> I wasn't positive that the other callers were correct.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied to hid.git#for-3.19/upstream-fixes. Thanks,

-- 
Jiri Kosina
SUSE Labs

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

end of thread, other threads:[~2015-01-09 13:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-09 12:32 [patch] HID: roccat: potential out of bounds in pyra_sysfs_write_settings() Dan Carpenter
2015-01-09 13:42 ` Jiri Kosina

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