mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-18 23:09:29 +02:00
iio: buffer: Make IIO DMA fence release RCU-safe
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.
Reported-by: codex:gpt-5.6
Fixes: 3e26d9f08f ("iio: core: Add new DMABUF interface infrastructure")
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
f25ec4627d
commit
8662e56c31
@@ -54,6 +54,10 @@ struct iio_dmabuf_priv {
|
||||
};
|
||||
|
||||
struct iio_dma_fence {
|
||||
/*
|
||||
* Must remain the first member so the default release callback can pass
|
||||
* the fence directly to dma_fence_free().
|
||||
*/
|
||||
struct dma_fence base;
|
||||
spinlock_t lock; /* protects base */
|
||||
struct iio_dmabuf_priv *priv;
|
||||
@@ -1828,18 +1832,9 @@ iio_buffer_dma_fence_get_driver_name(struct dma_fence *fence)
|
||||
return "iio";
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static const struct dma_fence_ops iio_buffer_dma_fence_ops = {
|
||||
.get_driver_name = iio_buffer_dma_fence_get_driver_name,
|
||||
.get_timeline_name = iio_buffer_dma_fence_get_driver_name,
|
||||
.release = iio_buffer_dma_fence_release,
|
||||
};
|
||||
|
||||
static int iio_buffer_enqueue_dmabuf(struct iio_dev_buffer_pair *ib,
|
||||
|
||||
Reference in New Issue
Block a user