From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from r3-11.sinamail.sina.com.cn (r3-11.sinamail.sina.com.cn [202.108.3.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F4D833C188 for ; Thu, 23 Apr 2026 04:15:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.108.3.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917718; cv=none; b=i1XQrjXyyFqjDAyXK+hnSKAawgZr0qkaJvnKS2Ecn/P9oacTC0NnW57/5bSp8OODq/8C3XljrECvCzYtSypbi9NWPkjBSJEKBAlUuptBqegDXreTbnQPn6tuYu3n8J1uBNbOUTiVRrFDc1P6CFaKTW6z7PlxL4X3sdmNpDeWfs0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776917718; c=relaxed/simple; bh=Qz70XQWqkjFL1n7DMKpRt8RNanc3bCYxPXKEjrvC0wg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ejxwjhYyYnma+4sCLMO+3syC2wRr6Hv3dIrfFQhtnWpGFg0XDKHuXkxIkGxpIz+1BsNb8FrIC7PKi82DZvo09YBkyzN0HHBeZytrhVVzJAd4vJJbM6dipFQWAfl9+cz6nf8dip4NN/fUg5JrN++Xm260dk/GGktKalaMhs9dQs0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.com; spf=pass smtp.mailfrom=sina.com; dkim=pass (1024-bit key) header.d=sina.com header.i=@sina.com header.b=VRNwzgHX; arc=none smtp.client-ip=202.108.3.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sina.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=sina.com header.i=@sina.com header.b="VRNwzgHX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sina.com; s=201208; t=1776917713; bh=kXgg4bK6ZCKpzRg3Eg2FXeTLIzhmAY6ilX5qNb/Q9O0=; h=From:Subject:Date:Message-ID; b=VRNwzgHXlEaWhBj6wpwBrXVR7jx0VFnAPnmv8e8hkCCeOC5hWNuqfT0BzECxZ1ucM 5qBMC/+25bg4AanjGHqwzjXfxsi50JIJ4zPX7iyT59wOuF7wXtmIPBclePYbztzwKv xA8Y3G4IRBvuz9QIzw7xcFNnBrPKRkUb0x3BN2og= X-SMAIL-HELO: localhost.localdomain Received: from unknown (HELO localhost.localdomain)([114.249.62.144]) by sina.com (10.54.253.34) with ESMTP id 69E99CCB000034DA; Thu, 23 Apr 2026 12:15:09 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com Authentication-Results: sina.com; spf=none smtp.mailfrom=hdanton@sina.com; dkim=none header.i=none; dmarc=none action=none header.from=hdanton@sina.com X-SMAIL-MID: 553076291788 X-SMAIL-UIID: 3D56BE0CC2034011917CE9A522D806FC-20260423-121509-1 From: Hillf Danton To: Jeongjun Park Cc: Johannes Berg , Kalle Valo , 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 Message-ID: <20260423041500.2020-1-hdanton@sina.com> In-Reply-To: <20260422173846.37640-1-aha310510@gmail.com> References: Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: > 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 > --- > 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); > -- >