[PATCH] wifi: ath12k: hold dp_lock when updating monitor user stats
From: Yaohan Li
Date: Tue Nov 17 2026 - 09:55:11 EST
ath12k_dp_mon_rx_update_user_stats() looks the peer up with
ath12k_dp_link_peer_find_by_ast(), which walks dp->peers and asserts
dp->dp_lock, but the monitor NAPI path only holds rcu_read_lock().
Peers are not RCU freed. ath12k_dp_link_peer_unmap_event() takes
dp->dp_lock and calls ath12k_dp_link_peer_free(), which does list_del()
followed by kfree(peer->peer_stats.rx_stats) and kfree(peer), so an
unmap arriving between the lookup and the use of peer or rx_stats frees
the objects the monitor path is still writing to. The lookup itself
walks a list that the same path can be unlinking from.
Take dp_lock around the lookup and the statistics update. The update
only performs arithmetic on the peer, so nothing that can sleep ends up
under the lock.
The affected code is present in v7.0 and later trees.
Signed-off-by: Yaohan Li <shunsheng1218@xxxxxxxxx>
---
Prepared against v7.4-rc1-1969-g666539eecdf4.
AI assistance: the analysis, the change and its review notes were
prepared with Claude (Anthropic) as a coding assistant. The author
reviewed the reasoning and takes responsibility for the content.
Testing: compile tested only (x86_64, gcc 11.4). No ath12k hardware
was available. The affected code is present in v7.0 and later
trees; v6.18 and earlier do not have dp_peer.c.
Locking: the monitor call chain holds no other lock at this point
(ath12k_dp_mon_rx_process_ulofdma() and the rate-table helper take
none, and the monitor paths never take ab->base_lock), and dp_lock is
not held by any caller, so the added lock introduces no inversion.
No Fixes: tag is given because the introducing commit lies outside the
fetched history of this tree; the code has been present since v7.0.
---
drivers/net/wireless/ath/ath12k/dp_mon.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ath/ath12k/dp_mon.c b/drivers/net/wireless/ath/ath12k/dp_mon.c
index ae14e118fe36..edf7a8142998 100644
--- a/drivers/net/wireless/ath/ath12k/dp_mon.c
+++ b/drivers/net/wireless/ath/ath12k/dp_mon.c
@@ -955,9 +955,12 @@ ath12k_dp_mon_rx_update_user_stats(struct ath12k_base *ab,
if (user_stats->ast_index == 0 || user_stats->ast_index == 0xFFFF)
return;
+ spin_lock_bh(&dp->dp_lock);
+
peer = ath12k_dp_link_peer_find_by_ast(dp, user_stats->ast_index);
if (!peer) {
+ spin_unlock_bh(&dp->dp_lock);
ath12k_warn(ab, "peer ast idx %d can't be found\n",
user_stats->ast_index);
return;
@@ -966,8 +969,10 @@ ath12k_dp_mon_rx_update_user_stats(struct ath12k_base *ab,
peer->rssi_comb = ppdu_info->rssi_comb;
ewma_avg_rssi_add(&peer->avg_rssi, ppdu_info->rssi_comb);
rx_stats = peer->peer_stats.rx_stats;
- if (!rx_stats)
+ if (!rx_stats) {
+ spin_unlock_bh(&dp->dp_lock);
return;
+ }
num_msdu = user_stats->tcp_msdu_count + user_stats->tcp_ack_msdu_count +
user_stats->udp_msdu_count + user_stats->other_msdu_count;
@@ -1038,6 +1043,8 @@ ath12k_dp_mon_rx_update_user_stats(struct ath12k_base *ab,
ath12k_dp_mon_rx_update_peer_rate_table_stats(rx_stats, ppdu_info,
user_stats, num_msdu);
+
+ spin_unlock_bh(&dp->dp_lock);
}
void
--
2.34.1