mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: st-delta: fix decoder use-after-free on release
@ 2026-10-28  7:44 Sicong Huang
  2026-11-26 21:47 ` Nicolas Dufresne
  0 siblings, 1 reply; 3+ messages in thread
From: Sicong Huang @ 2026-10-28  7:44 UTC (permalink / raw)
  To: linux-media; +Cc: hugues.fruchet, mchehab, linux-kernel, Sicong Huang

The st-delta driver processes decoding jobs asynchronously. Its V4L2
mem2mem .device_run callback, delta_device_run(), queues ctx->run_work,
which executes delta_run_work() to decode an access unit. For MJPEG,
the worker accesses the decoder-private context stored in ctx->priv
and the IPC buffer shared with the firmware.

During release, delta_release() closes the decoder before calling
v4l2_m2m_ctx_release() to cancel outstanding jobs. For MJPEG,
delta_mjpeg_close() frees the decoder-private context and closes the
IPC channel, releasing its shared buffer if the channel was opened.
However, the V4L2 core does not stop streaming before invoking
delta_release(), so ctx->run_work may still be queued or running.
The delta->lock held by delta_release() does not synchronize with the
worker, which uses ctx->lock. As a result, the worker may access
freed decoder state, causing a use-after-free.

One possible interleaving is:

  CPU0 (release)                    CPU1 (worker)
                                    delta_run_work()
                                      delta_mjpeg_decode()
                                        ctx = to_ctx(pctx)
  delta_release()
    delta_mjpeg_close()
      kfree(ctx)
                                        if (!ctx->header) /* UAF */
    v4l2_m2m_ctx_release()
      /* Waits for the job too late. */

Here, ctx in the MJPEG functions refers to struct delta_mjpeg_ctx.

Move v4l2_m2m_ctx_release() before closing the decoder. It prevents
further scheduling for the instance, removes jobs waiting in the mem2mem
queue, and waits for an active job to finish. Since delta_run_work()
completes its decoder accesses before signalling job completion, the
decoder can be safely closed afterwards.

Found by code inspection.
Fixes: f386509e4959 ("[media] st-delta: STiH4xx multi-format video decoder v4l2 driver")

Signed-off-by: Sicong Huang <congei42@163.com>
---
 drivers/media/platform/st/sti/delta/delta-v4l2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/st/sti/delta/delta-v4l2.c b/drivers/media/platform/st/sti/delta/delta-v4l2.c
index 7dd27de37b78..586dae169d35 100644
--- a/drivers/media/platform/st/sti/delta/delta-v4l2.c
+++ b/drivers/media/platform/st/sti/delta/delta-v4l2.c
@@ -1699,6 +1699,9 @@ static int delta_release(struct file *file)
 
 	mutex_lock(&delta->lock);
 
+	/* make sure no m2m job runs once the decoder is closed */
+	v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
+
 	/* close decoder */
 	call_dec_op(dec, close, ctx);
 
@@ -1708,8 +1711,6 @@ static int delta_release(struct file *file)
 	 */
 	delta_trace_summary(ctx);
 
-	v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
-
 	v4l2_fh_del(&ctx->fh, file);
 	v4l2_fh_exit(&ctx->fh);
 

base-commit: 27285b099fbc5cb2ae3aef20f3bbd7b3c88b3005
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: st-delta: fix decoder use-after-free on release
  2026-10-28  7:44 [PATCH] media: st-delta: fix decoder use-after-free on release Sicong Huang
@ 2026-11-26 21:47 ` Nicolas Dufresne
  2026-11-27 20:42   ` Jérôme AUDU
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Dufresne @ 2026-11-26 21:47 UTC (permalink / raw)
  To: Sicong Huang, linux-media, hugues.fruchet; +Cc: mchehab, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 369 bytes --]

Hi,

Le mercredi 28 octobre 2026 à 15:44 +0800, Sicong Huang a écrit :
> Found by code inspection.

All the changes in this driver since 2022 (and even there I'm not sure) are
"found by code inspection". Is there any users left of this? Shall we just
remove this driver ?

I'll hold on any changes until I ear back from Hugues or someone at ST.

Nicolas

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: st-delta: fix decoder use-after-free on release
  2026-11-26 21:47 ` Nicolas Dufresne
@ 2026-11-27 20:42   ` Jérôme AUDU
  0 siblings, 0 replies; 3+ messages in thread
From: Jérôme AUDU @ 2026-11-27 20:42 UTC (permalink / raw)
  To: Nicolas Dufresne, Sicong Huang, linux-media, hugues.fruchet
  Cc: mchehab, linux-kernel

Hi Nicolas, Hugues, all,

On Thu, 2026-11-26 at 16:47 -0500, Nicolas Dufresne wrote:
 > All the changes in this driver since 2022 (and even there I'm not
 > sure) are "found by code inspection". Is there any users left of
 > this? Shall we just remove this driver ? I'll hold on any changes
 > until I ear back from Hugues or someone at ST.

Yes, there are still active users of st-delta on real hardware, so
please keep it in mainline if possible!

There are at least 20 active boards — specifically STiH418-B2264
(4kopen) and STiH410-B2260 — running kernels that have been tracking
mainline closely for several years (currently on 7.3.y).

Over the last 6 months, mostly as a hobby project, we have done quite a
bit of work on top of the mainline STi drivers (st-delta, st-hva, bdisp,
sti-drm) and completed hardware decoding support in st-delta for
MPEG-1/2, MPEG-4 Part 2, H.264, H.265/HEVC, and VC-1/WMV9 (whereas
upstream only had MJPEG), working end-to-end with GStreamer and
FFmpeg/mpv. To be completely transparent, AI-assisted development
helped a lot to make this feasible on spare time, and everything is
thoroughly verified and validated on real hardware (including
conformance bitstreams).

Cleaning up and upstreaming our fixes and additions will take time
since this is done on spare time, so I don't want to over-promise on a
timeline, but it is definitely something we would like to do step by
step.

In the meantime, if it helps keep st-delta alive in mainline, I am
happy to test patches on real hardware (including this use-after-free
fix) so changes don't remain "code inspection only".

Best regards,
Jerome

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28  7:44 [PATCH] media: st-delta: fix decoder use-after-free on release Sicong Huang
2026-11-26 21:47 ` Nicolas Dufresne
2026-11-27 20:42   ` Jérôme AUDU

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®