From nobody Mon Jun 8 16:31:17 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.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 E18891A680F; Thu, 28 May 2026 05:56:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779947776; cv=none; b=dl+1uvjzm9/G6QyhnBPYdWz+I3dzc24v1mOVLmTICNVHOJl75F2IomCO41zHDs/paWJcE8J3uhZxnD39wNoUxtpLEiI4Q8OSbXIqcetr3TBND2oXODVqp080CHLV6PKQQa2cPk7nHSxWZLcqUKK1p16aEeUyJCoAzqBjeeW4/+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779947776; c=relaxed/simple; bh=3Pz2/POEIG27/OLincfenN/OFgbzNrurtHLqmbuPSbk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=tcGutWqCAMGbLhthEW1OiYvuJD/RBFgLnrAaLWX49dCzUmAEV9hSMQ+e0RgC7wSzkV0cqntuYkNhf1PLZ5CJ4Zjxy+ylGOpDPUe7eF9kFzC36fg9vh496ElfkacPsx+U7xkLFRmJI9jUTH/ocsbvruMGuK0wHrbArjDON9buWe4= 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=lhfVqYVS; arc=none smtp.client-ip=117.135.210.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="lhfVqYVS" 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=2znY/CshLD06l5CCn5YAkQ481WGsnDnDH3u8+6xLglw=; b=lhfVqYVS1W9k7/ADAZjvNjvCPFZNIDWjZavbtACp6V5AhKigIowywXfnAw7yhu AR2OxMgpMyHXNwkLjqeIjHBYZVpYDtbw1/DncridyMnabzjAJTlrv7Lxwtdi2Rjg KHr1NdHwvjvsohmA+ko3gnK+ninwEBUxPgoBZowvRzOag= Received: from pek-lpg-core5.wrs.com (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wBHgqCX2BdqeNomAA--.4959S2; Thu, 28 May 2026 13:54:32 +0800 (CST) From: Robert Garcia To: stable@vger.kernel.org, Duoming Zhou Cc: Johannes Berg , Arend van Spriel , Franky Lin , Hante Meuleman , Chi-hsien Lin , Wright Feng , Chung-hsien Hsu , Kalle Valo , "David S . Miller" , Jakub Kicinski , Piotr Haber , "John W . Linville" , Pieter-Paul Giesberts , Robert Garcia , 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 5.15.y] wifi: brcmfmac: fix use-after-free when rescheduling brcmf_btcoex_info work Date: Thu, 28 May 2026 13:54:31 +0800 Message-Id: <20260528055431.4124445-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: _____wBHgqCX2BdqeNomAA--.4959S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxJw1ktFWrCr4fKF4DKw43Awb_yoWrJryfpa y3G34ayry0qrWakrWkJr1kZFy5KanrG3Wqyr48AF43uFsIqF1xGFW0yF12gFW7CFW09ay2 yF4Fqry3Jrs8tFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pNii6bUUUUU= X-CM-SenderInfo: 5uresw5dufxti6rwjhhfrp/xtbC5Ri8KGoX2JhQigAA3O 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 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