From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
"Phil Howard" <phil@gadgetoid.com>,
linux-gpio@vger.kernel.org,
"Bartosz Golaszewski" <bartosz.golaszewski@linaro.org>,
"José Guilherme de Castro Rodrigues"
<joseguilhermebh@hotmail.com>
Subject: Re: [libgpiod][PATCH] core: ignore positive values returned by the GPIO_V2_GET_LINE ioctl()
Date: Wed, 24 Jan 2024 19:29:07 +0800 [thread overview]
Message-ID: <20240124112907.GA67212@rigel> (raw)
In-Reply-To: <CAMRc=MfGJ2UxOdchd=qmM340x2d-QT0egpG4HkR1fCiz8sfyoA@mail.gmail.com>
On Wed, Jan 24, 2024 at 11:58:16AM +0100, Bartosz Golaszewski wrote:
> On Wed, Jan 24, 2024 at 11:54 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > On Wed, Jan 24, 2024 at 11:39:29AM +0100, Bartosz Golaszewski wrote:
> > > 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;
> > >
> >
> > What is errno going to be here?
> > Is errno set if the ioctl returns positive?
> >
>
> No it isn't, thanks for catching it.
>
> This patch is incomplete - we need a wrapper around ioctl() for all
> uAPI calls that will check for positive numbers and set errno to
> ERANGE (is that the right one? any other ideas?) then return -1.
>
The two things I'm looking for in an error code would be that we don't
use it already, and it isn't too confusing.
ERANGE is typically for numeric overlow, so a bit confusing.
EBADE?
Though EHWPOISON does seem fitting given the root cause ;-).
Cheers,
Kent.
next prev parent reply other threads:[~2024-01-24 11:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-01-24 12:11 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240124112907.GA67212@rigel \
--to=warthog618@gmail.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=joseguilhermebh@hotmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=phil@gadgetoid.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox