Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH ath-current 0/3] wifi: ath11k: give the regulatory state the lifetime of the device
@ 2026-11-18 15:29 Zhao Li
  2026-11-18 15:29 ` [PATCH ath-current 1/3] wifi: ath11k: don't walk an unallocated regulatory info store Zhao Li
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zhao Li @ 2026-11-18 15:29 UTC (permalink / raw)
  To: Jeff Johnson
  Cc: Kalle Valo, Wen Gong, Baochen Qiang, Anilkumar Kolli,
	linux-wireless, ath11k, linux-kernel

ab->reg_info_store, with the rules it holds, and the default_regd[] and
new_regd[] domains live as long as struct ath11k_base, but their
teardown does not follow that lifetime. The SERVICE_READY_EXT error
path frees the store from a transient event handler, and the remove
paths that follow a failed start never call ath11k_reg_free().

Patch 1 lets ath11k_reg_free() cope with a store that was never
allocated. Patch 2 moves ath11k_reg_free() into ath11k_core_free(), so
that every teardown path frees the regulatory state. Patch 3 then drops
the free from the SERVICE_READY_EXT error path. In this order no step
adds a crash or a leak.

A separate patch, sent on its own, makes a failed SERVICE_READY_EXT
fail the start instead of letting SERVICE_READY_EXT2 complete it.

Zhao Li (3):
  wifi: ath11k: don't walk an unallocated regulatory info store
  wifi: ath11k: free the regulatory state when the device is freed
  wifi: ath11k: keep the regulatory info store on a SERVICE_READY_EXT
    error

 drivers/net/wireless/ath/ath11k/core.c | 2 +-
 drivers/net/wireless/ath/ath11k/reg.c  | 6 ++++--
 drivers/net/wireless/ath/ath11k/wmi.c  | 9 ---------
 3 files changed, 5 insertions(+), 12 deletions(-)


base-commit: b1ed5a45b994a6473ca1cf34f35a1bf87f1d8e2a
-- 
2.56.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH ath-current 1/3] wifi: ath11k: don't walk an unallocated regulatory info store
  2026-11-18 15:29 [PATCH ath-current 0/3] wifi: ath11k: give the regulatory state the lifetime of the device Zhao Li
@ 2026-11-18 15:29 ` Zhao Li
  2026-11-18 15:29 ` [PATCH ath-current 2/3] wifi: ath11k: free the regulatory state when the device is freed Zhao Li
  2026-11-18 15:29 ` [PATCH ath-current 3/3] wifi: ath11k: keep the regulatory info store on a SERVICE_READY_EXT error Zhao Li
  2 siblings, 0 replies; 4+ messages in thread
From: Zhao Li @ 2026-11-18 15:29 UTC (permalink / raw)
  To: Jeff Johnson
  Cc: Kalle Valo, Wen Gong, Baochen Qiang, Anilkumar Kolli,
	linux-wireless, ath11k, linux-kernel, stable, Zhao Li

ath11k_reg_free() resets the regulatory information of every radio in
ab->reg_info_store before it frees the store, without checking that the
store exists. SERVICE_READY_EXT counts the radios before it allocates
the store, and since commit 64828f091c7d ("wifi: ath11k: fix
reg_info_store leak in ath11k_service_ready_ext_event()") its error path
can also free the store after a firmware restart, so ab->num_radios can
be set while the store is NULL. A later ath11k_reg_free() then resets
the radios through the NULL store and faults on the second radio.

Reset the radios only when the store exists.

AI assistance was used.

Fixes: 7004bdceef60 ("wifi: ath11k: store cur_regulatory_info for each radio")
Cc: stable@vger.kernel.org
Signed-off-by: Zhao Li <enderaoelyther@gmail.com>
---
Found by code review. Tested in QEMU with KASAN, using a test module
and a test-only allocation failure in the SERVICE_READY_EXT handler that
leave a two-radio synthetic device without a store, and then calls
ath11k_reg_free(): without this change the call faults in
ath11k_reg_free(); with the series applied it completes.

No new W=1, sparse or smatch warnings.

 drivers/net/wireless/ath/ath11k/reg.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/reg.c b/drivers/net/wireless/ath/ath11k/reg.c
index 1030e119fd90..13e2ac96a12c 100644
--- a/drivers/net/wireless/ath/ath11k/reg.c
+++ b/drivers/net/wireless/ath/ath11k/reg.c
@@ -1049,8 +1049,10 @@ void ath11k_reg_free(struct ath11k_base *ab)
 {
 	int i;
 
-	for (i = 0; i < ab->num_radios; i++)
-		ath11k_reg_reset_info(&ab->reg_info_store[i]);
+	if (ab->reg_info_store) {
+		for (i = 0; i < ab->num_radios; i++)
+			ath11k_reg_reset_info(&ab->reg_info_store[i]);
+	}
 
 	kfree(ab->reg_info_store);
 	ab->reg_info_store = NULL;
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH ath-current 2/3] wifi: ath11k: free the regulatory state when the device is freed
  2026-11-18 15:29 [PATCH ath-current 0/3] wifi: ath11k: give the regulatory state the lifetime of the device Zhao Li
  2026-11-18 15:29 ` [PATCH ath-current 1/3] wifi: ath11k: don't walk an unallocated regulatory info store Zhao Li
@ 2026-11-18 15:29 ` Zhao Li
  2026-11-18 15:29 ` [PATCH ath-current 3/3] wifi: ath11k: keep the regulatory info store on a SERVICE_READY_EXT error Zhao Li
  2 siblings, 0 replies; 4+ messages in thread
From: Zhao Li @ 2026-11-18 15:29 UTC (permalink / raw)
  To: Jeff Johnson
  Cc: Kalle Valo, Wen Gong, Baochen Qiang, Anilkumar Kolli,
	linux-wireless, ath11k, linux-kernel, stable, Zhao Li

The regulatory state of struct ath11k_base, the reg_info_store array
with the rules it holds and the default_regd[] and new_regd[] domains,
lives as long as the device, but ath11k_reg_free() runs from
ath11k_core_soc_destroy(), which only ath11k_core_deinit() calls. The
teardown paths that follow a failed start skip ath11k_core_deinit():
ath11k_pci_remove() when ATH11K_FLAG_QMI_FAIL is set, and
ath11k_ahb_remove() and ath11k_ahb_shutdown() when
ATH11K_FLAG_REGISTERED is clear. They reach ath11k_core_free(), which
frees ab, and whatever regulatory state the failed start allocated
leaks.

Free the regulatory state in ath11k_core_free(), which every teardown
path reaches, right before ab itself.

AI assistance was used.

Fixes: 61a57e51e46e ("ath11k: fix rmmod failure if qmi sequence fails")
Cc: stable@vger.kernel.org # needs adjustments for <= 5.15
Signed-off-by: Zhao Li <enderaoelyther@gmail.com>
---
Found by code review. Tested in QEMU with KASAN, using a test module
that frees a synthetic device through ath11k_core_free() after a
SERVICE_READY_EXT event allocated the store, then reads the store to
see whether it was freed: without this change the read succeeds, so the
store leaks; with the series applied KASAN reports the read as a
use-after-free of the store that ath11k_reg_free() freed from
ath11k_core_free().

No new W=1, sparse or smatch warnings.

 drivers/net/wireless/ath/ath11k/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c
index 766ae27306f4..90124a826088 100644
--- a/drivers/net/wireless/ath/ath11k/core.c
+++ b/drivers/net/wireless/ath/ath11k/core.c
@@ -2021,7 +2021,6 @@ static void ath11k_core_soc_destroy(struct ath11k_base *ab)
 {
 	ath11k_debugfs_soc_destroy(ab);
 	ath11k_dp_free(ab);
-	ath11k_reg_free(ab);
 	ath11k_qmi_deinit_service(ab);
 }
 
@@ -2734,6 +2733,7 @@ void ath11k_core_free(struct ath11k_base *ab)
 {
 	destroy_workqueue(ab->workqueue_aux);
 	destroy_workqueue(ab->workqueue);
+	ath11k_reg_free(ab);
 
 	kfree(ab);
 }
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH ath-current 3/3] wifi: ath11k: keep the regulatory info store on a SERVICE_READY_EXT error
  2026-11-18 15:29 [PATCH ath-current 0/3] wifi: ath11k: give the regulatory state the lifetime of the device Zhao Li
  2026-11-18 15:29 ` [PATCH ath-current 1/3] wifi: ath11k: don't walk an unallocated regulatory info store Zhao Li
  2026-11-18 15:29 ` [PATCH ath-current 2/3] wifi: ath11k: free the regulatory state when the device is freed Zhao Li
@ 2026-11-18 15:29 ` Zhao Li
  2 siblings, 0 replies; 4+ messages in thread
From: Zhao Li @ 2026-11-18 15:29 UTC (permalink / raw)
  To: Jeff Johnson
  Cc: Kalle Valo, Wen Gong, Baochen Qiang, Anilkumar Kolli,
	linux-wireless, ath11k, linux-kernel, stable, Zhao Li

ab->reg_info_store lives as long as the device. The first
SERVICE_READY_EXT event allocates it, every later firmware start reuses
it, the regulatory events keep the rules of each radio in it, and
ath11k_reg_free() frees it together with those rules when the device is
freed.

Commit 64828f091c7d ("wifi: ath11k: fix reg_info_store leak in
ath11k_service_ready_ext_event()") frees the store and clears the
pointer on the SERVICE_READY_EXT error path. When the event fails after
a firmware restart, that leaks the rules the store holds and leaves the
store NULL while the radios stay registered with mac80211:
ath11k_reg_handle_chan_list() then writes through the NULL pointer, and
the 6 GHz paths of ath11k_mac_op_add_interface(),
ath11k_mac_parse_tx_pwr_env() and ath11k_mac_op_sta_state() read
through it. The leak that commit addressed, a store allocated by a
first start that later fails, no longer needs it: ath11k_core_free()
frees the regulatory state on every teardown path.

Do not free the store on the error path.

AI assistance was used.

Fixes: 64828f091c7d ("wifi: ath11k: fix reg_info_store leak in ath11k_service_ready_ext_event()")
Cc: stable@vger.kernel.org
Signed-off-by: Zhao Li <enderaoelyther@gmail.com>
---
Found by code review. Tested in QEMU with KASAN, using a test module
that runs a SERVICE_READY_EXT and a regulatory event on a synthetic
device and then restarts it with a failing SERVICE_READY_EXT: without
this change the store pointer is cleared; with the series applied the
store keeps the country code and the rule count of the first start.

No new W=1, sparse or smatch warnings.

 drivers/net/wireless/ath/ath11k/wmi.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/net/wireless/ath/ath11k/wmi.c b/drivers/net/wireless/ath/ath11k/wmi.c
index 08fd6795ed9e..bbca275a8289 100644
--- a/drivers/net/wireless/ath/ath11k/wmi.c
+++ b/drivers/net/wireless/ath/ath11k/wmi.c
@@ -5136,15 +5136,6 @@ static int ath11k_service_ready_ext_event(struct ath11k_base *ab,
 
 err:
 	kfree(svc_rdy_ext.mac_phy_caps);
-
-	/*
-	 * During TLV iteration the WMI_TAG_SOC_HAL_REG_CAPABILITIES
-	 * handler may have allocated ab->reg_info_store, so free it
-	 * on error to avoid a memory leak
-	 */
-	kfree(ab->reg_info_store);
-	ab->reg_info_store = NULL;
-
 	ath11k_wmi_free_dbring_caps(ab);
 	return ret;
 }
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-18 15:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 15:29 [PATCH ath-current 0/3] wifi: ath11k: give the regulatory state the lifetime of the device Zhao Li
2026-11-18 15:29 ` [PATCH ath-current 1/3] wifi: ath11k: don't walk an unallocated regulatory info store Zhao Li
2026-11-18 15:29 ` [PATCH ath-current 2/3] wifi: ath11k: free the regulatory state when the device is freed Zhao Li
2026-11-18 15:29 ` [PATCH ath-current 3/3] wifi: ath11k: keep the regulatory info store on a SERVICE_READY_EXT error Zhao Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox