From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Shengzhuo Wei <me@cherr.cc>,
Mirela Rabulea <mirela.rabulea@nxp.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Hans Verkuil <hverkuil@kernel.org>, Ming Qian <ming.qian@nxp.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Bin Liu <bin.liu@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
irui wang <irui.wang@mediatek.com>,
kyrie wu <kyrie.wu@mediatek.com>
Cc: imx@lists.linux.dev, linux-media@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, stable@vger.kernel.org
Subject: Re: [PATCH 3/3] media: mediatek: jpeg: cancel job timeout work before m2m release
Date: Thu, 19 Nov 2026 13:35:18 -0500 [thread overview]
Message-ID: <e323dfe8a9b848833332599d6d5df6d302b5fd20.camel@collabora.com> (raw)
In-Reply-To: <20260825-media-timeout-work-v1-3-ebfebbeb6c31@cherr.cc>
[-- Attachment #1: Type: text/plain, Size: 2065 bytes --]
Hi,
Le mardi 25 août 2026 à 03:34 +0800, Shengzhuo Wei a écrit :
> Each job arms jpeg->job_timeout_work, cancelled only by the IRQ
> completion path. If a job stalls, mtk_jpeg_remove() frees
> jpeg->m2m_dev via v4l2_m2m_release() with the timeout still pending,
> and mtk_jpeg_job_timeout_work() then dereferences the freed m2m_dev
> and the stale ctx it returns -- a use-after-free.
>
> Drain the work before the m2m device is released. The device-level
> job_timeout_work was missed by the earlier fix for ctx->jpeg_work.
>
> Fixes: 5fb1c2361e56 ("mtk-jpegenc: add jpeg encode worker interface")
> Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shengzhuo Wei <me@cherr.cc>
> Assisted-by: GLM:5.3
> ---
> drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index d147ec48308110ae8520662e182dc0445447d8d0..f0fe14e83d515f5011cbfe051abbf565568013d0 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> @@ -1405,6 +1405,7 @@ static void mtk_jpeg_remove(struct platform_device *pdev)
>
> pm_runtime_disable(&pdev->dev);
> video_unregister_device(jpeg->vdev);
> + cancel_delayed_work_sync(&jpeg->job_timeout_work);
A similar fix was made by Fan We, instead of doing it in remove, it actually
sync on the delayed work in stop streaming:
https://lore.kernel.org/lkml/20260623103031.3051-1-fanwu01@zju.edu.cn/
This way, whatever gets added in the timeout later won't possibly outlive the
instance. Might be just extra cautious for this specific driver, but I'd rather
fix it once, then having this fixed again later.
In some ways, your Sashiko review tends to verbosely lean toward this.
Nicolas
> v4l2_m2m_release(jpeg->m2m_dev);
> v4l2_device_unregister(&jpeg->v4l2_dev);
> }
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
prev parent reply other threads:[~2026-11-19 18:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 19:34 [PATCH 0/3] media: cancel timeout delayed work before freeing its owner Shengzhuo Wei
2026-08-24 19:34 ` [PATCH 1/3] media: nxp: imx-jpeg: cancel task_timer before freeing ctx Shengzhuo Wei
2026-08-25 1:56 ` Ming Qian(OSS)
2026-08-25 3:39 ` Shengzhuo Wei
2026-08-24 19:34 ` [PATCH 2/3] media: verisilicon: hantro: cancel watchdog work before m2m release Shengzhuo Wei
2026-09-14 19:35 ` Frank Li
2026-11-19 18:36 ` Nicolas Dufresne
2026-08-24 19:34 ` [PATCH 3/3] media: mediatek: jpeg: cancel job timeout " Shengzhuo Wei
2026-11-19 18:35 ` Nicolas Dufresne [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=e323dfe8a9b848833332599d6d5df6d302b5fd20.camel@collabora.com \
--to=nicolas.dufresne@collabora.com \
--cc=Frank.Li@nxp.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=benjamin.gaignard@collabora.com \
--cc=bin.liu@mediatek.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=festevam@gmail.com \
--cc=hverkuil@kernel.org \
--cc=imx@lists.linux.dev \
--cc=irui.wang@mediatek.com \
--cc=kernel@pengutronix.de \
--cc=kyrie.wu@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-media@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=mchehab@kernel.org \
--cc=me@cherr.cc \
--cc=ming.qian@nxp.com \
--cc=mirela.rabulea@nxp.com \
--cc=p.zabel@pengutronix.de \
--cc=s.hauer@pengutronix.de \
--cc=stable@vger.kernel.org \
/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