Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: media-ci@linuxtv.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v6 05/14] media: mediatek: vcodec: get share memory address
Date: Mon, 20 Jul 2026 01:40:43 +0000	[thread overview]
Message-ID: <20260720014044.0B1BA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720012056.1026551-6-kyrie.wu@mediatek.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [High] mtk_vcodec_fw_map_dm_addr() has inconsistent error semantics across firmware types, leading to NULL or ERR_PTR dereferences.
- [High] mtk_vcodec_vcp_dm_addr() calculates shared memory offsets blindly without verifying they fit within the allocated firmware memory (vsi_size).

Pre-existing issues:
- [High] Firmware-provided sizes vsi->cdf_table_size and vsi->iq_table_size are used for memory allocation and memcpy without validation.
--

--- Patch [5]: [PATCH v6 05/14] media: mediatek: vcodec: get share memory address ---
commit 4c9f9286cbe2e7417003bc83c03e8482665fcca4
Author: Kyrie Wu <kyrie.wu@mediatek.com>

media: mediatek: vcodec: get share memory address

This commit adds support to get shared memory addresses for the VCP
architecture by dividing a single shared memory block into different
functions.

> 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
> --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c
[ ... ]
> @@ -483,8 +483,31 @@ static unsigned int mtk_vcodec_vcp_get_vdec_capa(struct mtk_vcodec_fw *fw)
>  	       MTK_VDEC_IS_SUPPORT_10BIT | MTK_VDEC_IS_SUPPORT_EXT;
>  }
>  
> -static void *mtk_vcodec_vcp_dm_addr(struct mtk_vcodec_fw *fw, u32 dtcm_dmem_addr)
> +static unsigned int mtk_vcodec_vcp_get_venc_capa(struct mtk_vcodec_fw *fw)
>  {
> +	return 0;
> +}
> +
> +static void *mtk_vcodec_vcp_dm_addr(struct mtk_vcodec_fw *fw, u32 mem_type)
> +{
> +	unsigned char *vsi_core = fw->vcp->vsi_core_addr;
> +
> +	switch (mem_type) {
> +	case ENCODER_MEM:
> +	case VCODEC_LAT_MEM:
> +		return fw->vcp->vsi_addr;
> +	case VCODEC_CORE_MEM:
> +		return vsi_core;
> +	case VP9_FRAME_MEM:
> +		return vsi_core + VCODEC_VSI_LEN;
> +	case AV1_CDF_MEM:
> +		return vsi_core + VCODEC_VSI_LEN + VP9_FRAME_SIZE;
> +	case AV1_IQ_MEM:
> +		return vsi_core + VCODEC_VSI_LEN + VP9_FRAME_SIZE + AV1_CDF_SIZE;

[Severity: High]
Are these offsets guaranteed to fit within the memory provided by the
hardware?

When fw->vcp->vsi_size is initialized via get_mem_size() in
mtk_vcodec_vcp_load_firmware(), the driver doesn't seem to validate that
the allocated block is large enough to contain these offsets. If a
malformed device tree or mismatched firmware provides a smaller memory
block, could this lead to out-of-bounds accesses into adjacent memory?

> +	default:
> +		break;
> +	}
> +
> +	return NULL;
> +}

[Severity: High]
Is returning NULL here safe when other firmware types return an ERR_PTR?

In drivers like vpu and scp, mapping functions return ERR_PTR(-EINVAL)
on failure. Because this VCP function returns NULL instead, callers have
mixed expectations.

For example, in vdec_av1_slice_init_cdf_table(), the code checks:

        remote_cdf_table = mtk_vcodec_fw_map_dm_addr(...);
        if (IS_ERR(remote_cdf_table)) {
                ...
        }

If VCP mapping fails and returns NULL, it passes the IS_ERR() check and
can cause a NULL pointer dereference during the subsequent memcpy().

> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
> --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_if.c
[ ... ]
> @@ -775,7 +784,7 @@ static int vdec_av1_slice_init_cdf_table(struct vdec_av1_slice_instance *instanc
>  	ctx = instance->ctx;
>  	vsi = instance->vpu.vsi;
>  	remote_cdf_table = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
> -						     (u32)vsi->cdf_table_addr);
> +						     vdec_av1_get_cdf_table_addr(ctx, vsi));
>  	if (IS_ERR(remote_cdf_table)) {
>  		mtk_vdec_err(ctx, "failed to map cdf table\n");
>  		return PTR_ERR(remote_cdf_table);

[Severity: High]
This is a pre-existing issue, but does vsi->cdf_table_size need to be
validated against the maximum allowed size before it is used?

Shortly after this mapping, the code does:

        memcpy(instance->cdf_table.va, remote_cdf_table, vsi->cdf_table_size);

Since vsi->cdf_table_size is provided by the firmware via shared memory, a
compromised or malformed firmware could provide a size larger than the
AV1_CDF_SIZE (0xFE80) memory region. Could this result in an out-of-bounds
read of adjacent kernel memory?

> diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
> --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c
[ ... ]
> @@ -514,7 +523,7 @@ static int vdec_vp9_slice_init_default_frame_ctx(struct vdec_vp9_slice_instance
>  		return -EINVAL;
>  
>  	remote_frame_ctx = mtk_vcodec_fw_map_dm_addr(ctx->dev->fw_handler,
> -						     (u32)vsi->default_frame_ctx);
> +						     vdec_vp9_get_frame_ctx_addr(ctx, vsi));
>  	if (!remote_frame_ctx) {
>  		mtk_vdec_err(ctx, "failed to map default frame ctx\n");
>  		return -EINVAL;

[Severity: High]
Does this !remote_frame_ctx check properly handle the ERR_PTR(-EINVAL) that
can be returned by mtk_vcodec_fw_map_dm_addr() when using VPU or SCP?

Since the VPU and SCP mapping paths return an ERR_PTR on failure, this check
will bypass them, resulting in kmemdup() attempting to dereference the
error pointer:

vdec_vp9_slice_init_default_frame_ctx() {
    ...
    if (!remote_frame_ctx) {
        return -EINVAL;
    }
    ...
    frame_ctx = kmemdup(remote_frame_ctx, sizeof(*frame_ctx), GFP_KERNEL);
}

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

  reply	other threads:[~2026-07-20  1:40 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20  1:20 [PATCH v6 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-07-20  1:20 ` [PATCH v6 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-07-20  1:36   ` sashiko-bot
2026-07-20 12:57   ` Nicolas Dufresne
2026-07-20  1:20 ` [PATCH v6 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-07-20  1:36   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-07-20  1:45   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-07-20  1:44   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-07-20  1:40   ` sashiko-bot [this message]
2026-07-20  1:20 ` [PATCH v6 06/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-07-20  1:31   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 07/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-07-20  1:32   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 08/14] dt-bindings: media: mediatek: vcodec: add decoder dt-bindings for mt8196 Kyrie Wu
2026-07-20  1:29   ` sashiko-bot
2026-07-20  5:46   ` Krzysztof Kozlowski
2026-07-20  5:49     ` Krzysztof Kozlowski
2026-07-20  6:26       ` Kyrie Wu (吴晗)
2026-07-20 10:19         ` Krzysztof Kozlowski
2026-07-20  1:20 ` [PATCH v6 09/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-07-20  1:36   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 10/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-07-20  1:20 ` [PATCH v6 11/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-07-20  1:20 ` [PATCH v6 12/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-07-20  2:03   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-07-20  1:48   ` sashiko-bot
2026-07-20  1:20 ` [PATCH v6 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
2026-07-20  1:50   ` 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=20260720014044.0B1BA1F000E9@smtp.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