mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@kernel.org>,
	Alexandru Ardelean <ardeleanalex@gmail.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: buffer: fix use-after-free for attached_buffers array
Date: Sun, 7 Mar 2021 13:54:28 +0100	[thread overview]
Message-ID: <a1ffef80-2f43-68bc-cb46-4f3bac326671@metafoo.de> (raw)
In-Reply-To: <20210307123658.3bdc0016@archlinux>

On 3/7/21 1:36 PM, Jonathan Cameron wrote:
> On Sat,  6 Mar 2021 18:47:10 +0200
> Alexandru Ardelean <ardeleanalex@gmail.com> wrote:
>
>> Thanks to Lars for finding this.
>> The free of the 'attached_buffers' array should be done as late as
>> possible. This change moves it to iio_buffers_put(), which looks like
>> the best place for it, since it takes place right before the IIO device
>> data is free'd.
> It feels a bit wrong to do direct freeing of stuff in a _put() call
> given that kind of implies nothing will happen without some reference
> count dropping to 0.  We could think about renaming the function to
> something like
>
> iio_buffers_put_and_free_array() but is a bit long winded.
>
> Otherwise, I'm fine with this but want to let it sit on list a tiny bit
> longer before I take it as it's not totally trivial unlike the previous
> one.

Maybe to go with naming schema of iio_device_attach_buffer() call this 
function iio_device_detach_buffers(). We grab the reference in attach, 
and drop it in detach.

- Lars


  reply	other threads:[~2021-03-07 12:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-06 16:47 Alexandru Ardelean
2021-03-07 12:36 ` Jonathan Cameron
2021-03-07 12:54   ` Lars-Peter Clausen [this message]
2021-03-07 18:35     ` Alexandru Ardelean
2021-03-07 18:54 ` [PATCH v2] " Alexandru Ardelean
2021-03-08  7:29   ` Alexandru Ardelean
2021-03-13 18:28     ` Jonathan Cameron

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=a1ffef80-2f43-68bc-cb46-4f3bac326671@metafoo.de \
    --to=lars@metafoo.de \
    --cc=ardeleanalex@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@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

all inboxes | Powered by JetHome®