Skip to contentSkip to conversation

ath11k: acquire ab->base_lock in unassign when finding the peer by addr

PATCH In review Niels Dossche 2 participants 8 messages Mar 14, 2022 – Mar 23, 2022 Qualcomm Atheros ATH11K wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ath11k: acquire ab->base_lock in unassign when finding the peer by addr

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +9 -3
index 07f499d5ec92..5db2333478a2 100644
@@ -7077,9 +7077,15 @@ ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
 	WARN_ON(!arvif->is_started);
 
 	if (ab->hw_params.vdev_start_delay &&
-	    arvif->vdev_type == WMI_VDEV_TYPE_MONITOR &&
-	    ath11k_peer_find_by_addr(ab, ar->mac_addr))
-		ath11k_peer_delete(ar, arvif->vdev_id, ar->mac_addr);
+	    arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
+		struct ath11k_peer *peer;
+
+		spin_lock_bh(&ab->base_lock);
+		peer = ath11k_peer_find_by_addr(ab, ar->mac_addr);
+		spin_unlock_bh(&ab->base_lock);
+		if (peer)
+			ath11k_peer_delete(ar, arvif->vdev_id, ar->mac_addr);
+	}
 
 	if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
 		ret = ath11k_mac_monitor_stop(ar);
Signature · 1 line
2.35.1
#1 lore raw
Quoted 10 lines · Niels Dossche

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")

On what hardware and firmware version did you test this?

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#2 lore raw
Quoted 10 lines · Kalle Valo
Quoted 8 lines · Niels Dossche

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Quoted 5 lines
Quoted 2 lines
Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")

On what hardware and firmware version did you test this?

Hi Kalle

Thanks for your reply.
I am currently working on a static analyser to detect missing locks. This was a reported case. I manually verified the report by looking
at the code, so that I do not send wrong information or patches.
After concluding that this seems to be a true positive, I created this patch. However, as I do not in fact have this particular hardware, I was unable to test it.

Thanks

#3 lore raw
Quoted 17 lines · Niels Dossche
Quoted 10 lines · Kalle Valo
Quoted 8 lines · Niels Dossche

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Quoted 5 lines
Quoted 2 lines
Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")

On what hardware and firmware version did you test this?

Quoted 6 lines

Thanks for your reply.
I am currently working on a static analyser to detect missing locks. This was a reported case. I manually verified the report by looking
at the code, so that I do not send wrong information or patches.
After concluding that this seems to be a true positive, I created this patch. However, as I do not in fact have this particular hardware, I was unable to test it.

Ah, I didn't realise this. If you are using a tool to find errors in the code it's always a good idea to document that in the commit log. I'll add an edited version of what wrote you above in the commit log, ok?

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#4 lore raw
Quoted 26 lines · Kalle Valo
Quoted 17 lines · Niels Dossche
Quoted 10 lines · Kalle Valo
Quoted 8 lines · Niels Dossche

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Quoted 5 lines
Quoted 2 lines
Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")

On what hardware and firmware version did you test this?

Quoted 6 lines

Thanks for your reply.
I am currently working on a static analyser to detect missing locks. This was a reported case. I manually verified the report by looking
at the code, so that I do not send wrong information or patches.
After concluding that this seems to be a true positive, I created this patch. However, as I do not in fact have this particular hardware, I was unable to test it.

Quoted 4 lines

Ah, I didn't realise this. If you are using a tool to find errors in the code it's always a good idea to document that in the commit log. I'll add an edited version of what wrote you above in the commit log, ok?

I will make sure to write that in future commits, sorry for the inconvenience. Adding an edited version of what I write to the commit log is okay for me, thanks!

Signature · 3 lines
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
#5 lore raw
In reply to Niels Dossche
Quoted 19 lines · Niels Dossche

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +0 -0
index 07f499d5ec92..5db2333478a2 100644

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, · line 7081

Quoted 8 lines
drivers/net/wireless/ath/ath11k/mac.c +2 -3
@@ -7077,9 +7077,15 @@ ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
 	WARN_ON(!arvif->is_started);
 
 	if (ab->hw_params.vdev_start_delay &&
-	    arvif->vdev_type == WMI_VDEV_TYPE_MONITOR &&
-	    ath11k_peer_find_by_addr(ab, ar->mac_addr))
-		ath11k_peer_delete(ar, arvif->vdev_id, ar->mac_addr);
+	    arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
+		struct ath11k_peer *peer;

In the pending branch I moved the declaration to the beginning of the function and added this to the commit log:

"I am currently working on a static analyser to detect missing locks and this was a reported case. I manually verified the report by looking at the code, but I do not have real hardware so this is compile tested only."

Signature · 8 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

-- 
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
#6 lore raw
Quoted 33 lines · Kalle Valo
Quoted 19 lines · Niels Dossche

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")
---
 drivers/net/wireless/ath/ath11k/mac.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +0 -0
index 07f499d5ec92..5db2333478a2 100644

drivers/net/wireless/ath/ath11k/mac.c ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw, · line 7081

Quoted 8 lines
drivers/net/wireless/ath/ath11k/mac.c +2 -3
@@ -7077,9 +7077,15 @@ ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
 	WARN_ON(!arvif->is_started);
 
 	if (ab->hw_params.vdev_start_delay &&
-	    arvif->vdev_type == WMI_VDEV_TYPE_MONITOR &&
-	    ath11k_peer_find_by_addr(ab, ar->mac_addr))
-		ath11k_peer_delete(ar, arvif->vdev_id, ar->mac_addr);
+	    arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
+		struct ath11k_peer *peer;

In the pending branch I moved the declaration to the beginning of the function and added this to the commit log:

Quoted 5 lines

"I am currently working on a static analyser to detect missing locks and this was a reported case. I manually verified the report by looking at the code, but I do not have real hardware so this is compile tested only."

Sounds good to me. Thanks!

Signature · 3 lines
ath11k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath11k
#7 lore raw
In reply to Niels Dossche
Quoted 8 lines · Niels Dossche

ath11k_peer_find_by_addr states via lockdep that ab->base_lock must be held when calling that function in order to protect the list. All callers except ath11k_mac_op_unassign_vif_chanctx have that lock acquired when calling ath11k_peer_find_by_addr. That lock is also not transitively held by a path towards ath11k_mac_op_unassign_vif_chanctx. The solution is to acquire the lock when calling ath11k_peer_find_by_addr inside ath11k_mac_op_unassign_vif_chanctx.

Quoted 8 lines

I am currently working on a static analyser to detect missing locks and this was a reported case. I manually verified the report by looking at the code, but I do not have real hardware so this is compile tested only.

Fixes 701e48a43e15 ("ath11k: add packet log support for QCA6390")

Patch applied to ath-next branch of ath.git, thanks.

2db80f93869d ath11k: acquire ab->base_lock in unassign when finding the peer by addr

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches