Skip to content

Commit

Permalink
gpio: GPIO_GET_LINEHANDLE_IOCTL: Validate line offset
Browse files Browse the repository at this point in the history
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: d7c51b4 ("gpio: userspace ABI for reading/writing GPIO lines")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Lars-Peter Clausen authored and Linus Walleij committed Oct 21, 2016
1 parent 0f4bbb2 commit e405f9f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
u32 lflags = handlereq.flags;
struct gpio_desc *desc;

if (offset >= gdev->ngpio) {
ret = -EINVAL;
goto out_free_descs;
}

desc = &gdev->descs[offset];
ret = gpiod_request(desc, lh->label);
if (ret)
Expand Down

0 comments on commit e405f9f

Please sign in to comment.