From: "Nuno Sá" <nuno.sa@analog.com>
To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Jonathan Cameron <jic23@kernel.org>
Cc: David Lechner <dlechner@baylibre.com>,
Andy Shevchenko <andy@kernel.org>,
stable@vger.kernel.org
Subject: Re: [PATCH] iio: buffer: fix bounce buffer use-after-free on unregister
Date: Mon, 16 Nov 2026 09:33:55 +0000 [thread overview]
Message-ID: <avrN564spY0seOze@nsa> (raw)
In-Reply-To: <20261106-iio-fix-possible-uaf-v1-1-1bd8b94e771b@analog.com>
On Fri, Nov 06, 2026 at 04:53:00PM +0000, Nuno Sá wrote:
> The bounce buffer used by iio_push_to_buffers_with_ts_unaligned() is
> allocated with devm_krealloc() against the IIO device itself. Since
> commit 699fb50d9903 ("drivers: base: Free devm resources when
> unregistering a device"), device_del() releases the devres of devices
> without a bound driver, so the bounce buffer is now freed from
> cdev_device_del() in iio_device_unregister().
>
> At that point buffering may still be enabled, as
> iio_disable_all_buffers() only runs afterwards. A trigger handler
> firing in that window copies the sample into the freed bounce buffer
> and pushes it to the buffers.
>
> To fix it, allocate the bounce buffer with plain krealloc() and free it
> in iio_dev_release().
>
> Assisted-by: LLM
> Fixes: 95ec3fdf2b79 ("iio: core: Introduce iio_push_to_buffers_with_ts_unaligned()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> ---
BTW, realized the other way the LLM tag is already outdated :)
- Nuno Sá
> Found this by accident and do note this is just code inspection.
>
> I tagged the original commit supporting the bounce_buffer in Fixes: but
> to be fair, the original commit was fine. Tagging 699fb50d9903 also
> looks bit odd but maybe it's the real one to blame?
> ---
> drivers/iio/industrialio-buffer.c | 6 ++----
> drivers/iio/industrialio-core.c | 1 +
> 2 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 4294101810fd..cc5fde0f5191 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -2464,10 +2464,8 @@ int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev,
> if (iio_dev_opaque->bounce_buffer_size != indio_dev->scan_bytes) {
> void *bb;
>
> - bb = devm_krealloc(&indio_dev->dev,
> - iio_dev_opaque->bounce_buffer,
> - indio_dev->scan_bytes,
> - GFP_KERNEL | __GFP_ZERO);
> + bb = krealloc(iio_dev_opaque->bounce_buffer,
> + indio_dev->scan_bytes, GFP_KERNEL | __GFP_ZERO);
> if (!bb)
> return -ENOMEM;
> iio_dev_opaque->bounce_buffer = bb;
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 825cf7f32059..ed097eb8d799 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1727,6 +1727,7 @@ static void iio_dev_release(struct device *device)
> lockdep_unregister_key(&iio_dev_opaque->mlock_key);
>
> ida_free(&iio_ida, iio_dev_opaque->id);
> + kfree(iio_dev_opaque->bounce_buffer);
> kfree(iio_dev_opaque);
> }
>
>
> ---
> base-commit: 20ce8ef9c9e04cd6c5ae0422e251a9b5936c6b7c
> change-id: 20261106-iio-fix-possible-uaf-853ce6ff96bc
> --
>
> Thanks!
> - Nuno Sá
>
prev parent reply other threads:[~2026-11-16 9:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 16:53 [PATCH] iio: buffer: fix bounce buffer use-after-free on unregister Nuno Sá
2026-11-15 0:41 ` Jonathan Cameron
2026-11-16 14:21 ` Nuno Sá
2026-11-16 9:33 ` Nuno Sá [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=avrN564spY0seOze@nsa \
--to=nuno.sa@analog.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.