Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v8 03/14] media: mediatek: vcodec: add driver to support vcp encoder
Date: Sat, 10 Oct 2026 08:59:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-166385@kernel.org> (raw)
In-Reply-To: <c2a0025b6962f96d8d05de5970863ef6329baf0e.1791619743.git.kyrie.wu@mediatek.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] media: mtk_vcodec: encoder initialization fails due to unmapped IPI ID for VCP
- [High] media: mtk_vcodec: delayed ACK causes protocol desynchronization in VCP IPC
- [High] media: vcodec: vcp encoder fails to initialize due to out-of-bounds ipi_id
- [High] media: mediatek: vcodec: UAF in IPI message handlers on device close due to IPC timeout
--

commit c1db7dc6cad08382fb97ce9b64a0f609116bfae6
Author: Kyrie Wu <kyrie.wu@mediatek.com>

media: mediatek: vcodec: add driver to support vcp encoder

This commit adds encoder support for the VCP interface to allow communication
between the encoder and VCP hardware.

> diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> index 150d842c7d226..ece4e3e87e62d 100644
> --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c

[ ... ]

> @@ -223,8 +225,13 @@ static int mtk_vcodec_vcp_msg_ipi_send(struct mtk_vcodec_fw *fw, int id, void *b
>  	}
>  
>  	mutex_lock(&vcp->ipi_mutex);
> -	feature_id = VDEC_FEATURE_ID;
> -	mailbox_id = IPI_OUT_VDEC_1;
> +	if (fw->fw_use == ENCODER) {
> +		feature_id = VENC_FEATURE_ID;
> +		mailbox_id = IPI_OUT_VENC_0;
> +	} else {
> +		feature_id = VDEC_FEATURE_ID;
> +		mailbox_id = IPI_OUT_VDEC_1;
> +	}
>  
>  	timeout_jiffies = jiffies + msecs_to_jiffies(VCP_SYNC_TIMEOUT_MS);

[Severity: High]
Will this initialization succeed for encoders?

The encoder driver appears to initialize its ID to SCP_IPI_VENC_H264 (4)
or IPI_VENC_H264 (3), as seen in h264_enc_init():

    if (is_ext)
        inst->vpu_inst.id = SCP_IPI_VENC_H264;
    else
        inst->vpu_inst.id = IPI_VENC_H264;

However, earlier in mtk_vcodec_vcp_msg_ipi_send() and in 
mtk_vcodec_vcp_ipi_register(), the code checks mtk_vcodec_vcp_ipi_id_valid(),
which strictly requires the ID to be less than VCP_IPI_MAX.

Since VCP_IPI_MAX is 3, these encoder IDs will always fail the validation
check, returning -EINVAL and preventing the VCP encoder from communicating.


[Severity: High]
Could a delayed ACK from the firmware cause memory corruption or state
desynchronization?

When waiting for an ACK later in mtk_vcodec_vcp_msg_ipi_send(), the function
uses a hardcoded 100ms timeout and relies on a shared boolean:

wait_ack:
    ret = wait_event_interruptible_timeout(*msg_wq, *msg_signaled,
                                           msecs_to_jiffies(IPI_TIMEOUT_MS));

If the firmware takes longer than 100ms to reply, the wait times out
and returns an error. However, the firmware might still process the message
and send the ACK later.

This appears to lead to two potential issues:

1. If the timeout occurs during device teardown, such as when sending a
DEINIT message before closing the device, the driver proceeds to free
the instance via kfree(inst). When the delayed ACK eventually arrives,
the asynchronous message thread calls the IPI handler:

vpu_enc_ipi_handler()
    vpu = (struct venc_vpu_inst *)(unsigned long)msg->venc_inst;
    mtk_venc_debug(vpu->ctx, ...);

The handler extracts the freed instance from the message and dereferences
vpu->ctx, resulting in a use-after-free.

2. Because there are no sequence numbers matching ACKs to requests, a
delayed ACK could arrive during a subsequent message on the same ID.
The new message resets the shared flag and waits, but the delayed ACK
from the previous message would immediately wake it up prematurely,
desynchronizing the state between the driver and the firmware.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791619742.git.kyrie.wu@mediatek.com?part=3

  reply	other threads:[~2026-10-10  9:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10  8:35 [PATCH v8 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-10-10  8:36 ` [PATCH v8 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-10-10  8:36 ` [PATCH v8 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-10-10  8:53   ` sashiko-bot
2026-10-10  8:36 ` [PATCH v8 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-10-10  8:59   ` sashiko-bot [this message]
2026-10-10  8:36 ` [PATCH v8 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-10-10  8:56   ` sashiko-bot
2026-10-10  8:36 ` [PATCH v8 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-10-10  8:56   ` sashiko-bot
2026-10-10  8:36 ` [PATCH v8 06/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-10-10  8:48   ` sashiko-bot
2026-10-10  8:36 ` [PATCH v8 07/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-10-10  8:46   ` sashiko-bot
2026-10-10  8:36 ` [PATCH v8 08/14] dt-bindings: media: mediatek,vcodec-subdev-decoder: Add MT8196 Kyrie Wu
2026-10-10  8:36 ` [PATCH v8 09/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-10-10  8:36 ` [PATCH v8 10/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-10-10  8:36 ` [PATCH v8 11/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-10-10  8:36 ` [PATCH v8 12/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-10-10  8:50   ` sashiko-bot
2026-10-10  8:36 ` [PATCH v8 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-10-10  8:57   ` sashiko-bot
2026-10-10  8:36 ` [PATCH v8 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
2026-10-10  8:51   ` 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=sashiko-outbox-166385@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kyrie.wu@mediatek.com \
    --cc=media-ci@linuxtv.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