From: Dmitry Torokhov Date: Mon, 6 Oct 2014 17:55:49 +0000 (-0700) Subject: Input: evdev - fix EVIOCG{type} ioctl X-Git-Tag: v3.18-rc1~6^2~5^2~11 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=7c4f56070fde2367766fa1fb04852599b5e1ad35;p=~emulex%2Finfiniband.git Input: evdev - fix EVIOCG{type} ioctl The 'max' size passed into the function is measured in number of bits (KEY_MAX, LED_MAX, etc) so we need to convert it accordingly before trying to copy the data out, otherwise we will try copying too much and end up with up with a page fault. Reported-by: Pavel Machek Reviewed-by: Pavel Machek Reviewed-by: David Herrmann Signed-off-by: Dmitry Torokhov --- diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index de055451d1a..bc203485716 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c @@ -738,20 +738,23 @@ static int evdev_handle_set_keycode_v2(struct input_dev *dev, void __user *p) */ static int evdev_handle_get_val(struct evdev_client *client, struct input_dev *dev, unsigned int type, - unsigned long *bits, unsigned int max, - unsigned int size, void __user *p, int compat) + unsigned long *bits, unsigned int maxbit, + unsigned int maxlen, void __user *p, + int compat) { int ret; unsigned long *mem; + size_t len; - mem = kmalloc(sizeof(unsigned long) * max, GFP_KERNEL); + len = BITS_TO_LONGS(maxbit) * sizeof(unsigned long); + mem = kmalloc(len, GFP_KERNEL); if (!mem) return -ENOMEM; spin_lock_irq(&dev->event_lock); spin_lock(&client->buffer_lock); - memcpy(mem, bits, sizeof(unsigned long) * max); + memcpy(mem, bits, len); spin_unlock(&dev->event_lock); @@ -759,7 +762,7 @@ static int evdev_handle_get_val(struct evdev_client *client, spin_unlock_irq(&client->buffer_lock); - ret = bits_to_user(mem, max, size, p, compat); + ret = bits_to_user(mem, maxbit, maxlen, p, compat); if (ret < 0) evdev_queue_syn_dropped(client);