Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Bartosz Golaszewski and committed by
Linus Walleij
e5332d54 ad817297

+7 -1
+7 -1
drivers/gpio/gpiolib.c
··· 449 449 450 450 return 0; 451 451 } else if (cmd == GPIOHANDLE_SET_LINE_VALUES_IOCTL) { 452 - /* TODO: check if descriptors are really output */ 452 + /* 453 + * All line descriptors were created at once with the same 454 + * flags so just check if the first one is really output. 455 + */ 456 + if (!test_bit(FLAG_IS_OUT, &lh->descs[0]->flags)) 457 + return -EPERM; 458 + 453 459 if (copy_from_user(&ghd, ip, sizeof(ghd))) 454 460 return -EFAULT; 455 461