Linux Media Controller development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
	linux-media@vger.kernel.org
Subject: Re: [PATCH v5 11/14] dt-bindings: media: mediatek: vcodec: add decoder dt-bindings for mt8196
Date: Wed, 03 Jun 2026 09:03:29 +0000	[thread overview]
Message-ID: <20260603090329.7C4B21F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260603084045.17488-12-kyrie.wu@mediatek.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] The VCP message queue processing thread uses the untrusted `obj->id` directly as an array index without bounds checking, leading to out-of-bounds memory access and potential arbitrary code execution.
- [High] The VCP message queue kthreads spawned during firmware load are leaked, leading to a fatal Use-After-Free kernel panic on driver unbind.
- [High] The `ipi_id_ack` array stores negative error codes into `bool` elements, truncating them to `1`, and is never reset on success, which breaks error handling and permanently poisons the IPC state.
- [Medium] The patch adds the MT8196 compatible string but completely omits the corresponding hardware constraints mentioned in the commit message, breaking device tree validation for this SoC.
--

commit f686f0ab8d134aa32615f005292674ee98cf9fb9
Author: Yunfei Dong <yunfei.dong@mediatek.com>

dt-bindings: media: mediatek: vcodec: add decoder dt-bindings for mt8196

This commit adds the device tree binding compatible string for the MT8196
decoder. The commit message outlines hardware changes, including 12 clock
inputs, 2 power domains, and the use of VCP instead of SCP.

> The MT8196 decoder differs from previous generations in several
> key aspects, most notably in its use of VCP instead of SCP.
> Additionally, the MT8196 enhances codec capabilities by supporting
> HEVC Main10 profile decoding. To accommodate these hardware changes,
> the binding constraints specify a total of 12 clock inputs,
> consisting of 9 decoder clocks and 3 VCP interface clocks,
> along with 2 power domains covering both the decoder and VCP
> subsystems.

[Severity: Medium]
The commit message mentions that the binding constraints specify a total of 12
clock inputs, 2 power domains, and the use of VCP instead of SCP. However,
are these constraints actually added in this patch?

> diff --git a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
> index bf8082d87ac03..74e1d88d30568 100644
> --- a/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
> +++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-subdev-decoder.yaml
> @@ -76,6 +76,7 @@ properties:
>        - mediatek,mt8186-vcodec-dec
>        - mediatek,mt8188-vcodec-dec
>        - mediatek,mt8195-vcodec-dec
> +      - mediatek,mt8196-vcodec-dec

Looking at the diff, it appears only the compatible string is added. The
required conditional blocks and property constraints for the clocks, power
domains, and the mediatek,vcp property seem to be missing. Would this cause
valid MT8196 device tree files to falsely fail schema validation?

I also have some questions regarding the VCP message queue handling in the
related C driver files.

In drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c:

[Severity: High]
Does this code leak the vcp_enc_msq_thread kthread?

mtk_vcodec_fw_vcp.c:mtk_vcodec_vcp_load_firmware() {
    ...
    kthread_run(mtk_vcodec_vcp_msg_process_thread, fw, "vcp_enc_msq_thread");
    ...
}

It seems the task_struct pointer returned by kthread_run() is discarded, so
kthread_stop() cannot be called later in mtk_vcodec_vcp_release().

If the thread is leaked, could this lead to a use-after-free crash on driver
unbind? The leaked thread appears to block indefinitely on the waitqueue inside
the devres-managed fw->vcp struct:

mtk_vcodec_fw_vcp.c:mtk_vcodec_vcp_msg_process_thread() {
    ...
    ret = wait_event_interruptible(fw->vcp->msg_queue.wq,
                                   atomic_read(&fw->vcp->msg_queue.cnt) > 0);
    ...
}


[Severity: Critical]
Can an invalid firmware payload trigger an out-of-bounds memory access here?

mtk_vcodec_fw_vcp.c:mtk_vcodec_vcp_msg_process_thread() {
    ...
    mtk_vcodec_vcp_ipi_lock(fw->vcp, obj->id);
    handler = fw->vcp->ipi_desc[obj->id].handler;
    ...
    handler(msg, obj->len, fw->vcp->ipi_desc[obj->id].priv);
    ...
}

The obj->id value comes from the firmware IPC message payload. If this value
exceeds the VCP_IPI_MAX bound, it looks like it could directly index outside
the ipi_desc array, fetching an unvalidated function pointer and immediately
executing it. Should we add a bounds check for obj->id?


[Severity: High]
Are standard negative error codes truncated in this structure?

drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.h:struct mtk_vcp {
    ...
    bool ipi_id_ack[VCP_IPI_MAX];
    ...
}

Because ipi_id_ack is declared as a boolean array, assigning negative error
codes to it will truncate them to 1 (true).

Additionally, it seems the flag is never reset to false on success:

mtk_vcodec_fw_vcp.c:mtk_vcodec_vcp_msg_ipi_send() {
    ...
    return vcp->ipi_id_ack[id];
}

If a single error or timeout sets this flag to true, won't all subsequent
successful IPC sends falsely report failure because they read the stale true
state?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260603084045.17488-1-kyrie.wu@mediatek.com?part=11

  reply	other threads:[~2026-06-03  9:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  8:40 [PATCH v5 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-06-03  8:40 ` [PATCH v5 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-06-03  8:40 ` [PATCH v5 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-06-03  8:58   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-06-03 11:01   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-06-03  8:40 ` [PATCH v5 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-06-03  8:59   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 06/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-06-03  8:51   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 07/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-06-03  8:52   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 08/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-06-03  8:40 ` [PATCH v5 09/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-06-03  8:40 ` [PATCH v5 10/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-06-03 11:09   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 11/14] dt-bindings: media: mediatek: vcodec: add decoder dt-bindings for mt8196 Kyrie Wu
2026-06-03  9:03   ` sashiko-bot [this message]
2026-06-03 16:14   ` Conor Dooley
2026-06-03  8:40 ` [PATCH v5 12/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-06-03  8:59   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-06-03  9:07   ` sashiko-bot
2026-06-03  8:40 ` [PATCH v5 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
2026-06-03  9:10   ` sashiko-bot

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=20260603090329.7C4B21F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kyrie.wu@mediatek.com \
    --cc=linux-media@vger.kernel.org \
    --cc=robh@kernel.org \
    --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