From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v9 03/14] media: mediatek: vcodec: add driver to support vcp encoder
Date: Tue, 17 Nov 2026 03:53:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-218168@kernel.org> (raw)
In-Reply-To: <20261117032950.1425556-4-kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] media: mediatek: vcodec: UAF in IPI handlers after VCP IPC
timeout
--
commit e54823b0eef88187197f04023f2a3956ba3b46d7
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: vcodec: add driver to support vcp encoder
This commit extends the VCP firmware interface driver to support the video
encoder by handling the encoder feature ID, memory ID, mailbox ID, and IPI
message queue thread.
> 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 3b85ae0e632a8..5ec7a67b51b67 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);
> while (!vcp_device->ops->vcp_is_ready(vcp_device, feature_id)) {
[Severity: High]
Can a timeout or signal interruption in mtk_vcodec_vcp_msg_ipi_send() lead
to a use-after-free in vpu_enc_ipi_handler() and vpu_dec_ipi_handler()?
mtk_vcodec_vcp_msg_ipi_send() ignores its wait argument (2000 ms) and waits
with wait_event_interruptible_timeout() for 100 ms (IPI_TIMEOUT_MS), which
includes both VCP firmware response time and scheduling delay for
mtk_vcodec_vcp_msg_process_thread(). If a DEINIT IPI times out or is
interrupted by a signal during device close, h264_enc_deinit()
unconditionally frees inst (and fops_vcodec_release() frees ctx) while the
ACK is still in flight or queued:
drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c:h264_enc_deinit() {
...
ret = vpu_enc_deinit(&inst->vpu_inst);
if (inst->work_buf_allocated)
h264_enc_free_work_buf(inst);
kfree(inst);
...
}
drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c:vpu_enc_ipi_handler() {
...
mtk_venc_debug(vpu->ctx, "msg_id %x inst %p status %d", msg->msg_id, vpu, msg->status);
if (!vpu_enc_check_ap_inst(enc_dev, vpu) || msg->msg_id < VPU_IPIMSG_ENC_INIT_DONE ||
msg->msg_id > VPU_IPIMSG_ENC_DEINIT_DONE) {
mtk_v4l2_venc_err(vpu->ctx, "venc msg id not correctly => 0x%x", msg->msg_id);
vpu->failure = -EINVAL;
goto error;
}
...
error:
vpu->signaled = 1;
}
CPU0 vcp_enc_msq_thread
fops_vcodec_release()
...
h264_enc_deinit()
vpu_enc_deinit(&inst->vpu_inst)
mtk_vcodec_vcp_msg_ipi_send()
wait_event_interruptible_timeout()
/* times out or -ERESTARTSYS */
kfree(inst)
kfree(ctx)
mtk_vcodec_vcp_msg_process_thread()
vpu_enc_ipi_handler()
mtk_venc_debug(vpu->ctx, ...)
vpu_enc_check_ap_inst() /* false */
mtk_v4l2_venc_err(vpu->ctx, ...)
vpu->failure = -EINVAL;
vpu->signaled = 1; <-- use-after-free
When the delayed ACK is processed, vpu_enc_ipi_handler() dereferences
vpu->ctx before calling vpu_enc_check_ap_inst(), and both
vpu_enc_ipi_handler() and vpu_dec_ipi_handler() still dereference vpu->ctx
and write to vpu->failure and vpu->signaled after the instance check fails.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117032950.1425556-1-kyrie.wu@mediatek.com?part=3
next prev parent reply other threads:[~2026-11-17 3:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 3:29 [PATCH v9 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-11-17 3:55 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-11-17 3:53 ` sashiko-bot [this message]
2026-11-17 3:29 ` [PATCH v9 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-11-17 3:53 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-11-17 3:58 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 06/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 07/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 08/14] media: dt-bindings: mediatek,vcodec-subdev-decoder: Add MT8196 Kyrie Wu
2026-11-17 3:39 ` sashiko-bot
2026-11-17 3:29 ` [PATCH v9 09/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 10/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 11/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 12/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-11-17 3:29 ` [PATCH v9 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
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-218168@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