Skip to content

Commit d77651a

Browse files
committed
Input: uinput - fix undefined behavior in uinput_validate_absinfo()
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 <[email protected]> Reviewed-by: Peter Hutterer <[email protected]> Cc: [email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 3eb66e9 commit d77651a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/input/misc/uinput.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <linux/init.h>
4040
#include <linux/fs.h>
4141
#include <linux/miscdevice.h>
42+
#include <linux/overflow.h>
4243
#include <linux/input/mt.h>
4344
#include "../input-compat.h"
4445

@@ -405,7 +406,7 @@ static int uinput_open(struct inode *inode, struct file *file)
405406
static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code,
406407
const struct input_absinfo *abs)
407408
{
408-
int min, max;
409+
int min, max, range;
409410

410411
min = abs->minimum;
411412
max = abs->maximum;
@@ -417,7 +418,7 @@ static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code,
417418
return -EINVAL;
418419
}
419420

420-
if (abs->flat > max - min) {
421+
if (!check_sub_overflow(max, min, &range) && abs->flat > range) {
421422
printk(KERN_DEBUG
422423
"%s: abs_flat #%02x out of range: %d (min:%d/max:%d)\n",
423424
UINPUT_NAME, code, abs->flat, min, max);

0 commit comments

Comments
 (0)