public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: Jeongjun Park <aha310510@gmail.com>
Cc: Johannes Berg <johannes.berg@intel.com>,
	Kalle Valo <kvalo@kernel.org>,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+5de83f57cd8531f55596@syzkaller.appspotmail.com,
	syzkaller-bugs@googlegroups.com, stable@vger.kernel.org
Subject: Re: [PATCH] wifi: rsi: fix kthread lifetime race between self-exit and external-stop
Date: Thu, 23 Apr 2026 12:14:58 +0800	[thread overview]
Message-ID: <20260423041500.2020-1-hdanton@sina.com> (raw)
In-Reply-To: <20260422173846.37640-1-aha310510@gmail.com>

On Thu, 23 Apr 2026 02:38:46 +0900 Jeongjun Park wrote:
> RSI driver use both self-exit(kthread_complete_and_exit) and external-stop
> (kthread_stop) when killing a kthread. Generally, kthread_stop() is called
> first, and in this case, no particular issues occur.
> 
> However, in rare instances where kthread_complete_and_exit() is called
> first and then kthread_stop() is called, a UAF occurs because the kthread
> object, which has already exited and been freed, is accessed again.
> 
Alternatively the race could be described with the regular diagram to better
understand the uaf.

	rsi_kill_thread()	rsi_tx_scheduler_thread()
	---			---
	atomic_inc(&handle->thread_done); // set the done flag
 	rsi_set_event(&handle->event);

				do {
					something;
				} while (atomic_read(&common->tx_thread.thread_done) == 0);
				// exit after done
				kthread_complete_and_exit(&common->tx_thread.completion, 0);

	kthread_stop(handle->task); // uaf

> Therefore, to prevent this with minimal modification, you must remove
> kthread_stop() and change the code to wait until the self-exit operation
> is completed.
> 
> Cc: <stable@vger.kernel.org>
> Reported-by: syzbot+5de83f57cd8531f55596@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/69e5d03b.a00a0220.1bd0ca.0064.GAE@google.com/
> Fixes: 4c62764d0fc2 ("rsi: improve kernel thread handling to fix kernel panic")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> ---
>  drivers/net/wireless/rsi/rsi_common.h | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/wireless/rsi/rsi_common.h b/drivers/net/wireless/rsi/rsi_common.h
> index 591602beeec6..3cdf9ded876d 100644
> --- a/drivers/net/wireless/rsi/rsi_common.h
> +++ b/drivers/net/wireless/rsi/rsi_common.h
> @@ -70,12 +70,11 @@ static inline int rsi_create_kthread(struct rsi_common *common,
>  	return 0;
>  }
>  
> -static inline int rsi_kill_thread(struct rsi_thread *handle)
> +static inline void rsi_kill_thread(struct rsi_thread *handle)
>  {
>  	atomic_inc(&handle->thread_done);
>  	rsi_set_event(&handle->event);
> -
> -	return kthread_stop(handle->task);
> +	wait_for_completion(&handle->completion);
>  }
>  
>  void rsi_mac80211_detach(struct rsi_hw *hw);
> --
> 

      reply	other threads:[~2026-04-23  4:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 17:38 [PATCH] wifi: rsi: fix kthread lifetime race between self-exit and external-stop Jeongjun Park
2026-04-23  4:14 ` Hillf Danton [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=20260423041500.2020-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=aha310510@gmail.com \
    --cc=johannes.berg@intel.com \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+5de83f57cd8531f55596@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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