]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: ath12k: fix NULL pointer dereference in rhash table destroy
authorJose Ignacio Tornos Martinez <jtornosm@redhat.com>
Mon, 15 Jun 2026 11:21:03 +0000 (13:21 +0200)
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>
Mon, 13 Jul 2026 13:55:17 +0000 (06:55 -0700)
When unbinding the ath12k driver, kernel NULL pointer dereferences
occur in irq_work_sync() called from rhashtable_destroy().

Two hash tables are affected:
1. ath12k_link_sta hash table in ath12k_base
2. ath12k_dp_link_peer hash table in ath12k_dp

The issue happens because the destroy functions are called unconditionally
in cleanup paths, but the hash tables are only initialized late in their
respective init functions. If the device was never fully started or if the
init functions failed before initializing the hash tables, the pointers
will be NULL. The issues are always reproducible from a VM because the MSI
addressing initialization is failing.

Call trace for ath12k_link_sta_rhash_tbl_destroy:
 RIP: irq_work_sync+0x1e/0x70
 rhashtable_destroy+0x12/0x60
 ath12k_link_sta_rhash_tbl_destroy+0x19/0x40 [ath12k]
 ath12k_core_stop+0xe/0x80 [ath12k]
 ath12k_core_hw_group_cleanup+0x6b/0xb0 [ath12k]
 ath12k_pci_remove+0x60/0x110 [ath12k]

Call trace for ath12k_dp_link_peer_rhash_tbl_destroy:
 RIP: irq_work_sync+0x1e/0x70
 rhashtable_destroy+0x12/0x60
 ath12k_dp_link_peer_rhash_tbl_destroy+0x29/0x50 [ath12k]
 ath12k_dp_cmn_device_deinit+0x21/0x140 [ath12k]
 ath12k_core_hw_group_cleanup+0x6b/0xb0 [ath12k]
 ath12k_pci_remove+0x60/0x110 [ath12k]

Fix this by adding NULL checks before calling rhashtable_destroy() in
both destroy functions.

The NULL check approach was chosen because the rhashtable pointer
serves as the initialization state indicator. The init can fail at
various points, leaving some components uninitialized. Checking the
pointer directly is simpler than adding separate state flags that
would need synchronization.

Fixes: 57ccca410237 ("wifi: ath12k: Add hash table for ath12k_link_sta in ath12k_base")
Fixes: a88cf5f71adf ("wifi: ath12k: Add hash table for ath12k_dp_link_peer")
Cc: stable@vger.kernel.org
Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com>
Reviewed-by: Vasanthakumar Thiagarajan <vasanthakumar.thiagarajan@oss.qualcomm.com>
Link: https://patch.msgid.link/20260615112103.601982-1-jtornosm@redhat.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
drivers/net/wireless/ath/ath12k/dp_peer.c
drivers/net/wireless/ath/ath12k/peer.c

index 2660b4c7449be2066dad70412d2d12d012d8b102..a12073afc307cea39dee50ee77b4fe2cb17f4891 100644 (file)
@@ -274,11 +274,14 @@ int ath12k_dp_link_peer_rhash_tbl_init(struct ath12k_dp *dp)
 
 void ath12k_dp_link_peer_rhash_tbl_destroy(struct ath12k_dp *dp)
 {
-       mutex_lock(&dp->link_peer_rhash_tbl_lock);
+       guard(mutex)(&dp->link_peer_rhash_tbl_lock);
+
+       if (!dp->rhead_peer_addr)
+               return;
+
        rhashtable_destroy(dp->rhead_peer_addr);
        kfree(dp->rhead_peer_addr);
        dp->rhead_peer_addr = NULL;
-       mutex_unlock(&dp->link_peer_rhash_tbl_lock);
 }
 
 static int ath12k_dp_link_peer_rhash_insert(struct ath12k_dp *dp,
index c222bdaa333c523d939256387daac7c95343c01f..2681a047d4d51968d44c29240369256dbacbfe5f 100644 (file)
@@ -453,6 +453,9 @@ err_free:
 
 void ath12k_link_sta_rhash_tbl_destroy(struct ath12k_base *ab)
 {
+       if (!ab->rhead_sta_addr)
+               return;
+
        rhashtable_destroy(ab->rhead_sta_addr);
        kfree(ab->rhead_sta_addr);
        ab->rhead_sta_addr = NULL;