From: Lars-Peter Clausen Date: Tue, 18 Oct 2016 14:54:01 +0000 (+0200) Subject: gpio: GPIO_GET_LINEHANDLE_IOCTL: Validate line offset X-Git-Tag: v4.8.7~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e22edf53b40fabd70ed61d4c1d1f6dc4cfdbb8ef;p=thirdparty%2Fkernel%2Fstable.git gpio: GPIO_GET_LINEHANDLE_IOCTL: Validate line offset commit e405f9fcb63602d35f7a419ededa3f952a395a72 upstream. 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. Fixes: d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines") Signed-off-by: Lars-Peter Clausen Signed-off-by: Linus Walleij Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6c443ddedb38b..ee20b46d798e7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -442,6 +442,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)