Commit 88ce1fe8 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Luis Henriques

Input: evdev - fix EVIOCG{type} ioctl

commit 7c4f5607 upstream.

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: default avatarPavel Machek <pavel@ucw.cz>
Reviewed-by: default avatarPavel Machek <pavel@ucw.cz>
Reviewed-by: default avatarDavid Herrmann <dh.herrmann@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent aefb6152
...@@ -739,20 +739,23 @@ static int evdev_handle_set_keycode_v2(struct input_dev *dev, void __user *p) ...@@ -739,20 +739,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, static int evdev_handle_get_val(struct evdev_client *client,
struct input_dev *dev, unsigned int type, struct input_dev *dev, unsigned int type,
unsigned long *bits, unsigned int max, unsigned long *bits, unsigned int maxbit,
unsigned int size, void __user *p, int compat) unsigned int maxlen, void __user *p,
int compat)
{ {
int ret; int ret;
unsigned long *mem; 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) if (!mem)
return -ENOMEM; return -ENOMEM;
spin_lock_irq(&dev->event_lock); spin_lock_irq(&dev->event_lock);
spin_lock(&client->buffer_lock); spin_lock(&client->buffer_lock);
memcpy(mem, bits, sizeof(unsigned long) * max); memcpy(mem, bits, len);
spin_unlock(&dev->event_lock); spin_unlock(&dev->event_lock);
...@@ -760,7 +763,7 @@ static int evdev_handle_get_val(struct evdev_client *client, ...@@ -760,7 +763,7 @@ static int evdev_handle_get_val(struct evdev_client *client,
spin_unlock_irq(&client->buffer_lock); 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) if (ret < 0)
evdev_queue_syn_dropped(client); evdev_queue_syn_dropped(client);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment