* [PATCH 0/2] media: rcar-isp: Fix ConfigDMA buffer overflow
@ 2026-12-02 15:17 Hyeonjun Hong
2026-12-02 15:17 ` [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check Hyeonjun Hong
2026-12-02 15:17 ` [PATCH 2/2] media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is full Hyeonjun Hong
0 siblings, 2 replies; 8+ messages in thread
From: Hyeonjun Hong @ 2026-12-02 15:17 UTC (permalink / raw)
To: Niklas Söderlund, Mauro Carvalho Chehab
Cc: Geert Uytterhoeven, Magnus Damm, linux-media, linux-renesas-soc,
linux-kernel, stable
Hi,
The bounds check that protects the ConfigDMA buffer of the R-Car ISP
core does not account for the 8 byte header, so one address/value pair
can be written past the end of the 16384 byte buffer. The number of
pairs depends on the parameters buffer queued by userspace on the
params video node.
Patch 1/2 fixes the check. Patch 2/2 makes buffer preparation fail when
the buffer is full, as the result of the write callback is not checked
by the rppx1 block handlers.
How this was found and tested:
- Found by reading the callers of the v4l2-isp helpers side by side,
with the help of an LLM (Claude).
- I do not have R-Car hardware. The overflow was reproduced only in a
userspace model that compiles the unmodified function bodies of
risp_conf_dma_prepare(), rppx1_params(), the CCOR block handler and
the v4l2-isp validation helpers, built with AddressSanitizer.
170 header-only, disabled CCOR_POST blocks: 2041 pairs, no report.
171 blocks: heap-buffer-overflow, WRITE of size 4, 0 bytes after the
16384 byte region, in risp_conf_dma_prepare().
With the series applied: stops at 2047 pairs (16384 bytes used) and
returns -ENOMEM.
- Compile tested for arm64 with W=1.
- Not tested on hardware.
One thing I could not resolve from the code: risp_core_job_prepare() in
core.c limits the pair count to (RISP_IO_PARAMS_BUF_SIZE - 8) / 16,
i.e. 16 bytes per pair, while core-io.c and vsp1_vspx.c count 8 bytes
per pair. With this series a buffer holding 1024..2047 pairs passes
buf_prepare and is then rejected when the job is prepared. I left that
check alone as I do not know which limit is the intended one.
Hyeonjun Hong (2):
media: rcar-isp: Account for the header in the ConfigDMA bounds check
media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is
full
drivers/media/platform/renesas/rcar-isp/core-io.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
base-commit: 62dfd7c0e599b6f02392b117ee77a070796ad765
--
2.34.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check
2026-12-02 15:17 [PATCH 0/2] media: rcar-isp: Fix ConfigDMA buffer overflow Hyeonjun Hong
@ 2026-12-02 15:17 ` Hyeonjun Hong
2026-12-02 16:26 ` Niklas Söderlund
2026-12-02 15:17 ` [PATCH 2/2] media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is full Hyeonjun Hong
1 sibling, 1 reply; 8+ messages in thread
From: Hyeonjun Hong @ 2026-12-02 15:17 UTC (permalink / raw)
To: Niklas Söderlund, Mauro Carvalho Chehab
Cc: Geert Uytterhoeven, Magnus Damm, linux-media, linux-renesas-soc,
linux-kernel, stable
risp_io_params_buffer_prepare() fills the ConfigDMA buffer with
address/value pairs starting 8 bytes into the buffer, the first 8 bytes
being reserved for the header. The bounds check in
risp_conf_dma_prepare() compares the size of the pairs alone against
RISP_IO_PARAMS_BUF_SIZE, so it accepts one pair more than fits and the
last accepted pair is written to bytes 16384..16391 of the 16384 byte
buffer.
The number of pairs is controlled by the parameters buffer queued by
userspace. v4l2_isp_params_validate_buffer() accepts repeated blocks of
the same type and a header-only block still results in register writes.
For example 171 header-only RPPX1_PARAMS_BLOCK_TYPE_CCOR_POST blocks
with V4L2_ISP_PARAMS_FL_BLOCK_DISABLE set (1368 bytes of block data)
produce more than the 2047 pairs that fit.
Include the header in the check.
Fixes: 2151350f60d1 ("media: rcar-isp: Add support for ISPCORE")
Cc: stable@vger.kernel.org
Signed-off-by: Hyeonjun Hong <hyeonjunhong330@gmail.com>
---
drivers/media/platform/renesas/rcar-isp/core-io.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
index b60b91f43d42..5c6018491160 100644
--- a/drivers/media/platform/renesas/rcar-isp/core-io.c
+++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
@@ -507,8 +507,8 @@ static int risp_conf_dma_prepare(void *priv, u32 offset, u32 value)
{
struct risp_conf_dma_write_desc *desc = priv;
- /* Bounds check, 8 bytes = address (4)+ value (4). */
- if ((desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE)
+ /* Bounds check, 8 bytes header + 8 bytes = address (4) + value (4). */
+ if (8 + (desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE)
return -ENOMEM;
(*desc->buf++) = desc->base | offset;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is full
2026-12-02 15:17 [PATCH 0/2] media: rcar-isp: Fix ConfigDMA buffer overflow Hyeonjun Hong
2026-12-02 15:17 ` [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check Hyeonjun Hong
@ 2026-12-02 15:17 ` Hyeonjun Hong
2026-12-02 16:31 ` Niklas Söderlund
1 sibling, 1 reply; 8+ messages in thread
From: Hyeonjun Hong @ 2026-12-02 15:17 UTC (permalink / raw)
To: Niklas Söderlund, Mauro Carvalho Chehab
Cc: Geert Uytterhoeven, Magnus Damm, linux-media, linux-renesas-soc,
linux-kernel, stable
risp_conf_dma_prepare() returns -ENOMEM when the ConfigDMA buffer is
full, but the rppx1 block handlers that call it do not check the result
of the write callback. rppx1_params() then returns 0, the remaining
register writes are dropped without notice and the truncated
configuration is queued.
Record the condition in the write descriptor and fail
risp_io_params_buffer_prepare() if it was hit, instead of adding error
handling to every write in the rppx1 block handlers.
Signed-off-by: Hyeonjun Hong <hyeonjunhong330@gmail.com>
---
drivers/media/platform/renesas/rcar-isp/core-io.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
index 5c6018491160..a5f18aeb1f28 100644
--- a/drivers/media/platform/renesas/rcar-isp/core-io.c
+++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
@@ -501,6 +501,7 @@ struct risp_conf_dma_write_desc {
u32 *buf;
u32 base;
unsigned int count;
+ bool overflow;
};
static int risp_conf_dma_prepare(void *priv, u32 offset, u32 value)
@@ -508,8 +509,10 @@ static int risp_conf_dma_prepare(void *priv, u32 offset, u32 value)
struct risp_conf_dma_write_desc *desc = priv;
/* Bounds check, 8 bytes header + 8 bytes = address (4) + value (4). */
- if (8 + (desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE)
+ if (8 + (desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE) {
+ desc->overflow = true;
return -ENOMEM;
+ }
(*desc->buf++) = desc->base | offset;
(*desc->buf++) = value;
@@ -534,6 +537,7 @@ static int risp_io_params_buffer_prepare(struct vb2_buffer *vb)
desc.buf = cpu_addr + 2;
desc.base = io->core->rppaddr;
desc.count = 0;
+ desc.overflow = false;
/* Fill params body. */
ret = rppx1_params(io->core->rpp, vb, io->format.fmt.meta.buffersize,
@@ -541,6 +545,10 @@ static int risp_io_params_buffer_prepare(struct vb2_buffer *vb)
if (ret)
return ret;
+ /* The block handlers do not check the result of the write callback. */
+ if (desc.overflow)
+ return -ENOMEM;
+
/* Fill params header. */
cpu_addr[0] = desc.count;
cpu_addr[1] = 0x0;
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check
2026-12-02 15:17 ` [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check Hyeonjun Hong
@ 2026-12-02 16:26 ` Niklas Söderlund
2026-12-02 16:38 ` Hyeonjun Hong
0 siblings, 1 reply; 8+ messages in thread
From: Niklas Söderlund @ 2026-12-02 16:26 UTC (permalink / raw)
To: Hyeonjun Hong
Cc: Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
linux-media, linux-renesas-soc, linux-kernel, stable
Hi Hyeonjun,
Thanks for your work.
On 2026-12-03 00:17:17 +0900, Hyeonjun Hong wrote:
> risp_io_params_buffer_prepare() fills the ConfigDMA buffer with
> address/value pairs starting 8 bytes into the buffer, the first 8 bytes
> being reserved for the header. The bounds check in
> risp_conf_dma_prepare() compares the size of the pairs alone against
> RISP_IO_PARAMS_BUF_SIZE, so it accepts one pair more than fits and the
> last accepted pair is written to bytes 16384..16391 of the 16384 byte
> buffer.
>
> The number of pairs is controlled by the parameters buffer queued by
> userspace. v4l2_isp_params_validate_buffer() accepts repeated blocks of
> the same type and a header-only block still results in register writes.
> For example 171 header-only RPPX1_PARAMS_BLOCK_TYPE_CCOR_POST blocks
> with V4L2_ISP_PARAMS_FL_BLOCK_DISABLE set (1368 bytes of block data)
> produce more than the 2047 pairs that fit.
>
> Include the header in the check.
>
> Fixes: 2151350f60d1 ("media: rcar-isp: Add support for ISPCORE")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hyeonjun Hong <hyeonjunhong330@gmail.com>
> ---
> drivers/media/platform/renesas/rcar-isp/core-io.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
> index b60b91f43d42..5c6018491160 100644
> --- a/drivers/media/platform/renesas/rcar-isp/core-io.c
> +++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
> @@ -507,8 +507,8 @@ static int risp_conf_dma_prepare(void *priv, u32 offset, u32 value)
> {
> struct risp_conf_dma_write_desc *desc = priv;
>
> - /* Bounds check, 8 bytes = address (4)+ value (4). */
> - if ((desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE)
> + /* Bounds check, 8 bytes header + 8 bytes = address (4) + value (4). */
> + if (8 + (desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE)
Nice catch, but could you move the magic values to defines, maybe
something like,
#define RISP_IO_PARAMS_HEADER_SIZE 8
#define RISP_IO_PARAMS_MAX_PAIRS ((RISP_IO_PARAMS_BUF_SIZE - RISP_IO_PARAMS_HEADER_SIZE) / 8)
And use them here? I really should have added RISP_IO_PARAMS_MAX_PAIRS
myself when writing this...
> return -ENOMEM;
>
> (*desc->buf++) = desc->base | offset;
> --
> 2.34.1
>
--
Kind Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is full
2026-12-02 15:17 ` [PATCH 2/2] media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is full Hyeonjun Hong
@ 2026-12-02 16:31 ` Niklas Söderlund
2026-12-02 16:43 ` Hyeonjun Hong
0 siblings, 1 reply; 8+ messages in thread
From: Niklas Söderlund @ 2026-12-02 16:31 UTC (permalink / raw)
To: Hyeonjun Hong
Cc: Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
linux-media, linux-renesas-soc, linux-kernel, stable
Hi Hyeonjun,
Thanks for your work.
On 2026-12-03 00:17:18 +0900, Hyeonjun Hong wrote:
> risp_conf_dma_prepare() returns -ENOMEM when the ConfigDMA buffer is
> full, but the rppx1 block handlers that call it do not check the result
> of the write callback. rppx1_params() then returns 0, the remaining
> register writes are dropped without notice and the truncated
> configuration is queued.
>
> Record the condition in the write descriptor and fail
> risp_io_params_buffer_prepare() if it was hit, instead of adding error
> handling to every write in the rppx1 block handlers.
>
> Signed-off-by: Hyeonjun Hong <hyeonjunhong330@gmail.com>
> ---
> drivers/media/platform/renesas/rcar-isp/core-io.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/renesas/rcar-isp/core-io.c b/drivers/media/platform/renesas/rcar-isp/core-io.c
> index 5c6018491160..a5f18aeb1f28 100644
> --- a/drivers/media/platform/renesas/rcar-isp/core-io.c
> +++ b/drivers/media/platform/renesas/rcar-isp/core-io.c
> @@ -501,6 +501,7 @@ struct risp_conf_dma_write_desc {
> u32 *buf;
> u32 base;
> unsigned int count;
> + bool overflow;
I don't like adding a flag for this, and it's not needed...
> };
>
> static int risp_conf_dma_prepare(void *priv, u32 offset, u32 value)
> @@ -508,8 +509,10 @@ static int risp_conf_dma_prepare(void *priv, u32 offset, u32 value)
> struct risp_conf_dma_write_desc *desc = priv;
>
> /* Bounds check, 8 bytes header + 8 bytes = address (4) + value (4). */
> - if (8 + (desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE)
> + if (8 + (desc->count + 1) * 8 > RISP_IO_PARAMS_BUF_SIZE) {
... This check while also setting the new overflow flag will return
-ENOMEM ...
> + desc->overflow = true;
> return -ENOMEM;
> + }
>
> (*desc->buf++) = desc->base | offset;
> (*desc->buf++) = value;
> @@ -534,6 +537,7 @@ static int risp_io_params_buffer_prepare(struct vb2_buffer *vb)
> desc.buf = cpu_addr + 2;
> desc.base = io->core->rppaddr;
> desc.count = 0;
> + desc.overflow = false;
>
> /* Fill params body. */
> ret = rppx1_params(io->core->rpp, vb, io->format.fmt.meta.buffersize,
> @@ -541,6 +545,10 @@ static int risp_io_params_buffer_prepare(struct vb2_buffer *vb)
> if (ret)
> return ret;
... Which will be propagated and returned here ...
>
> + /* The block handlers do not check the result of the write callback. */
> + if (desc.overflow)
> + return -ENOMEM;
... So this check will never be reached.
> +
> /* Fill params header. */
> cpu_addr[0] = desc.count;
> cpu_addr[1] = 0x0;
> --
> 2.34.1
>
--
Kind Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check
2026-12-02 16:26 ` Niklas Söderlund
@ 2026-12-02 16:38 ` Hyeonjun Hong
2026-12-02 16:43 ` Niklas Söderlund
0 siblings, 1 reply; 8+ messages in thread
From: Hyeonjun Hong @ 2026-12-02 16:38 UTC (permalink / raw)
To: Niklas Söderlund
Cc: Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
linux-media, linux-renesas-soc, linux-kernel, stable
Hi Niklas,
Thanks for the review.
On 2026-12-02 17:26:45 +0100, Niklas Söderlund wrote:
> Nice catch, but could you move the magic values to defines, maybe
> something like,
>
> #define RISP_IO_PARAMS_HEADER_SIZE 8
> #define RISP_IO_PARAMS_MAX_PAIRS ((RISP_IO_PARAMS_BUF_SIZE - RISP_IO_PARAMS_HEADER_SIZE) / 8)
>
> And use them here?
Will do in v2. The check then becomes
if (desc->count >= RISP_IO_PARAMS_MAX_PAIRS)
return -ENOMEM;
and I will also update the comment above RISP_IO_PARAMS_BUF_SIZE, which
says 2048 pairs.
One related question, also in the cover letter: risp_core_job_prepare()
in core.c rejects the buffer if
pairs > (RISP_IO_PARAMS_BUF_SIZE - 8) / 16
which is 1023, i.e. it counts 16 bytes per pair. Should that become
RISP_IO_PARAMS_MAX_PAIRS as well? If so I can add a patch for it to v2.
Thanks,
Hyeonjun
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is full
2026-12-02 16:31 ` Niklas Söderlund
@ 2026-12-02 16:43 ` Hyeonjun Hong
0 siblings, 0 replies; 8+ messages in thread
From: Hyeonjun Hong @ 2026-12-02 16:43 UTC (permalink / raw)
To: Niklas Söderlund
Cc: Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
linux-media, linux-renesas-soc, linux-kernel, stable
Hi Niklas,
On 2026-12-02 17:31:00 +0100, Niklas Söderlund wrote:
> ... This check while also setting the new overflow flag will return
> -ENOMEM ...
[...]
> ... Which will be propagated and returned here ...
I do not think it is propagated. The block handlers ignore the return
value of the write callback and return 0, e.g. rppx1_ccor_fill_params():
write(priv, mod->base + CCOR_COEFF_REG(0), 0x1000);
[...]
return 0;
None of the write() calls in the rppx1_*.c handlers is checked, so
rppx1_params() returns 0 after the buffer is full. In the userspace
model, with only patch 1/2 applied, 700 header-only CCOR_POST blocks
give 2047 pairs written and rppx1_params() == 0.
> I don't like adding a flag for this, and it's not needed...
Understood. Would you prefer one of these instead?
a) No flag, keep counting in the callback and check the count
afterwards:
if (desc->count++ >= RISP_IO_PARAMS_MAX_PAIRS)
return -ENOMEM;
and in risp_io_params_buffer_prepare():
if (desc.count > RISP_IO_PARAMS_MAX_PAIRS)
return -ENOMEM;
b) Make the rppx1 block handlers check and return the result of
write(). That is the proper fix but touches about 170 call sites
in rppx1.
c) Drop patch 2/2 and leave it as is.
Thanks,
Hyeonjun
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check
2026-12-02 16:38 ` Hyeonjun Hong
@ 2026-12-02 16:43 ` Niklas Söderlund
0 siblings, 0 replies; 8+ messages in thread
From: Niklas Söderlund @ 2026-12-02 16:43 UTC (permalink / raw)
To: Hyeonjun Hong
Cc: Mauro Carvalho Chehab, Geert Uytterhoeven, Magnus Damm,
linux-media, linux-renesas-soc, linux-kernel, stable
On 2026-12-03 01:38:31 +0900, Hyeonjun Hong wrote:
> Hi Niklas,
>
> Thanks for the review.
>
> On 2026-12-02 17:26:45 +0100, Niklas Söderlund wrote:
> > Nice catch, but could you move the magic values to defines, maybe
> > something like,
> >
> > #define RISP_IO_PARAMS_HEADER_SIZE 8
> > #define RISP_IO_PARAMS_MAX_PAIRS ((RISP_IO_PARAMS_BUF_SIZE - RISP_IO_PARAMS_HEADER_SIZE) / 8)
d00h this should have been / 16, not / 8. Maybe add a define for that
too, RISP_IO_PARAMS_PAIR_SIZE and use that ;-)
> >
> > And use them here?
>
> Will do in v2. The check then becomes
>
> if (desc->count >= RISP_IO_PARAMS_MAX_PAIRS)
> return -ENOMEM;
>
> and I will also update the comment above RISP_IO_PARAMS_BUF_SIZE, which
> says 2048 pairs.
>
> One related question, also in the cover letter: risp_core_job_prepare()
> in core.c rejects the buffer if
>
> pairs > (RISP_IO_PARAMS_BUF_SIZE - 8) / 16
>
> which is 1023, i.e. it counts 16 bytes per pair. Should that become
> RISP_IO_PARAMS_MAX_PAIRS as well? If so I can add a patch for it to v2.
Most likely.
>
> Thanks,
> Hyeonjun
--
Kind Regards,
Niklas Söderlund
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-02 16:43 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 15:17 [PATCH 0/2] media: rcar-isp: Fix ConfigDMA buffer overflow Hyeonjun Hong
2026-12-02 15:17 ` [PATCH 1/2] media: rcar-isp: Account for the header in the ConfigDMA bounds check Hyeonjun Hong
2026-12-02 16:26 ` Niklas Söderlund
2026-12-02 16:38 ` Hyeonjun Hong
2026-12-02 16:43 ` Niklas Söderlund
2026-12-02 15:17 ` [PATCH 2/2] media: rcar-isp: Fail buffer preparation if the ConfigDMA buffer is full Hyeonjun Hong
2026-12-02 16:31 ` Niklas Söderlund
2026-12-02 16:43 ` Hyeonjun Hong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox