]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
Input: uinput - fix undefined behavior in uinput_validate_absinfo()
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 14 Jan 2019 21:54:55 +0000 (13:54 -0800)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 14 Aug 2019 09:18:49 +0000 (11:18 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837664
commit d77651a227f8920dd7ec179b84e400cce844eeb3 upstream.

An integer overflow may arise in uinput_validate_absinfo() if "max - min"
can't be represented by an "int". We should check for overflow before
trying to use the result.

Reported-by: Kyungtae Kim <kt0755@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Connor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/input/misc/uinput.c

index 0afeef1672bc2d4e3ec43eddc934206575c21892..f01ef955289abfbc1f718ec3361253ea1788c486 100644 (file)
@@ -32,6 +32,7 @@
  *             - first public version
  */
 #include <uapi/linux/uinput.h>
+#include <linux/overflow.h>
 #include <linux/poll.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
@@ -403,7 +404,7 @@ static int uinput_open(struct inode *inode, struct file *file)
 static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code,
                                   const struct input_absinfo *abs)
 {
-       int min, max;
+       int min, max, range;
 
        min = abs->minimum;
        max = abs->maximum;
@@ -415,7 +416,7 @@ static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code,
                return -EINVAL;
        }
 
-       if (abs->flat > max - min) {
+       if (!check_sub_overflow(max, min, &range) && abs->flat > range) {
                printk(KERN_DEBUG
                       "%s: abs_flat #%02x out of range: %d (min:%d/max:%d)\n",
                       UINPUT_NAME, code, abs->flat, min, max);