linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Pitre <nicolas.pitre@linaro.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: smuchun@gmail.com,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] gpiolib: Fix possible use after free on label
Date: Fri, 2 Nov 2018 12:12:24 -0400 (EDT)	[thread overview]
Message-ID: <nycvar.YSQ.7.76.1811021205400.1498@knanqh.ubzr> (raw)
In-Reply-To: <CACRpkdZ_jrNNB7n0DOuL6n_JtupiwacbMxWcockTak9F8fdAjA@mail.gmail.com>

On Fri, 2 Nov 2018, Linus Walleij wrote:

> On Thu, Nov 1, 2018 at 4:27 PM Linus Walleij <linus.walleij@linaro.org> wrote:
> > On Thu, Nov 1, 2018 at 2:13 PM Muchun Song <smuchun@gmail.com> wrote:
> >
> > > gpiod_request_commit() copies the pointer to the label passed as
> > > an argument only to be used later. But there's a chance the caller
> > > could immediately free the passed string(e.g., local variable).
> > > This could trigger a use after free when we use gpio label(e.g.,
> > > gpiochip_unlock_as_irq(), gpiochip_is_requested()).
> > >
> > > To be on the safe side: duplicate the string with kstrdup_const()
> > > so that if an unaware user passes an address to a stack-allocated
> > > buffer, we won't get the arbitrary label.
> > >
> > > Also fix gpiod_set_consumer_name().
> > >
> > > Signed-off-by: Muchun Song <smuchun@gmail.com>
> >
> > I am still a bit worried about the kstrdup_const() that this
> > introduces.
> 
> Forget it. I realized after actually reading the code
> for kstrdup_const() that it really does exactly
> what we want.
> 
> I should stop assuming things are syntactic sugar
> in the kernel, we have some really smart people
> working with it...

I didn't know about kstrdup_const() either before just now.

If the device tree lands in the kernel rodata area then all is fine. I 
don't know enough about the actual DT processing to be sure though.


Nicolas

      reply	other threads:[~2018-11-02 16:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-01 13:12 [PATCH v2] gpiolib: Fix possible use after free on label Muchun Song
2018-11-01 15:27 ` Linus Walleij
2018-11-02  9:24   ` Linus Walleij
2018-11-02 16:12     ` Nicolas Pitre [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=nycvar.YSQ.7.76.1811021205400.1498@knanqh.ubzr \
    --to=nicolas.pitre@linaro.org \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=smuchun@gmail.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;
as well as URLs for NNTP newsgroup(s).