Skip to contentSkip to conversation

wifi: ath10k: free msdu_id and skb reference when HL TX fails

PATCH Superseded Changyul Lee 3 participants 5 messages Nov 18 Qualcomm Atheros ATH10K wireless driver

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: ath10k: free msdu_id and skb reference when HL TX fails

For SDIO and USB devices, ath10k_htt_tx_hl() allocates an msdu_id in htt->pending_tx and takes an extra skb reference that ath10k_htt_htc_tx_complete() normally drops. If ath10k_htc_send_hl() fails, for example because the endpoint has no TX credits and TX bundling is off, no completion runs and both are leaked. After max_num_pending_tx such failures, msdu_id allocation fails and no more data frames can be sent.

Free the msdu_id under tx_lock, as ath10k_htt_tx_32() does on its error path, and drop the extra skb reference.

Fixes 8ea51e409eb0 ("ath10k: htt: support MSDU ids with SDIO")
Fixes 30382dd1cf3a ("ath10k: fix use-after-free on SDIO data frames")

---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus ATH10K_SDIO, ATH10K_USB and W=1.

 drivers/net/wireless/ath/ath10k/htt_tx.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/wireless/ath/ath10k/htt_tx.c +8 -0
index efaea150025b..b437b09717e1 100644
@@ -1378,6 +1378,14 @@ static int ath10k_htt_tx_hl(struct ath10k_htt *htt, enum ath10k_hw_txrx_mode txm
 	tx_desc->peerid = __cpu_to_le32(HTT_INVALID_PEERID);
 
 	res = ath10k_htc_send_hl(&htt->ar->htc, htt->eid, msdu);
+	if (res) {
+		if (ar->bus_param.hl_msdu_ids) {
+			spin_lock_bh(&htt->tx_lock);
+			ath10k_htt_tx_free_msdu_id(htt, msdu_id);
+			spin_unlock_bh(&htt->tx_lock);
+		}
+		dev_kfree_skb_any(msdu);
+	}
 
 out:
 	return res;

base-commit: 4016f6c3149e7e3faccc1654db6a3030c069383a

Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Changyul Lee

For SDIO and USB devices, ath10k_htt_tx_hl() allocates an msdu_id in htt->pending_tx and takes an extra skb reference that ath10k_htt_htc_tx_complete() normally drops. If ath10k_htc_send_hl() fails, for example because the endpoint has no TX credits and TX bundling is off, no completion runs and both are leaked. After max_num_pending_tx such failures, msdu_id allocation fails and no more data frames can be sent.

The above message looks too verbose and confusing for a somewhat simple issue. Maybe this should be split properly in two fixes.

Quoted 5 lines

Free the msdu_id under tx_lock, as ath10k_htt_tx_32() does on its error path, and drop the extra skb reference.

Fixes 8ea51e409eb0 ("ath10k: htt: support MSDU ids with SDIO")
Fixes 30382dd1cf3a ("ath10k: fix use-after-free on SDIO data frames")

If this is a fix you should not target 'ath-next'. Two fixes tag looks weird, what are you fixin exactly?

Quoted 34 lines

---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus ATH10K_SDIO, ATH10K_USB and W=1.

 drivers/net/wireless/ath/ath10k/htt_tx.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/net/wireless/ath/ath10k/htt_tx.c +8 -0
index efaea150025b..b437b09717e1 100644
@@ -1378,6 +1378,14 @@ static int ath10k_htt_tx_hl(struct ath10k_htt *htt, enum ath10k_hw_txrx_mode txm
        tx_desc->peerid = __cpu_to_le32(HTT_INVALID_PEERID);
 
        res = ath10k_htc_send_hl(&htt->ar->htc, htt->eid, msdu);
+       if (res) {
+               if (ar->bus_param.hl_msdu_ids) {
+                       spin_lock_bh(&htt->tx_lock);
+                       ath10k_htt_tx_free_msdu_id(htt, msdu_id);
+                       spin_unlock_bh(&htt->tx_lock);
+               }
+               dev_kfree_skb_any(msdu);
+       }
 
 out:
        return res;

base-commit: 4016f6c3149e7e3faccc1654db6a3030c069383a --
2.43.0

#2 lore raw

Hi Loic,

Thanks for the review.

Quoted 2 lines · Loic Poulain

The above message looks too verbose and confusing for a somewhat simple issue. Maybe this should be split properly in two fixes.

I originally wanted to fix the msdu_id leak. ath10k_htt_tx_hl() allocates an msdu_id in htt->pending_tx, but leaves the entry there if ath10k_htc_send_hl() fails.

I also noticed that the same error path doesn't drop the extra skb reference taken by skb_get(), so I included both fixes in v1. I think I could have explained this more clearly when covering both fixes together. Sorry for the confusion.

Quoted 2 lines

If this is a fix you should not target 'ath-next'. Two fixes tag looks weird, what are you fixin exactly?

I Cc'd Wentao Liang because he had already posted a patch for the skb reference leak [1], but I left that explanation out of v1. Would it be okay if I sent a v2 that only fixes the msdu_id leak?

[1] https://lore.kernel.org/all/[email protected]/

Thanks,
Changyul

#3 lore raw
Quoted 17 lines · Changyul Lee

Hi Loic,

Thanks for the review.

Quoted 2 lines · Loic Poulain

The above message looks too verbose and confusing for a somewhat simple issue. Maybe this should be split properly in two fixes.

I originally wanted to fix the msdu_id leak. ath10k_htt_tx_hl() allocates an msdu_id in htt->pending_tx, but leaves the entry there if ath10k_htc_send_hl() fails.

I also noticed that the same error path doesn't drop the extra skb reference taken by skb_get(), so I included both fixes in v1. I think I could have explained this more clearly when covering both fixes together. Sorry for the confusion.

Quoted 8 lines
Quoted 2 lines

If this is a fix you should not target 'ath-next'. Two fixes tag looks weird, what are you fixin exactly?

I Cc'd Wentao Liang because he had already posted a patch for the skb reference leak [1], but I left that explanation out of v1. Would it be okay if I sent a v2 that only fixes the msdu_id leak?

[1] https://lore.kernel.org/all/[email protected]/

FWIW I've rejected all patches from [email protected] since multiple folks were using the same e-mail address which is contrary to the DCO. So I'm waiting to see if there is a repost with an individualized e-mail address.

But I also don't want multiple fixes in a single patch because then it complicates backporting to stable kernels (unless both of the patches being fixed were originally part of the same kernel or both predate v5.10).

/jeff

#4 lore raw

Thanks for the explanation. I will split this into two patches and send them.
(I accidentally replied only to one person, sorry for the duplicate.)

Thank you,
Changyul