From nobody Tue Apr 7 18:36:35 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 4F8B5382281; Thu, 12 Mar 2026 03:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773285350; cv=none; b=TYpGtZrk4zoyFiMB/7oNpSCvG2NO/wpwnrld8bCQcWMifjWsOVJCn0PErOFOtbtxLBbVTRuVaE324mMm1/sOckFsgqpGniKF1hrRARrtMcOg4vPInMS2WmZuJ6uE3XeMVvBbrPVPqk4gDfbae0I6jYgOhlGEY3ieJYGbUqeCxgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773285350; c=relaxed/simple; bh=u2XwoLw3K6BtfFJbj/jPwjHUyfbW988SPIr5ioOxFkQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=NE4IipG77034zTmx4UXJmAWvTsv6ObiaMvE+xYUVpDnXHn9Yjazmxv94vSBvE92HTFCEZfIoH3U2PKdEtNAimIWZ0zUE5scK/3QOovoonYnacm7n64VgGWyMrHyM3BJb+ojIEphvgfrHfQxEas4loxjnW7Xkz/BJX3D8pJ9yQco= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Ukcq+I1D; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Ukcq+I1D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version: Content-Type; bh=/jTMC+2KJ2b94GuPAkaqYinINPkXiSH82g4rhnWCGSQ=; b=Ukcq+I1DqHQ4Nv4XMYOPfjlpgW4nA/wT7EsTucOkyOpN3uk28lanqTtx8c8ObD axtPwT50UNK8YqspnlEEsuEZzHryEVUk/W08CF2h7TJKUSWjcGZrlS2592rmFm+Y 4mDmbG2XR+SMOJBO2BySzvmbBYUV6h/ye9ua4igUcHsRc= Received: from pek-lpg-core5.wrs.com (unknown []) by gzga-smtp-mtada-g1-1 (Coremail) with SMTP id _____wD3N36VL7Jpip3uAQ--.10515S2; Thu, 12 Mar 2026 11:14:32 +0800 (CST) From: Robert Garcia To: stable@vger.kernel.org, Duoming Zhou Cc: Johannes Berg , Robert Garcia , Arend van Spriel , Kalle Valo , Franky Lin , Hante Meuleman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Pieter-Paul Giesberts , Piotr Haber , "John W . Linville" , linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6.1.y] wifi: brcmfmac: fix use-after-free when rescheduling brcmf_btcoex_info work Date: Thu, 12 Mar 2026 11:14:29 +0800 Message-Id: <20260312031429.3432419-1-rob_garcia@163.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3N36VL7Jpip3uAQ--.10515S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw1ktFWrCr4fKF4DKw43Awb_yoWrJw17pa y3G34ayry0qrWakrWkJr1kZFy5KanrG3Wqyr48CF43uFsIqF1xJFW0yF12gFW7CFW09ay2 yF4Fqry3Jrs8tFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UI-ewUUUUU= X-CM-SenderInfo: 5uresw5dufxti6rwjhhfrp/xtbDAhn4ZGmyL5nOVAAA3w From: Duoming Zhou [ Upstream commit 9cb83d4be0b9b697eae93d321e0da999f9cdfcfc ] The brcmf_btcoex_detach() only shuts down the btcoex timer, if the flag timer_on is false. However, the brcmf_btcoex_timerfunc(), which runs as timer handler, sets timer_on to false. This creates critical race conditions: 1.If brcmf_btcoex_detach() is called while brcmf_btcoex_timerfunc() is executing, it may observe timer_on as false and skip the call to timer_shutdown_sync(). 2.The brcmf_btcoex_timerfunc() may then reschedule the brcmf_btcoex_info worker after the cancel_work_sync() has been executed, resulting in use-after-free bugs. The use-after-free bugs occur in two distinct scenarios, depending on the timing of when the brcmf_btcoex_info struct is freed relative to the execution of its worker thread. Scenario 1: Freed before the worker is scheduled The brcmf_btcoex_info is deallocated before the worker is scheduled. A race condition can occur when schedule_work(&bt_local->work) is called after the target memory has been freed. The sequence of events is detailed below: CPU0 | CPU1 brcmf_btcoex_detach | brcmf_btcoex_timerfunc | bt_local->timer_on =3D false; if (cfg->btcoex->timer_on) | ... | cancel_work_sync(); | ... | kfree(cfg->btcoex); // FREE | | schedule_work(&bt_local->work); // USE Scenario 2: Freed after the worker is scheduled The brcmf_btcoex_info is freed after the worker has been scheduled but before or during its execution. In this case, statements within the brcmf_btcoex_handler() =E2=80=94 such as the container_of macro and subsequent dereferences of the brcmf_btcoex_info object will cause a use-after-free access. The following timeline illustrates this scenario: CPU0 | CPU1 brcmf_btcoex_detach | brcmf_btcoex_timerfunc | bt_local->timer_on =3D false; if (cfg->btcoex->timer_on) | ... | cancel_work_sync(); | ... | schedule_work(); // Reschedule | kfree(cfg->btcoex); // FREE | brcmf_btcoex_handler() // Worker /* | btci =3D container_of(....); // USE The kfree() above could | ... also occur at any point | btci-> // USE during the worker's execution| */ | To resolve the race conditions, drop the conditional check and call timer_shutdown_sync() directly. It can deactivate the timer reliably, regardless of its current state. Once stopped, the timer_on state is then set to false. Fixes: 61730d4dfffc ("brcmfmac: support critical protocol API for DHCP") Acked-by: Arend van Spriel Signed-off-by: Duoming Zhou Link: https://patch.msgid.link/20250822050839.4413-1-duoming@zju.edu.cn Signed-off-by: Johannes Berg [ Keep del_timer_sync() instead of timer_shutdown_sync() here. ] Signed-off-by: Robert Garcia --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c b/dr= ivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c index f9f18ff451ea..f46e40900217 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c @@ -392,10 +392,8 @@ void brcmf_btcoex_detach(struct brcmf_cfg80211_info *c= fg) if (!cfg->btcoex) return; =20 - if (cfg->btcoex->timer_on) { - cfg->btcoex->timer_on =3D false; - del_timer_sync(&cfg->btcoex->timer); - } + del_timer_sync(&cfg->btcoex->timer); + cfg->btcoex->timer_on =3D false; =20 cancel_work_sync(&cfg->btcoex->work); =20 --=20 2.34.1