]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: roccat: potential out of bounds in pyra_sysfs_write_settings()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 9 Jan 2015 12:32:31 +0000 (15:32 +0300)
committerZefan Li <lizefan@huawei.com>
Tue, 14 Apr 2015 09:33:52 +0000 (17:33 +0800)
commit 606185b20caf4c57d7e41e5a5ea4aff460aef2ab upstream.

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>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
[lizf: Backported to 3.4: define the variable @settings]
Signed-off-by: Zefan Li <lizefan@huawei.com>
drivers/hid/hid-roccat-pyra.c

index df05c1b1064ff18e304d2f08f3c59d920dceda9b..53466474b42025087ec9edf48893cf45b10548b8 100644 (file)
@@ -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;
 }
@@ -299,10 +301,15 @@ static ssize_t pyra_sysfs_write_settings(struct file *fp,
        int retval = 0;
        int difference;
        struct pyra_roccat_report roccat_report;
+       struct pyra_settings const *settings;
 
        if (off != 0 || count != sizeof(struct pyra_settings))
                return -EINVAL;
 
+       settings = (struct pyra_settings const *)buf;
+       if (settings->startup_profile >= ARRAY_SIZE(pyra->profile_settings))
+               return -EINVAL;
+
        mutex_lock(&pyra->pyra_lock);
        difference = memcmp(buf, &pyra->settings, sizeof(struct pyra_settings));
        if (difference) {