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 v16 11/12] media: mediatek: jpeg: add jpeg compatible
Date: Mon, 20 Jul 2026 14:23:14 +0000 [thread overview]
Message-ID: <20260720142315.0D17E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720133432.1042046-12-kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing bounds check on the number of DT child nodes causes out-of-bounds array accesses and stack overflows.
- [High] Incorrect calculation of the 34-bit extension address for the encoder's stall address.
--
--- Patch [11]: [PATCH v16 11/12] media: mediatek: jpeg: add jpeg compatible ---
Note: The format of this report has been altered to provide a free-form
summary without quoting the original patch code, due to recitation
restrictions.
commit f9b0fac0a51678a6983018a9ca39e5cce2cb6604
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: add jpeg compatible
This commit adds JPEG encoder and decoder compatibles for the mt8196
platform. It sets up the variant data structures with appropriate
capabilities like multi-core and 34-bit support.
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the new
compatibles, I noticed a potential stack overflow in the core driver.
In drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c:mtk_jpeg_probe(),
the code iterates over the device tree child nodes and sets
jpeg->max_hw_count to the total number of children, without capping it.
Later, in mtk_jpegenc_worker() and mtk_jpegdec_worker(), this unbounded
jpeg->max_hw_count is used as a loop limit to copy elements into the
comp_jpeg array, which is a fixed-size stack array. Additionally, in
mtk_jpegenc_hw_probe(), the hw_index is incremented and used without
bounds checking to store hardware instances into master_dev->enc_hw_dev.
Could a malformed device tree with more child nodes than the hardware limit
cause a stack buffer overflow or out-of-bounds write here? Should we add
bounds checking against MTK_JPEGENC_HW_MAX and MTK_JPEGDEC_HW_MAX?
[Severity: High]
This isn't a bug introduced by this patch, but adding support_34bit = true
for mt8196_jpegenc_drvdata exposes an existing issue in the encoder address
calculation.
In drivers/media/platform/mediatek/jpeg/mtk_jpeg_enc_hw.c at
mtk_jpeg_set_enc_dst(), when 34-bit support is enabled, the code calculates
the extended address using FIELD_PREP on the upper 32 bits of dma_addr.
It then writes the sum of this extended address and the buffer size to the
JPEG_ENC_STALL_ADDR0_EXT register. Because the extended address is a masked
bitfield representing the upper 32 bits, adding the raw byte length size
directly to this bitfield seems incorrect.
Could this result in writing an invalid, unmasked address extension to the
hardware registers, potentially leading to SMMU faults or memory corruption?
Should this instead calculate the upper 32 bits of the sum of dma_addr
and size?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720133432.1042046-1-kyrie.wu@mediatek.com?part=11
next prev parent reply other threads:[~2026-07-20 14:23 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 [this message]
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
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=20260720142315.0D17E1F000E9@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.