From: sashiko-bot@kernel.org
To: "Kazuki Hanai" <hnkz.64@gmail.com>
Cc: Frank.Li@kernel.org, media-ci@linuxtv.org, imx@lists.linux.dev
Subject: Re: [PATCH] media: imx-jpeg: Cancel timeout work on release
Date: Fri, 28 Aug 2026 05:35:44 +0000 [thread overview]
Message-ID: <20260828053545.0DC3F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828051452.1940559-1-hnkz.64@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent execution of `v4l2_m2m_ctx_release()` and `v4l2_m2m_job_finish()` causes a use-after-free of `m2m_ctx`.
- [High] Race condition in `mxc_jpeg_device_run_timeout()` causes a NULL pointer dereference if it executes after its context's job finishes and another context starts.
--
commit ba4456d4cd6b4b2046f0bf363757a56e4661b019
Author: Kazuki Hanai <hnkz.64@gmail.com>
media: imx-jpeg: Cancel timeout work on release
This commit adds a synchronous cancellation of the timeout work during
device release to prevent a use-after-free. It places the cancellation
after the mem2mem context release.
> diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> @@ -2805,6 +2805,7 @@ static int mxc_jpeg_release(struct file *file)
> ctx->slot);
> v4l2_ctrl_handler_free(&ctx->ctrl_handler);
> v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
> + cancel_delayed_work_sync(&ctx->task_timer);
[Severity: High]
This is a pre-existing issue, but does placing the sync cancel after
the mem2mem release still leave a use-after-free window?
If mxc_jpeg_release() calls v4l2_m2m_ctx_release(), it blocks in
v4l2_m2m_cancel_job() waiting for the hung hardware job to finish.
Concurrently, the timeout work mxc_jpeg_device_run_timeout() can
execute and call v4l2_m2m_job_finish(). Inside v4l2_m2m_job_finish(),
the job is marked finished and the wait queue is woken up, which
unblocks v4l2_m2m_ctx_release().
The release function then immediately frees m2m_ctx.
Meanwhile, v4l2_m2m_job_finish() continues on the timeout thread,
checks schedule_next, and calls v4l2_m2m_schedule_next_job(m2m_dev, m2m_ctx).
Will this access the newly freed m2m_ctx?
[Severity: High]
This is also a pre-existing issue, but since we are dealing with the
timeout work cancellation, is there a race condition in
mxc_jpeg_device_run_timeout() that can cause a NULL pointer dereference?
If a job for Context A finishes successfully, the IRQ handler
mxc_jpeg_dec_irq() calls cancel_delayed_work() (which is not synchronous).
If Context A's delayed work has already started executing but was preempted
before acquiring hw_lock, cancel_delayed_work() returns without stopping it.
The IRQ handler schedules the next job for Context B, which acquires hw_lock
and sets ctx->mxc_jpeg->slot_data.used = true.
Context A's timeout work then resumes, acquires hw_lock, and incorrectly
observes the globally shared slot_data.used as true. Assuming it timed out,
it calls mxc_jpeg_job_finish(ctxA, ...).
Since Context A has no active job, v4l2_m2m_next_src_buf() returns NULL.
When mxc_jpeg_job_finish() passes this NULL pointer to v4l2_m2m_buf_done(),
will it cause an unconditional dereference in vb2_buffer_done()?
> v4l2_fh_del(&ctx->fh, file);
> v4l2_fh_exit(&ctx->fh);
> kfree(ctx);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260828051452.1940559-1-hnkz.64@gmail.com?part=1
next prev parent reply other threads:[~2026-08-28 5:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 5:14 [PATCH] media: imx-jpeg: Cancel timeout work on release Kazuki Hanai
2026-08-28 5:35 ` sashiko-bot [this message]
2026-08-28 19:41 ` Frank Li
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=20260828053545.0DC3F1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=hnkz.64@gmail.com \
--cc=imx@lists.linux.dev \
--cc=media-ci@linuxtv.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