[PATCH] media: imx-jpeg: Prevent decoding NV12M jpegs into single-planar buffers
From: Mirela Rabulea
Date: Tue Jan 11 2022 - 21:10:17 EST
If the application queues an NV12M jpeg as output buffer, but then
queues a single planar capture buffer, the kernel will crash with
"Unable to handle kernel NULL pointer dereference" in mxc_jpeg_addrs,
prevent this by finishing the job with error.
Signed-off-by: Mirela Rabulea <mirela.rabulea@xxxxxxxxxxx>
---
drivers/media/platform/imx-jpeg/mxc-jpeg.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
index 4ca96cf9def7..6acb17318cf4 100644
--- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c
+++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
@@ -947,6 +947,11 @@ static void mxc_jpeg_device_run(void *priv)
v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true);
jpeg_src_buf = vb2_to_mxc_buf(&src_buf->vb2_buf);
+ if (q_data_cap->fmt->colplanes == 2 &&
+ dst_buf->vb2_buf.num_planes < 2) {
+ dev_err(dev, "Decoding multi-planar, but capture buffer is single-planar\n");
+ jpeg_src_buf->jpeg_parse_error = true;
+ }
if (jpeg_src_buf->jpeg_parse_error) {
jpeg->slot_data[ctx->slot].used = false;
v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
--
2.25.1