Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH v2] media: vicodec: zero-initialize stateful decoder heap buffers
@ 2026-09-08  7:27 Junrui Luo via B4 Relay
  0 siblings, 0 replies; only message in thread
From: Junrui Luo via B4 Relay @ 2026-09-08  7:27 UTC (permalink / raw)
  To: Hans Verkuil, Mauro Carvalho Chehab, Keiichi Watanabe,
	Nicolas Dufresne
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel, Yuhao Jiang,
	stable, Junrui Luo

From: Junrui Luo <moonafterrain@outlook.com>

The stateful decoder leaks uninitialized kernel heap memory to userspace.
A process that can open the decoder video node gets it back in the CAPTURE
buffers it dequeues.

The reference frame and the compressed frame buffer are allocated with
kvmalloc() in vicodec_start_streaming(), and the decoder can read them
before they have been written. The first frame is allowed to be a P-frame,
in which case it is decoded against a reference frame that was never
produced, and the padding rows below the visible area are never written
for any frame.

Use kvzalloc() for both allocations.

Fixes: 256bf813ba39 ("media: vicodec: add the virtual codec driver")
Reported-by: Yuhao Jiang <danisjiang@gmail.com>
Assisted-by: Claude:claude-opus-5
Cc: stable@vger.kernel.org
Signed-off-by: Junrui Luo <moonafterrain@outlook.com>
---
Changes in v2:
- Rewrite the commit message per Nicolas' review.
- Link to v1: https://lore.kernel.org/r/20260813-vicodec-fixes-v1-1-13077b5b6c29@outlook.com
---
 drivers/media/test-drivers/vicodec/vicodec-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c
index ff9d50fb05fd..0b898ed5801f 100644
--- a/drivers/media/test-drivers/vicodec/vicodec-core.c
+++ b/drivers/media/test-drivers/vicodec/vicodec-core.c
@@ -1595,9 +1595,9 @@ static int vicodec_start_streaming(struct vb2_queue *q,
 	}
 	state->ref_stride = q_data->coded_width * info->luma_alpha_step;
 
-	state->ref_frame.buf = kvmalloc(total_planes_size, GFP_KERNEL);
+	state->ref_frame.buf = kvzalloc(total_planes_size, GFP_KERNEL);
 	state->ref_frame.luma = state->ref_frame.buf;
-	new_comp_frame = kvmalloc(ctx->comp_max_size, GFP_KERNEL);
+	new_comp_frame = kvzalloc(ctx->comp_max_size, GFP_KERNEL);
 
 	if (!state->ref_frame.luma || !new_comp_frame) {
 		kvfree(state->ref_frame.luma);

---
base-commit: a500db7819c50db59e55f1b4fa1c3baa5a2616f3
change-id: 20260908-fixes-a453297f07c2

Best regards,
-- 
Junrui Luo <moonafterrain@outlook.com>



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-08  7:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08  7:27 [PATCH v2] media: vicodec: zero-initialize stateful decoder heap buffers Junrui Luo via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox