From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: Arend van Spriel <arend.vanspriel@broadcom.com>
Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
stable@vger.kernel.org, Abdun Nihaal <nihaal@cse.iitm.ac.in>,
Benjamin Drung <benjamin.drung@canonical.com>,
Fan Wu <fanwu01@zju.edu.cn>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Matthias Brugger <mbrugger@suse.com>,
Runyu Xiao <runyu.xiao@seu.edu.cn>,
brcm80211-dev-list.pdl@broadcom.com, brcm80211@lists.linux.dev,
linux-wireless@vger.kernel.org
Subject: [PATCH wireless] wifi: brcmfmac: fix use-after-free of the watchdog task_struct
Date: Fri, 20 Nov 2026 18:42:27 +0100 [thread overview]
Message-ID: <20261120174231.2024897-1-dario.binacchi@amarulasolutions.com> (raw)
The watchdog thread exits as soon as it receives a SIGTERM, also from
userspace, e.g. when init kills all the processes at reboot. If the
driver is removed afterwards, the reference taken right before sending
the signal by commit c623b6358088 ("wifi: brcmfmac: Fix potential
use-after-free issue when stopping watchdog task") comes too late, and
kthread_stop() runs on a task_struct already freed.
WARNING: kernel/kthread.c:84 at kthread_stop+0xd8/0x190
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
Call trace:
kthread_stop+0x148/0x190 (P)
kthread_stop_put+0x14/0xb0
brcmf_sdio_remove+0x58/0x1d0
brcmf_sdiod_remove+0x20/0xa0
brcmf_ops_sdio_remove+0x5c/0x90
Take the reference before the thread is started and drop it with
kthread_stop_put() when it is stopped.
Fixes: c623b6358088 ("wifi: brcmfmac: Fix potential use-after-free issue when stopping watchdog task")
Cc: stable@vger.kernel.org
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
.../net/wireless/broadcom/brcm80211/brcmfmac/sdio.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
index cea52d408817..67b2291f8ee5 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
@@ -2478,7 +2478,6 @@ static void brcmf_sdio_bus_stop(struct device *dev)
brcmf_dbg(TRACE, "Enter\n");
if (bus->watchdog_tsk) {
- get_task_struct(bus->watchdog_tsk);
send_sig(SIGTERM, bus->watchdog_tsk, 1);
kthread_stop_put(bus->watchdog_tsk);
bus->watchdog_tsk = NULL;
@@ -4500,12 +4499,16 @@ int brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
timer_setup(&bus->timer, brcmf_sdio_watchdog, 0);
/* Initialize watchdog thread */
init_completion(&bus->watchdog_wait);
- bus->watchdog_tsk = kthread_run(brcmf_sdio_watchdog_thread,
- bus, "brcmf_wdog/%s",
- dev_name(&sdiodev->func1->dev));
+ bus->watchdog_tsk = kthread_create(brcmf_sdio_watchdog_thread,
+ bus, "brcmf_wdog/%s",
+ dev_name(&sdiodev->func1->dev));
if (IS_ERR(bus->watchdog_tsk)) {
pr_warn("brcmf_watchdog thread failed to start\n");
bus->watchdog_tsk = NULL;
+ } else {
+ /* The thread may exit on a SIGTERM before it is stopped */
+ get_task_struct(bus->watchdog_tsk);
+ wake_up_process(bus->watchdog_tsk);
}
/* Initialize DPC thread */
bus->dpc_triggered = false;
@@ -4576,7 +4579,6 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
if (bus) {
/* Stop watchdog task */
if (bus->watchdog_tsk) {
- get_task_struct(bus->watchdog_tsk);
send_sig(SIGTERM, bus->watchdog_tsk, 1);
kthread_stop_put(bus->watchdog_tsk);
bus->watchdog_tsk = NULL;
---
base-commit: d0f871bfb831705d9f55479f5b2b40f636ea7b16
branch: brcmfmac-wdog-uaf
--
2.43.0
next reply other threads:[~2026-11-20 17:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 17:42 Dario Binacchi [this message]
2026-11-24 20:13 ` [PATCH wireless] wifi: brcmfmac: fix use-after-free of the watchdog task_struct Arend van Spriel
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=20261120174231.2024897-1-dario.binacchi@amarulasolutions.com \
--to=dario.binacchi@amarulasolutions.com \
--cc=arend.vanspriel@broadcom.com \
--cc=benjamin.drung@canonical.com \
--cc=brcm80211-dev-list.pdl@broadcom.com \
--cc=brcm80211@lists.linux.dev \
--cc=fanwu01@zju.edu.cn \
--cc=linux-amarula@amarulasolutions.com \
--cc=linux-wireless@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mbrugger@suse.com \
--cc=michael@amarulasolutions.com \
--cc=nihaal@cse.iitm.ac.in \
--cc=runyu.xiao@seu.edu.cn \
--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