HID: logitech-hidpp: add boundary check for name retrieval
authorPeter Wu <peter@lekensteyn.nl>
Thu, 11 Dec 2014 12:51:19 +0000 (13:51 +0100)
committerJiri Kosina <jkosina@suse.cz>
Thu, 11 Dec 2014 22:10:00 +0000 (23:10 +0100)
The HID response has a limited size. Do not trust the value returned by
hardware, check that it really fits in the message.

Signed-off-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-logitech-hidpp.c

index 4d72c20fa233427e46de1655178cd850398e7da2..4292cc33c11974fc09ec82142f6cb74aa5084ea6 100644 (file)
@@ -313,6 +313,9 @@ static char *hidpp_get_unifying_name(struct hidpp_device *hidpp_dev)
 
        len = response.rap.params[1];
 
+       if (2 + len > sizeof(response.rap.params))
+               return NULL;
+
        name = kzalloc(len + 1, GFP_KERNEL);
        if (!name)
                return NULL;