From: sashiko-bot@kernel.org
To: "Sven Püschel" <s.pueschel@pengutronix.de>
Cc: conor+dt@kernel.org, krzk+dt@kernel.org, robh@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v6 11/28] media: rockchip: rga: move hw specific parts to a dedicated struct
Date: Fri, 15 May 2026 16:05:30 +0000 [thread overview]
Message-ID: <20260515160531.11E2EC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260515-spu-rga3-v6-11-e547152eb9c9@pengutronix.de>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] Lack of PM state verification in the ISR allows spurious interrupts on suspended hardware to trigger a kernel panic.
- [Critical] Integer overflow in `vidioc_s_selection` allows bypassing bounds checks with maliciously large crop dimensions.
- [High] Use-After-Free race condition during module removal due to unbalanced teardown order in `rga_remove()`.
- [High] Unhandled initialization error in `rga_open()` leads to a use-after-free of a destroyed mutex.
--
commit 0a388e94d347297bf67ec0c6a92dbb56a186e007
Author: Sven Püschel <s.pueschel@pengutronix.de>
media: rockchip: rga: move hw specific parts to a dedicated struct
In preparation for the RGA3 unit, move RGA2 specific parts from rga.c
to rga-hw.c and create a struct to reference the RGA2 specific functions
and formats.
> diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
> index 8c34f73d69764..f599c992829dd 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
> @@ -55,13 +54,8 @@ static void device_run(void *prv)
> static irqreturn_t rga_isr(int irq, void *prv)
> {
> struct rockchip_rga *rga = prv;
> - int intr;
>
> - intr = rga_read(rga, RGA_INT) & 0xf;
> -
> - rga_mod(rga, RGA_INT, intr << 4, 0xf << 4);
> -
> - if (intr & 0x04) {
> + if (rga->hw->handle_irq(rga)) {
> struct vb2_v4l2_buffer *src, *dst;
> struct rga_ctx *ctx = rga->curr;
>
> WARN_ON(!ctx);
This isn't a bug introduced by this commit, but is it possible for rga_isr
to be called when the device is suspended?
If the device is suspended, reading RGA_INT might return 0xffffffff, which
evaluates to true here. Since ctx would be NULL, the code warns but then
dereferences ctx via ctx->fh.m2m_ctx, which could cause a panic.
With the planned addition of IRQF_SHARED support for external IOMMUs
mentioned in later patches, another device on the same shared interrupt
line could trigger this when the RGA is suspended. Would we need to verify
if the device is active using pm_runtime_get_if_active() before accessing
registers?
[ ... ]
> @@ -360,9 +225,9 @@ static int rga_open(struct file *file)
> ctx->out = def_frame;
>
> v4l2_fill_pixfmt_mp(&ctx->in.pix,
> - ctx->in.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT);
> + ctx->in.fmt->fourcc, def_width, def_height);
> v4l2_fill_pixfmt_mp(&ctx->out.pix,
> - ctx->out.fmt->fourcc, DEFAULT_WIDTH, DEFAULT_HEIGHT);
> + ctx->out.fmt->fourcc, def_width, def_height);
>
> if (mutex_lock_interruptible(&rga->mutex)) {
> kfree(ctx);
This isn't a bug introduced by this commit, but looking further down in
rga_open(), is it safe to ignore the return value of rga_setup_ctrls(ctx)?
If control setup fails, rga_setup_ctrls() internally calls
v4l2_ctrl_handler_free(), which frees the internal control buckets and
destroys the mutex.
However, rga_open() blindly proceeds to call
v4l2_ctrl_handler_setup(&ctx->ctrl_handler) and assigns the freed handler
to ctx->fh.ctrl_handler. Could this lead to a use-after-free of the mutex
during subsequent V4L2 ioctl operations?
[ ... ]
> @@ -660,7 +527,7 @@ static int vidioc_s_selection(struct file *file, void *priv,
>
> if (s->r.left + s->r.width > f->pix.width ||
> s->r.top + s->r.height > f->pix.height ||
> - s->r.width < MIN_WIDTH || s->r.height < MIN_HEIGHT) {
> + s->r.width < rga->hw->min_width || s->r.height < rga->hw->min_height) {
> v4l2_dbg(debug, 1, &rga->v4l2_dev, "unsupported crop value.\n");
> return -EINVAL;
> }
This isn't a bug introduced by this commit, but can the
s->r.left + s->r.width check overflow here?
Since s->r.width is an unsigned 32-bit integer, providing a maliciously
large width (e.g., 0xFFFFFFFF) and a small left offset could cause the
addition to wrap around to 0, bypassing the bounds check.
Furthermore, 0xFFFFFFFF < rga->hw->min_width evaluates to false, which
bypasses this minimum size check as well. Could this result in out-of-bounds
memory operations when the hardware DMA engine is programmed with these
excessively large dimensions?
[ ... ]
> @@ -883,7 +750,7 @@ static void rga_remove(struct platform_device *pdev)
> {
> struct rockchip_rga *rga = platform_get_drvdata(pdev);
>
> - dma_free_attrs(rga->dev, RGA_CMDBUF_SIZE, rga->cmdbuf_virt,
> + dma_free_attrs(rga->dev, rga->hw->cmdbuf_size, rga->cmdbuf_virt,
> rga->cmdbuf_phy, DMA_ATTR_WRITE_COMBINE);
>
> v4l2_info(&rga->v4l2_dev, "Removing\n");
This isn't a bug introduced by this commit, but is the teardown order
in rga_remove() safe?
It frees the DMA command buffer and releases the mem2mem context before
calling video_unregister_device().
Could a concurrent userspace process holding the device open continue to
issue V4L2 ioctls while the module is unloading, potentially causing a
use-after-free on m2m_dev or the newly freed DMA buffer memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260515-spu-rga3-v6-0-e547152eb9c9@pengutronix.de?part=11
next prev parent reply other threads:[~2026-05-15 16:05 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 15:32 [PATCH v6 00/28] media: platform: rga: Add RGA3 support Sven Püschel
2026-05-15 15:32 ` [PATCH v6 01/28] media: dt-bindings: media: rockchip-rga: add rockchip,rk3588-rga3 Sven Püschel
2026-05-15 15:32 ` [PATCH v6 02/28] media: v4l2-common: sort RGB formats in v4l2_format_info Sven Püschel
2026-05-15 15:32 ` [PATCH v6 03/28] media: v4l2-common: add missing 1 and 2 byte RGB formats to v4l2_format_info Sven Püschel
2026-05-15 15:32 ` [PATCH v6 04/28] media: v4l2-common: add has_alpha " Sven Püschel
2026-05-15 15:32 ` [PATCH v6 05/28] media: v4l2-common: add v4l2_fill_pixfmt_mp_aligned helper Sven Püschel
2026-05-15 15:58 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 06/28] media: rockchip: rga: fix too small buffer size Sven Püschel
2026-05-15 15:32 ` [PATCH v6 07/28] media: rockchip: rga: use clk_bulk api Sven Püschel
2026-05-15 15:54 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 08/28] media: rockchip: rga: use stride for offset calculation Sven Püschel
2026-05-15 15:32 ` [PATCH v6 09/28] media: rockchip: rga: remove redundant rga_frame variables Sven Püschel
2026-05-15 15:32 ` [PATCH v6 10/28] media: rockchip: rga: announce and sync colorimetry Sven Püschel
2026-05-15 16:14 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 11/28] media: rockchip: rga: move hw specific parts to a dedicated struct Sven Püschel
2026-05-15 16:05 ` sashiko-bot [this message]
2026-05-15 15:32 ` [PATCH v6 12/28] media: rockchip: rga: avoid odd frame sizes for YUV formats Sven Püschel
2026-05-15 15:32 ` [PATCH v6 13/28] media: rockchip: rga: calculate x_div/y_div using v4l2_format_info Sven Püschel
2026-05-15 15:32 ` [PATCH v6 14/28] media: rockchip: rga: move cmdbuf to rga_ctx Sven Püschel
2026-05-15 16:12 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 15/28] media: rockchip: rga: align stride to 4 bytes Sven Püschel
2026-05-15 16:17 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 16/28] media: rockchip: rga: reuse cmdbuf contents Sven Püschel
2026-05-15 15:59 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 17/28] media: rockchip: rga: check scaling factor Sven Püschel
2026-05-15 16:54 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 18/28] media: rockchip: rga: use card type to specify rga type Sven Püschel
2026-05-15 16:00 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 19/28] media: rockchip: rga: change offset to dma_addresses Sven Püschel
2026-05-15 15:59 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 20/28] media: rockchip: rga: support external iommus Sven Püschel
2026-05-15 16:08 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 21/28] media: rockchip: rga: share the interrupt when an external iommu is used Sven Püschel
2026-05-15 16:11 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 22/28] media: rockchip: rga: remove size from rga_frame Sven Püschel
2026-05-15 16:21 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 23/28] media: rockchip: rga: remove stride " Sven Püschel
2026-05-15 15:32 ` [PATCH v6 24/28] media: rockchip: rga: move rga_fmt to rga-hw.h Sven Püschel
2026-05-15 15:32 ` [PATCH v6 25/28] media: rockchip: rga: add feature flags Sven Püschel
2026-05-15 16:22 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 26/28] media: rockchip: rga: disable multi-core support Sven Püschel
2026-05-15 15:32 ` [PATCH v6 27/28] media: rockchip: rga: add rga3 support Sven Püschel
2026-05-15 16:34 ` sashiko-bot
2026-05-15 15:32 ` [PATCH v6 28/28] arm64: dts: rockchip: add rga3 dt nodes Sven Püschel
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=20260515160531.11E2EC2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=robh@kernel.org \
--cc=s.pueschel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox