From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: media-ci@linuxtv.org, robh@kernel.org, conor+dt@kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v18 06/13] media: mediatek: jpeg: fix buffer state update timing
Date: Sat, 10 Oct 2026 08:19:25 +0000 [thread overview]
Message-ID: <sashiko-outbox-166335@kernel.org> (raw)
In-Reply-To: <ce89b772dfbd5d86a3af4672dd40af41de8b6f98.1791614327.git.kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: Placebo lock and UAF in MTK JPEG worker timeout race
--
commit 8295f8055bf1ad5ac4c76dd2772ead51a8aecccb
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: jpeg: fix buffer state update timing
This commit delays the update of the destination buffer state until after the
decoder has selected a hardware core and successfully resumed its runtime PM
state. It aims to protect the destination buffer state update with the
hardware spinlock to avoid assigning frame tracking data to buffers that are
returned early.
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index a5a1f6126af73..e152ebae0f219 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
[ ... ]
> @@ -1773,6 +1767,9 @@ static void mtk_jpegdec_worker(struct work_struct *work)
> msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC));
>
> spin_lock_irqsave(&comp_jpeg[hw_id]->hw_lock, flags);
> + jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf);
> + jpeg_dst_buf->curr_ctx = ctx;
> + jpeg_dst_buf->frame_num = ctx->total_frame_num;
[Severity: High]
The commit message states the lock is used so the completion path observes a
consistent context and frame number. However, looking at the completion paths
in mtk_jpegdec_hw_irq_handler() and mtk_jpegdec_timeout_work(), they do not
appear to acquire comp_jpeg[hw_id]->hw_lock. Does this lock provide any
mutual exclusion against those paths?
Also, because schedule_delayed_work() arms the timeout before the buffer state
is initialized, is there a risk if the worker thread is preempted immediately
after arming the timer?
For example, could this sequence occur:
1. The timeout worker fires and executes without hw_lock.
2. It reads the uninitialized frame_num.
3. It adds the buffer to dst_done_queue, resets the hardware, and returns the
buffer to userspace via v4l2_m2m_buf_done().
4. The preempted worker thread resumes and concurrently writes to
jpeg_dst_buf->frame_num, corrupting the buffer that is already on the
completion list or in userspace.
5. It then starts the hardware via mtk_jpeg_dec_start() on the
already-returned buffer.
Could this lead to DMA into freed memory?
> ctx->total_frame_num++;
> mtk_jpeg_dec_reset(comp_jpeg[hw_id]->reg_base);
> mtk_jpeg_dec_set_config(comp_jpeg[hw_id]->reg_base,
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791614327.git.kyrie.wu@mediatek.com?part=6
next prev parent reply other threads:[~2026-10-10 8:19 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 8:07 [PATCH v18 00/13] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 01/13] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
2026-10-10 8:16 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 02/13] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 03/13] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 04/13] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
2026-10-10 8:17 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 05/13] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
2026-10-10 8:24 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 06/13] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
2026-10-10 8:19 ` sashiko-bot [this message]
2026-10-10 8:07 ` [PATCH v18 07/13] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
2026-10-10 8:24 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 08/13] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
2026-10-10 8:18 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 09/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 10/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
2026-10-10 8:18 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 11/13] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
2026-10-10 8:21 ` sashiko-bot
2026-10-10 8:07 ` [PATCH v18 12/13] dt-bindings: mediatek: Add MT8196 JPEG SMMU bindings Kyrie Wu
2026-10-10 8:07 ` [PATCH v18 13/13] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
2026-10-10 8:23 ` 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-166335@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