From: "Niklas Söderlund" <niklas.soderlund@ragnatech.se>
To: Hyeonjun Hong <hyeonjunhong330@gmail.com>
Cc: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>,
Jai Luthra <jai.luthra+renesas@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] media: rppx1: Validate and process a copy of the parameters buffer
Date: Wed, 2 Dec 2026 17:12:51 +0100 [thread overview]
Message-ID: <20261202161251.GF3157946@ragnatech.se> (raw)
In-Reply-To: <20261202153137.701735-1-hyeonjunhong330@gmail.com>
Hi Hyeonjun,
Thanks for your work.
On 2026-12-03 00:31:37 +0900, Hyeonjun Hong wrote:
> 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.
Can't this be fixed in the v4l2-isp helpers instead of fixing every
user?
>
> Fixes: b562e72bdb98 ("media: rppx1: Add framework to support Dreamchip RPPX1 ISP")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hyeonjun Hong <hyeonjunhong330@gmail.com>
> ---
> 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@gmail.com/
> 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
>
--
Kind Regards,
Niklas Söderlund
next prev parent reply other threads:[~2026-12-02 16:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 15:31 [PATCH] media: rppx1: Validate and process a copy of the parameters buffer Hyeonjun Hong
2026-12-02 16:12 ` Niklas Söderlund [this message]
2026-12-02 16:54 ` Hyeonjun Hong
2026-12-02 16:57 ` Niklas Söderlund
2026-12-02 17:04 ` Hyeonjun Hong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202161251.GF3157946@ragnatech.se \
--to=niklas.soderlund@ragnatech.se \
--cc=hyeonjunhong330@gmail.com \
--cc=jacopo.mondi+renesas@ideasonboard.com \
--cc=jai.luthra+renesas@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.