mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Yaohan Li <shunsheng1218@gmail.com>, mchehab@kernel.org
Cc: hverkuil+cisco@kernel.org, Frank.Li@nxp.com,
	ming.qian@oss.nxp.com,  dmantipov@yandex.ru, 121811682@qq.com,
	ezequiel@vanguardiasur.com.ar,  linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: v4l2-mem2mem: cancel job work before freeing m2m_dev
Date: Wed, 04 Nov 2026 08:39:46 -0500	[thread overview]
Message-ID: <35f68881d65e0bb60cb4c6f25c027164f09b926f.camel@collabora.com> (raw)
In-Reply-To: <179378585020.73536.6089775766038265997@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1780 bytes --]

Hi,

Le mercredi 04 novembre 2026 à 17:50 +0800, Yaohan Li a écrit :
> v4l2_m2m_release() frees the mem2mem device without draining its
> embedded job_work. A job completion can queue the work while device
> removal runs, leaving the worker to access a freed m2m_dev.
> 
> Cancel and wait for job_work before freeing the device. This ensures
> that a previously queued or running job worker has completed before
> the memory backing it is released.
> 
> The use-after-free was reproduced with an in-tree V4L2 test driver
> under KASAN during stream teardown and device unbind; the same
> injected scheduling sequence completed without the report after the
> change.
> 
> Fixes: cbd9463da1b12 ("media: v4l2-mem2mem: Avoid calling .device_run in v4l2_m2m_job_finish")
> Assisted-by: ZCode:GLM-4
> Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>


Please, check the mailing list before sending patches, there is a v2 of this
change already. Its as simple as adding this step to your prompt really.

Nicolas

> ---
>  drivers/media/v4l2-core/v4l2-mem2mem.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c
> index a65cbb124cfe0..c4756e7bb1fb2 100644
> --- a/drivers/media/v4l2-core/v4l2-mem2mem.c
> +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
> @@ -1207,6 +1207,12 @@ EXPORT_SYMBOL_GPL(v4l2_m2m_init);
>  
>  void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev)
>  {
> +	/*
> +	 * job_work is embedded in m2m_dev and is re-queued unconditionally
> +	 * whenever a job finishes; wait for it before freeing the device.
> +	 */
> +	cancel_work_sync(&m2m_dev->job_work);
> +
>  	kfree(m2m_dev);
>  }
>  EXPORT_SYMBOL_GPL(v4l2_m2m_release);

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

      reply	other threads:[~2026-11-04 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04  9:50 Yaohan Li
2026-11-04 13:39 ` 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=35f68881d65e0bb60cb4c6f25c027164f09b926f.camel@collabora.com \
    --to=nicolas.dufresne@collabora.com \
    --cc=121811682@qq.com \
    --cc=Frank.Li@nxp.com \
    --cc=dmantipov@yandex.ru \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=hverkuil+cisco@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ming.qian@oss.nxp.com \
    --cc=shunsheng1218@gmail.com \
    /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

all inboxes | Powered by JetHome®