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 --- 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