Linux Media Controller development
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil+cisco@kernel.org>
To: Sean Young <sean@mess.org>,
	linux-media@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Patrice Chotard <patrice.chotard@foss.st.com>
Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 11/15] media: rc: Use after free in ir_raw_event_handle()
Date: Tue, 28 Jul 2026 11:21:00 +0200	[thread overview]
Message-ID: <9b97f819-cfdb-4ca7-afae-74e66c854a27@kernel.org> (raw)
In-Reply-To: <3f498e032c1a5849dbb37eb016a82282ebc7fedf.1785158244.git.sean@mess.org>

On 27/07/2026 15:18, Sean Young wrote:
> If rc_unregister_device() is called while IR is being processed, then
> ir_raw_event_handle() could call wake_up_process(dev->raw->thread)
> after kthread_stop(dev->raw->thread).
> 
> Fixes: dccc0c3ddf8f ("media: rc: fix race between unregister and urb/irq callbacks")
> Signed-off-by: Sean Young <sean@mess.org>
> Cc: stable@vger.kernel.org
> ---
>  drivers/media/rc/rc-ir-raw.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
> index ba24c2f22d39..96849faafde3 100644
> --- a/drivers/media/rc/rc-ir-raw.c
> +++ b/drivers/media/rc/rc-ir-raw.c
> @@ -637,6 +637,7 @@ int ir_raw_event_register(struct rc_dev *dev)
>  	if (IS_ERR(thread))
>  		return PTR_ERR(thread);
>  
> +	get_task_struct(thread);
>  	dev->raw->thread = thread;
>  
>  	mutex_lock(&ir_raw_handler_lock);
> @@ -648,8 +649,13 @@ int ir_raw_event_register(struct rc_dev *dev)
>  
>  void ir_raw_event_free(struct rc_dev *dev)
>  {
> -	kfree(dev->raw);
> -	dev->raw = NULL;
> +	if (dev->raw) {
> +		timer_delete_sync(&dev->raw->edge_handle);
> +		if (dev->raw->thread)
> +			put_task_struct(dev->raw->thread);
> +		kfree(dev->raw);
> +		dev->raw = NULL;
> +	}
>  }
>  
>  void ir_raw_event_unregister(struct rc_dev *dev)

I think this patch could do with some comments in the code explaining why
you need get/put_task_struct.

It's the first time I've seen these functions being used, and I'm not sure
why they solve the issue or whether this is the right approach.

Regards,

	Hans

  reply	other threads:[~2026-07-28  9:21 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-27 13:18 [PATCH v4 00/15] Fix leaks in rc core Sean Young
2026-07-27 13:18 ` [PATCH v4 01/15] media: streamzap: Add missing rc_unregister_device() Sean Young
2026-07-27 13:18 ` [PATCH v4 02/15] media: redrat3: Ensure rc device is freed if enable_detector() fails Sean Young
2026-07-27 13:18 ` [PATCH v4 03/15] media: redrat3: Ensure we don't read beyond the end of the packet Sean Young
2026-07-27 13:18 ` [PATCH v4 04/15] media: redrat3: Ensure all urbs are suspended Sean Young
2026-07-27 13:18 ` [PATCH v4 05/15] media: redrat3: Error path leaves device in transmitting state Sean Young
2026-07-27 15:57   ` Markus Elfring
2026-07-28  8:13     ` Sean Young
2026-07-28  9:08       ` Markus Elfring
2026-07-27 13:18 ` [PATCH v4 06/15] media: sunxi-cir: Ensure no more interrupts can occur before free Sean Young
2026-07-27 13:18 ` [PATCH v4 07/15] media: meson-ir-tx: Ensure clock is disabled on unbind Sean Young
2026-07-27 13:18 ` [PATCH v4 08/15] media: meson-ir-tx: Ensure rc_free_device() is called " Sean Young
2026-07-28  8:30   ` Neil Armstrong
2026-07-27 13:18 ` [PATCH v4 09/15] media: meson-ir-tx: Ensure probe error is propagated Sean Young
2026-07-28  8:30   ` Neil Armstrong
2026-07-27 13:18 ` [PATCH v4 10/15] media: ir-hix5hd2: Ensure rdev is setup before interrupts are enabled Sean Young
2026-07-27 13:18 ` [PATCH v4 11/15] media: rc: Use after free in ir_raw_event_handle() Sean Young
2026-07-28  9:21   ` Hans Verkuil [this message]
2026-07-27 13:18 ` [PATCH v4 12/15] media: rc: Fix use after free in bpf progs Sean Young
2026-07-27 13:18 ` [PATCH v4 13/15] media: cx88: Specify rc type at rc_allocate_type() Sean Young
2026-07-27 13:18 ` [PATCH v4 14/15] media: saa7134: " Sean Young
2026-07-27 13:18 ` [PATCH v4 15/15] media: rc: Fix race condition during rc_register_device() Sean Young
2026-07-28  9:35   ` Hans Verkuil

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=9b97f819-cfdb-4ca7-afae-74e66c854a27@kernel.org \
    --to=hverkuil+cisco@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=patrice.chotard@foss.st.com \
    --cc=sean@mess.org \
    --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