[PATCH 1/2] media: meson: vdec: clear stale prev_frame/cur_frame on flush
From: Doruk Tan Ozturk
Date: Sat Jun 27 2026 - 02:56:23 EST
codec_vp9_flush_output() (the .drain callback) walks ref_frames_list
and kfree()s every vp9_frame node, but never clears vp9->prev_frame
or vp9->cur_frame, which alias nodes that were just freed.
If decoding resumes after a flush with an inter (non-key) frame,
codec_vp9_process_frame() calls codec_vp9_set_mpred_mv(), which
dereferences vp9->prev_frame->{width,height,intra_only,show,type}
and feeds vp9->prev_frame to codec_vp9_get_frame_mv_paddr(). With
prev_frame still pointing at freed memory this is a use-after-free.
Clear both cached pointers once the list has been freed so a resumed
decode starts from a clean state.
Found by 0sec's autonomous vulnerability analysis (https://0sec.ai).
Found by static analysis; not yet runtime-reproduced (Amlogic Meson
hardware required).
Fixes: 00c43088aa68 ("media: meson: vdec: add VP9 decoder support")
Signed-off-by: Doruk Tan Ozturk <doruk@xxxxxxx>
---
drivers/staging/media/meson/vdec/codec_vp9.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/staging/media/meson/vdec/codec_vp9.c b/drivers/staging/media/meson/vdec/codec_vp9.c
index 8e80ecf84193..5ca27930239f 100644
--- a/drivers/staging/media/meson/vdec/codec_vp9.c
+++ b/drivers/staging/media/meson/vdec/codec_vp9.c
@@ -681,6 +681,16 @@ static void codec_vp9_flush_output(struct amvdec_session *sess)
list_del(&tmp->list);
kfree(tmp);
}
+
+ /*
+ * All ref_frames_list nodes have been freed above. Drop the cached
+ * pointers so a decode resuming after the flush (e.g. an inter frame
+ * following a drain) cannot dereference freed vp9_frame memory in
+ * codec_vp9_set_mpred_mv().
+ */
+ vp9->prev_frame = NULL;
+ vp9->cur_frame = NULL;
+
mutex_unlock(&vp9->lock);
}
--
2.53.0