From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
linux-iio@vger.kernel.org,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Paul Cercueil" <paul@crapouillou.net>
Subject: Re: [PATCH 3/3] iio: buffer: Make IIO DMA fence release RCU-safe
Date: Wed, 15 Jul 2026 19:17:47 +0300 [thread overview]
Message-ID: <aleyq2J6tVWYA6pC@ashevche-desk.local> (raw)
In-Reply-To: <20260715154245.3814378-3-lars@metafoo.de>
On Wed, Jul 15, 2026 at 08:42:45AM -0700, Lars-Peter Clausen wrote:
> The `dma_fence` documentation states that if a custom release
> implementation is provided, the `dma_fence` object must be freed in an
> RCU-safe way. The current `iio_dma_fence` implementation uses `kfree()`,
> which might result in a use-after-free.
>
> Remove the custom `release` implementation. This makes the DMA fence core
> fall back to `dma_fence_free()`, which calls `kfree_rcu()` on the fence.
> This requires that the fence be the first member of `struct iio_dma_fence`.
>
> Using the default release method for extended DMA fence structures is a
> common pattern.
...
> + /*
> + * Must remain the first member so the default release callback can pass
> + * the fence directly to dma_fence_free().
> + */
> struct dma_fence base;
TBH, I don't like this trick. container_of() is there for a reason. Even if
it's the first member in the structure. Can we simply switch to RCU version?
Would it require big changes?
> -static void iio_buffer_dma_fence_release(struct dma_fence *fence)
> -{
> - struct iio_dma_fence *iio_fence =
> - container_of(fence, struct iio_dma_fence, base);
> -
> - kfree(iio_fence);
So, we can't use dma_fence_free() here, because without above guarantee it will
get a wrong address. Maybe (maybe!) as a quick fix this is fine, but in long
term can we also have a refactoring patch that drops above comment at the end?
> -}
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-07-15 16:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 15:42 [PATCH 1/3] iio: buffer: Fix potential use-after-free in anonymous buffer release Lars-Peter Clausen
2026-07-15 15:42 ` [PATCH 2/3] iio: buffer: Tie IIO dma fence lock lifetime to the fence Lars-Peter Clausen
2026-07-15 15:42 ` [PATCH 3/3] iio: buffer: Make IIO DMA fence release RCU-safe Lars-Peter Clausen
2026-07-15 16:17 ` Andy Shevchenko [this message]
2026-07-15 17:21 ` Lars-Peter Clausen
2026-07-19 0:56 ` Jonathan Cameron
2026-07-15 16:12 ` [PATCH 1/3] iio: buffer: Fix potential use-after-free in anonymous buffer release Andy Shevchenko
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=aleyq2J6tVWYA6pC@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=paul@crapouillou.net \
/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