From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
media-ci@linuxtv.org
Subject: Re: [PATCH v16 12/12] media: mediatek: jpeg: add jpeg smmu sid setting
Date: Mon, 20 Jul 2026 14:19:05 +0000 [thread overview]
Message-ID: <20260720141905.8DC1B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720133432.1042046-13-kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Critical] Probe failure in SMMU initialization leaves dangling pointers in the global master device arrays and permanently increments hw_index, causing UAF and array OOB on deferred probes.
Pre-existing issues:
- [High] Blind dereference of HW arrays when child probes fail early.
--
--- Patch [12]: [PATCH v16 12/12] media: mediatek: jpeg: add jpeg smmu sid setting ---
commit 73b8529184733966196568926fff60cf629320ae
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: add jpeg smmu sid setting
Add a configuration to set jpeg dec & enc smmu sid
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index 8e96501a4f9fa..bb9bdd9913d94 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
[ ... ]
> @@ -1663,6 +1680,11 @@ static void mtk_jpegenc_worker(struct work_struct *work)
> jpeg_dst_buf->frame_num = ctx->total_frame_num;
> ctx->total_frame_num++;
> mtk_jpeg_enc_reset(comp_jpeg[hw_id]->reg_base);
> +
> + if (jpeg->variant->support_smmu && comp_jpeg[hw_id]->smmu_regmap)
> + mtk_jpeg_set_smmu_sid(comp_jpeg[hw_id]->smmu_regmap,
> + JPG_REG_GUSER_ID_ENC_SID);
> +
[Severity: High]
This isn't a bug introduced by this patch, but I have a question about how
unpopulated hardware array entries are handled when a child probe fails.
In mtk_jpegenc_worker(), it calls mtk_jpegenc_get_hw() to select the hw_id.
If an earlier probe failure left the array entry in enc_hw_dev as NULL, could
this result in a NULL pointer dereference?
mtk_jpegenc_get_hw() iterates based on max_hw_count (which is set from the
Device Tree child nodes) and accesses the state directly:
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:mtk_jpegenc_get_hw() {
...
for (i = 0; i < jpeg->max_hw_count; i++) {
comp_jpeg = jpeg->enc_hw_dev[i];
if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) {
...
}
Could this blindly dereference comp_jpeg if the child probe never completed
and left it NULL? The exact same pattern seems to exist in mtk_jpegdec_get_hw().
> mtk_jpeg_set_enc_dst(ctx,
> comp_jpeg[hw_id]->reg_base,
> &dst_buf->vb2_buf);
[ ... ]
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> index 07452249bcb67..3058fdf4f6054 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_dec_hw.c
[ ... ]
> @@ -665,6 +684,10 @@ static int mtk_jpegdec_hw_probe(struct platform_device *pdev)
> master_dev->reg_decbase[i] = dev->reg_base;
> dev->master_dev = master_dev;
>
> + ret = mtk_jpegdec_smmu_init(dev);
> + if (ret)
> + return ret;
> +
[Severity: Critical]
If mtk_jpegdec_smmu_init() fails and returns an error like -EPROBE_DEFER,
will this leave a dangling pointer in the master_dev->dec_hw_dev array?
Looking earlier in mtk_jpegdec_hw_probe(), dev is allocated with devm_kzalloc
and added to the master_dev array, and hw_index is incremented:
i = atomic_add_return(1, &master_dev->hw_index) - 1;
master_dev->dec_hw_dev[i] = dev;
master_dev->reg_decbase[i] = dev->reg_base;
dev->master_dev = master_dev;
ret = mtk_jpegdec_smmu_init(dev);
if (ret)
return ret;
When returning ret, the devm-managed dev will be freed, but the pointer
remains in master_dev->dec_hw_dev[i] and hw_index is never decremented.
Could this lead to an out-of-bounds write on deferred probe retries and a
use-after-free when the worker thread accesses the array?
This same issue seems to be present in mtk_jpegenc_hw_probe() in
mtk_jpeg_enc_hw.c as well.
> platform_set_drvdata(pdev, dev);
> pm_runtime_enable(&pdev->dev);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720133432.1042046-1-kyrie.wu@mediatek.com?part=12
prev parent reply other threads:[~2026-07-20 14:19 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 13:34 [PATCH v16 00/12] Enable jpeg enc & dec multi-hardwares for MT8196 Kyrie Wu
2026-07-20 13:34 ` [PATCH v16 01/12] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
2026-07-20 13:47 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 02/12] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
2026-07-20 13:52 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 03/12] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
2026-07-20 13:59 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 04/12] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
2026-07-20 14:19 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 05/12] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
2026-07-20 13:49 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 06/12] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
2026-07-20 14:05 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 07/12] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
2026-07-20 14:08 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 08/12] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
2026-07-20 14:13 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 09/12] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
2026-07-20 13:34 ` [PATCH v16 10/12] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
2026-07-20 14:16 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 11/12] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
2026-07-20 14:23 ` sashiko-bot
2026-07-20 13:34 ` [PATCH v16 12/12] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
2026-07-20 14:19 ` sashiko-bot [this message]
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=20260720141905.8DC1B1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.