[PATCH] media: rppx1: Validate and process a copy of the parameters buffer

From: Hyeonjun Hong

Date: Wed Dec 02 2026 - 10:32:09 EST


rppx1_params() validates the parameters buffer in place and then walks
it again to process the blocks. The buffer comes from a vb2 queue that
supports VB2_MMAP and VB2_DMABUF, so userspace can keep a mapping and
modify the content while the driver is using it.

Everything that was validated can therefore change before it is used.
The loop in rppx1_params() reads data_size again on each iteration and
advances by a header.size that it reads again, so a larger data_size
makes the driver read past the end of the buffer, and a header.size of
0 in a block that is not handled keeps the loop from advancing.
v4l2_isp_params_validate_buffer() itself reads data_size more than once.

The other users of the v4l2-isp helpers, rkisp1, mali-c55 and c3-isp,
copy the buffer first and only use the copy. Do the same here.

Fixes: b562e72bdb98 ("media: rppx1: Add framework to support Dreamchip RPPX1 ISP")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hyeonjun Hong <hyeonjunhong330@xxxxxxxxx>
---
How this was found and tested:

- Found by comparing the callers of the v4l2-isp helpers, with the help
of an LLM (Claude). Same review pass as
https://lore.kernel.org/all/20261202151718.694973-1-hyeonjunhong330@xxxxxxxxx/
but independent of that series.
- I do not have R-Car hardware. Tested only in a userspace model that
compiles the unmodified function bodies of rppx1_params() and the
v4l2-isp validation helpers with AddressSanitizer, while a second
thread flips data_size in the shared buffer.
Before: heap-buffer-overflow READ of size 2 right after the buffer,
in v4l2_isp_params_validate_buffer(), within the first second. I
could only reproduce it at -O0; at -O1 the compiler merges the reads.
I have not checked how many reads the arm64 kernel build ends up
with.
After: 400 million iterations without a report.
- Compile tested for arm64 with W=1.
- Not tested on hardware.

This conflicts with "[PATCH 0/7] Introduce v4l2-isp reset buffers",
which changes the same function. I can rebase on top of it if that
series goes in first.

The copy is allocated per call to keep the fix local to rppx1_params().
The other drivers allocate it once in buf_init; that would need a
change in how rcar-isp and rppx1 share the buffer, which I can do in a
follow-up if preferred.

.../platform/dreamchip/rppx1/rpp_params.c | 21 ++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/dreamchip/rppx1/rpp_params.c b/drivers/media/platform/dreamchip/rppx1/rpp_params.c
index 44b0c2e673b7..241b92366a9d 100644
--- a/drivers/media/platform/dreamchip/rppx1/rpp_params.c
+++ b/drivers/media/platform/dreamchip/rppx1/rpp_params.c
@@ -5,6 +5,8 @@
* Copyright (C) 2026 Ragnatech AB
*/

+#include <linux/slab.h>
+
#include <media/v4l2-isp.h>
#include <media/videobuf2-v4l2.h>

@@ -49,13 +51,20 @@ int rppx1_params(struct rppx1 *rpp, struct vb2_buffer *vb, size_t max_size,
if (ret)
return ret;

- cfg = vb2_plane_vaddr(&vbuf->vb2_buf, 0);
+ /*
+ * The buffer is shared with userspace, which can modify its content
+ * at any time. Validate and process a copy.
+ */
+ cfg = kmemdup(vb2_plane_vaddr(&vbuf->vb2_buf, 0),
+ vb2_get_plane_payload(vb, 0), GFP_KERNEL);
+ if (!cfg)
+ return -ENOMEM;

ret = v4l2_isp_params_validate_buffer(rpp->dev, vb, cfg,
rppx1_ext_params_blocks_info,
ARRAY_SIZE(rppx1_ext_params_blocks_info));
if (ret)
- return ret;
+ goto out_free;

/* Walk the list of parameter blocks and process them. */
block_offset = 0;
@@ -63,7 +72,6 @@ int rppx1_params(struct rppx1 *rpp, struct vb2_buffer *vb, size_t max_size,
const union rppx1_params_block *block =
(const union rppx1_params_block *)&cfg->data[block_offset];
struct rpp_module *module;
- int ret;

block_offset += block->header.size;

@@ -107,13 +115,16 @@ int rppx1_params(struct rppx1 *rpp, struct vb2_buffer *vb, size_t max_size,
dev_err(rpp->dev,
"Error processing RPPX1 block type: 0x%04x\n",
block->header.type);
- return ret;
+ goto out_free;
}
}

/* Trigger update of shadowed registers after frame is done. */
write(priv, RPPX1_RPP_HDR_UPD_REG, RPPX1_RPP_HDR_UPD_REGS_GEN_CFG_UPD);

- return 0;
+out_free:
+ kfree(cfg);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(rppx1_params);

base-commit: 62dfd7c0e599b6f02392b117ee77a070796ad765
--
2.34.1