From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Subject: Re: [PATCH] gpiolib: fix invalid pointer access in debugfs
Date: Mon, 3 Nov 2025 09:45:04 +0200 [thread overview]
Message-ID: <aQhdgI33_f-tfHWu@smile.fi.intel.com> (raw)
In-Reply-To: <20251031150631.33592-1-brgl@bgdev.pl>
On Fri, Oct 31, 2025 at 04:06:31PM +0100, Bartosz Golaszewski wrote:
>
> If the memory allocation in gpiolib_seq_start() fails, the s->private
> field remains uninitialized and is later dereferenced without checking
> in gpiolib_seq_stop(). Initialize s->private to NULL before calling
> kzalloc() and check it before dereferencing it.
...
> static void gpiolib_seq_stop(struct seq_file *s, void *v)
> {
> struct gpiolib_seq_priv *priv = s->private;
>
> + if (!priv)
> + return;
My preference is to have the assignment be decoupled in such a case:
struct gpiolib_seq_priv *priv;
priv = s->private;
if (!priv)
return;
This will prevent from doing subtle mistakes (as dereferencing before check and
so on) in the future. Not that I expect this function to grow that way, but still...
always keep in mind that somebody who is not familiar with the code may take the
piece as high standard in the kernel and copy to their code without much thinking.
> srcu_read_unlock(&gpio_devices_srcu, priv->idx);
> kfree(priv);
> }
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2025-11-03 7:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-31 15:06 [PATCH] gpiolib: fix invalid pointer access in debugfs Bartosz Golaszewski
2025-11-01 8:55 ` Ilya Gavrilov
2025-11-01 22:49 ` Linus Walleij
2025-11-02 8:40 ` Markus Elfring
2025-11-03 7:45 ` Andy Shevchenko [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=aQhdgI33_f-tfHWu@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=brgl@bgdev.pl \
--cc=linus.walleij@linaro.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;
as well as URLs for NNTP newsgroup(s).