]> git.karo-electronics.de Git - linux-beck.git/commitdiff
gpio: GPIO_GET_LINEEVENT_IOCTL: Validate line offset
authorLars-Peter Clausen <lars@metafoo.de>
Tue, 18 Oct 2016 14:54:03 +0000 (16:54 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Fri, 21 Oct 2016 12:41:38 +0000 (14:41 +0200)
The line offset that is used as an index into the descs array is provided
by userspace and might go beyond the bounds of the array. If that happens
undefined behavior will occur.

Make sure that the offset is within the bounds of the desc array and reject
any requests that specify a value outside of it.

Cc: stable@vger.kernel.org
Fixes: 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c

index 4ed26bcf054c5c419ecb524523fc0b64d6a82230..db44a7da5eb44cec137d956175eea6dd7c33bef1 100644 (file)
@@ -733,6 +733,11 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
        lflags = eventreq.handleflags;
        eflags = eventreq.eventflags;
 
+       if (offset >= gdev->ngpio) {
+               ret = -EINVAL;
+               goto out_free_label;
+       }
+
        /* This is just wrong: we don't look for events on output lines */
        if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
                ret = -EINVAL;