summaryrefslogtreecommitdiffstats
path: root/drivers/input/evdev.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2014-10-06 13:55:49 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-10-07 12:55:01 -0400
commit7c4f56070fde2367766fa1fb04852599b5e1ad35 (patch)
treebae58fba448d8f38252bc2d7bccffb03fa503a1d /drivers/input/evdev.c
parent042e1c79166b9250edd8262bea84e1703f27ad2e (diff)
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 <pavel@ucw.cz> Reviewed-by: Pavel Machek <pavel@ucw.cz> Reviewed-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/evdev.c')
-rw-r--r--drivers/input/evdev.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index de055451d1af..bc203485716d 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)
738 */ 738 */
739static int evdev_handle_get_val(struct evdev_client *client, 739static int evdev_handle_get_val(struct evdev_client *client,
740 struct input_dev *dev, unsigned int type, 740 struct input_dev *dev, unsigned int type,
741 unsigned long *bits, unsigned int max, 741 unsigned long *bits, unsigned int maxbit,
742 unsigned int size, void __user *p, int compat) 742 unsigned int maxlen, void __user *p,
743 int compat)
743{ 744{
744 int ret; 745 int ret;
745 unsigned long *mem; 746 unsigned long *mem;
747 size_t len;
746 748
747 mem = kmalloc(sizeof(unsigned long) * max, GFP_KERNEL); 749 len = BITS_TO_LONGS(maxbit) * sizeof(unsigned long);
750 mem = kmalloc(len, GFP_KERNEL);
748 if (!mem) 751 if (!mem)
749 return -ENOMEM; 752 return -ENOMEM;
750 753
751 spin_lock_irq(&dev->event_lock); 754 spin_lock_irq(&dev->event_lock);
752 spin_lock(&client->buffer_lock); 755 spin_lock(&client->buffer_lock);
753 756
754 memcpy(mem, bits, sizeof(unsigned long) * max); 757 memcpy(mem, bits, len);
755 758
756 spin_unlock(&dev->event_lock); 759 spin_unlock(&dev->event_lock);
757 760
@@ -759,7 +762,7 @@ static int evdev_handle_get_val(struct evdev_client *client,
759 762
760 spin_unlock_irq(&client->buffer_lock); 763 spin_unlock_irq(&client->buffer_lock);
761 764
762 ret = bits_to_user(mem, max, size, p, compat); 765 ret = bits_to_user(mem, maxbit, maxlen, p, compat);
763 if (ret < 0) 766 if (ret < 0)
764 evdev_queue_syn_dropped(client); 767 evdev_queue_syn_dropped(client);
765 768