Re: [PATCH v3 3/4] media: iris: Fix use-after-free on unbind with open sessions
From: Vikash Garodia
Date: Fri Nov 27 2026 - 07:29:02 EST
On 11/19/2026 5:15 PM, Vishnu Reddy wrote:
The driver can be unbound through sysfs while a client has a video
session open. The core is devm allocated and freed when remove()
returns, so the open sessions then use freed memory.
Only the core structure needs to outlive remove(), because it is the
only thing the file operations of an open session still use. Allocate
it with kzalloc and tie it to the reference count of its v4l2_device,
which every registered video device holds. It is freed when the last
file descriptor is closed. The other devm resources (register mapping,
response packet, clocks, power domains, interconnects) are only used by
the power on/off sequence, the clock and bandwidth votes and the
interrupt handler. All of them are released with the unbind, after the
core is shut down.
To make sure nothing uses them afterwards, set a removing flag at the
start of iris_remove(). It makes core init, new sessions, command
writes and the clock and interconnect votes fail with -ENODEV, so a
client still holding a file descriptor cannot power the hardware on or
vote for resources that are gone. A client waiting for the firmware
only times out and returns an error without touching them. Runtime PM
is also disabled explicitly in iris_remove() instead of with devm,
because its callbacks use the core.
Callers that hold a runtime PM reference, such as iris_open(),
iris_hfi_queue_cmd_write() and iris_scale_power(), can still be running
when remove() starts, as video_unregister_device() does not wait for
them. Take an rw_semaphore for read around the reference and wait for
it in iris_remove(), so that the references are dropped before runtime
PM is disabled and the unbind releases the resources of the device.
Fixes: 38506cb7e8d2 ("media: iris: add platform driver for iris video device")
Reported-by: sashiko-bot<sashiko-bot@xxxxxxxxxx>
Closes:https://lore.kernel.org/all/20260926064921.976721F000FF@xxxxxxxxxxxxxxx
Cc:stable@xxxxxxxxxxxxxxx
Signed-off-by: Vishnu Reddy<busanna.reddy@xxxxxxxxxxxxxxxx>
---
drivers/media/platform/qcom/iris/iris_core.c | 5 +++
drivers/media/platform/qcom/iris/iris_core.h | 4 ++
drivers/media/platform/qcom/iris/iris_hfi_queue.c | 18 ++++++++-
drivers/media/platform/qcom/iris/iris_power.c | 24 +++++++++++-
drivers/media/platform/qcom/iris/iris_probe.c | 48 ++++++++++++++++++-----
drivers/media/platform/qcom/iris/iris_vidc.c | 15 ++++++-
6 files changed, 102 insertions(+), 12 deletions(-)
Reviewed-by: Vikash Garodia <vikash.garodia@xxxxxxxxxxxxxxxx>