Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [libgpiod][PATCH] core: ignore positive values returned by the GPIO_V2_GET_LINE ioctl()
@ 2024-01-24 10:39 Bartosz Golaszewski
  2024-01-24 10:54 ` Kent Gibson
  0 siblings, 1 reply; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-01-24 10:39 UTC (permalink / raw)
  To: Linus Walleij, Kent Gibson, Phil Howard
  Cc: linux-gpio, Bartosz Golaszewski,
	José Guilherme de Castro Rodrigues

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

If the kernel GPIO driver (erroneously) returns a positive value from one
of its callbacks, it may end up being propagated to user space as
a positive value returned by the call to ioctl(). Let's treat all
non-zero values as errors as GPIO uAPI ioctl()s are not expected to ever
return positive values. This should be addressed in the kernel but will
remain a problem on older or unpatched versions so we need to sanitize it
in user-space too.

Reported-by: José Guilherme de Castro Rodrigues <joseguilhermebh@hotmail.com>
Fixes: b7ba732e6a93 ("treewide: libgpiod v2 implementation")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 lib/chip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/chip.c b/lib/chip.c
index 7c05e53..7bf40c6 100644
--- a/lib/chip.c
+++ b/lib/chip.c
@@ -239,7 +239,7 @@ gpiod_chip_request_lines(struct gpiod_chip *chip,
 		return NULL;
 
 	ret = ioctl(chip->fd, GPIO_V2_GET_LINE_IOCTL, &uapi_req);
-	if (ret < 0)
+	if (ret)
 		return NULL;
 
 	request = gpiod_line_request_from_uapi(&uapi_req, info.name);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-24 12:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-24 10:39 [libgpiod][PATCH] core: ignore positive values returned by the GPIO_V2_GET_LINE ioctl() Bartosz Golaszewski
2024-01-24 10:54 ` Kent Gibson
2024-01-24 10:58   ` Bartosz Golaszewski
2024-01-24 11:29     ` Kent Gibson
2024-01-24 12:11       ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox