From: Kent Gibson <warthog618@gmail.com>
To: Douglas Anderson <dianders@chromium.org>
Cc: Linus Walleij <linusw@kernel.org>,
Christian Brauner <brauner@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] gpio: Avoid NULL dereference in linehandle_create()
Date: Sun, 15 Feb 2026 19:32:46 +0800 [thread overview]
Message-ID: <20260215113246.GA46983@rigel> (raw)
In-Reply-To: <20260213092930.1.I77c3eb563271c21870379eefd16ebbc4e09635bb@changeid>
On Fri, Feb 13, 2026 at 09:29:31AM -0800, Douglas Anderson wrote:
> In linehandle_create(), there is a statement like this:
> retain_and_null_ptr(lh);
>
> Soon after, there is a debug printout that dereferences "lh", which
> will crash things.
>
> Avoid the crash by reading value needed by the printout before making
> "lh" NULL.
>
> Fixes: da7e394bf58f ("gpio: convert linehandle_create() to FD_PREPARE()")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
>
> drivers/gpio/gpiolib-cdev.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
> index 2adc3c070908..13ab6a5ebb76 100644
> --- a/drivers/gpio/gpiolib-cdev.c
> +++ b/drivers/gpio/gpiolib-cdev.c
> @@ -304,6 +304,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
> {
> struct gpiohandle_request handlereq;
> struct linehandle_state *lh __free(linehandle_free) = NULL;
> + u32 num_descs;
> int i, ret;
> u32 lflags;
>
> @@ -379,6 +380,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
> lh, O_RDONLY | O_CLOEXEC));
> if (fdf.err)
> return fdf.err;
> + num_descs = lh->num_descs;
> retain_and_null_ptr(lh);
>
> handlereq.fd = fd_prepare_fd(fdf);
> @@ -388,7 +390,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
> fd_publish(fdf);
>
> dev_dbg(&gdev->dev, "registered chardev handle for %d lines\n",
> - lh->num_descs);
> + num_descs);
>
Use handlereq.lines rather than creating another local shadow.
Cheers,
Kent.
prev parent reply other threads:[~2026-02-15 11:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-13 17:29 [PATCH] gpio: Avoid NULL dereference in linehandle_create() Douglas Anderson
2026-02-15 11:32 ` Kent Gibson [this message]
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=20260215113246.GA46983@rigel \
--to=warthog618@gmail.com \
--cc=brauner@kernel.org \
--cc=brgl@kernel.org \
--cc=dianders@chromium.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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