From: Bartosz Golaszewski Date: Mon, 16 Jul 2018 08:34:23 +0000 (+0200) Subject: gpiolib: don't allow userspace to set values of input lines X-Git-Tag: v5.15~8221^2~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e5332d5437764f775cf4e3b8ca3bf592af063a02;p=platform%2Fkernel%2Flinux-starfive.git gpiolib: don't allow userspace to set values of input lines User space can currently both read and set values of input lines using the character device. This was not allowed by the old sysfs interface nor is it a correct behavior. Check the first descriptor in the set for the OUT flag when asked to set values and return -EPERM if the line is input. Signed-off-by: Bartosz Golaszewski Signed-off-by: Linus Walleij --- diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 2e2a6f8..c507cd3 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -449,7 +449,13 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd, return 0; } else if (cmd == GPIOHANDLE_SET_LINE_VALUES_IOCTL) { - /* TODO: check if descriptors are really output */ + /* + * All line descriptors were created at once with the same + * flags so just check if the first one is really output. + */ + if (!test_bit(FLAG_IS_OUT, &lh->descs[0]->flags)) + return -EPERM; + if (copy_from_user(&ghd, ip, sizeof(ghd))) return -EFAULT;