Skip to contentSkip to conversation

ath9k: hif_usb: fix memory leak in ath9k_hif_usb_firmware_cb

PATCH In review Dongliang Mu 3 participants 5 messages Jul 9, 2021 – Jul 27, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ath9k: hif_usb: fix memory leak in ath9k_hif_usb_firmware_cb

The commit 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()") adds three usb_get_urb in ath9k_hif_usb_dealloc_tx_urbs and usb_free_urb.

Fix this bug by adding corresponding usb_free_urb in ath9k_hif_usb_dealloc_tx_urbs other and hif_usb_stop.

Reported-by [email protected]
Fixes 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()")
---
 drivers/net/wireless/ath/ath9k/hif_usb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/ath9k/hif_usb.c +3 -0
index 860da13bfb6a..bda91ff3289b 100644
@@ -457,6 +457,7 @@ static void hif_usb_stop(void *hif_handle)
 		usb_kill_urb(tx_buf->urb);
 		list_del(&tx_buf->list);
 		usb_free_urb(tx_buf->urb);
+		usb_free_urb(tx_buf->urb);
 		kfree(tx_buf->buf);
 		kfree(tx_buf);
 		spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
@@ -779,6 +780,7 @@ static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
 		usb_kill_urb(tx_buf->urb);
 		list_del(&tx_buf->list);
 		usb_free_urb(tx_buf->urb);
+		usb_free_urb(tx_buf->urb);
 		kfree(tx_buf->buf);
 		kfree(tx_buf);
 		spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
@@ -797,6 +799,7 @@ static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
 		usb_kill_urb(tx_buf->urb);
 		list_del(&tx_buf->list);
 		usb_free_urb(tx_buf->urb);
+		usb_free_urb(tx_buf->urb);
 		kfree(tx_buf->buf);
 		kfree(tx_buf);
 		spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Dongliang Mu

The commit 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()") adds three usb_get_urb in ath9k_hif_usb_dealloc_tx_urbs and usb_free_urb.

Fix this bug by adding corresponding usb_free_urb in ath9k_hif_usb_dealloc_tx_urbs other and hif_usb_stop.

Any idea about this patch?

Quoted 38 lines
Reported-by [email protected]
Fixes 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()")
---
 drivers/net/wireless/ath/ath9k/hif_usb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/ath9k/hif_usb.c +3 -1
index 860da13bfb6a..bda91ff3289b 100644
@@ -457,6 +457,7 @@ static void hif_usb_stop(void *hif_handle)
                usb_kill_urb(tx_buf->urb);
                list_del(&tx_buf->list);
                usb_free_urb(tx_buf->urb);
+               usb_free_urb(tx_buf->urb);
                kfree(tx_buf->buf);
                kfree(tx_buf);
                spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
@@ -779,6 +780,7 @@ static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
                usb_kill_urb(tx_buf->urb);
                list_del(&tx_buf->list);
                usb_free_urb(tx_buf->urb);
+               usb_free_urb(tx_buf->urb);
                kfree(tx_buf->buf);
                kfree(tx_buf);
                spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
@@ -797,6 +799,7 @@ static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
                usb_kill_urb(tx_buf->urb);
                list_del(&tx_buf->list);
                usb_free_urb(tx_buf->urb);
+               usb_free_urb(tx_buf->urb);
                kfree(tx_buf->buf);
                kfree(tx_buf);
                spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
--

2.25.1

#2 lore raw
In reply to Dongliang Mu
Quoted 10 lines · Dongliang Mu

The commit 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()") adds three usb_get_urb in ath9k_hif_usb_dealloc_tx_urbs and usb_free_urb.

Fix this bug by adding corresponding usb_free_urb in ath9k_hif_usb_dealloc_tx_urbs other and hif_usb_stop.

Reported-by [email protected]
Fixes 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()")

In the past there have been so many problems with ath9k syzbot fixes that I have now a hard time trusting them. Can someone review this in detail, please?

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

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw
In reply to Dongliang Mu

Hi Dongliang,

(Drive-by review, I know almost nothing about the code in question)

Quoted 20 lines · Dongliang Mu

The commit 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()") adds three usb_get_urb in ath9k_hif_usb_dealloc_tx_urbs and usb_free_urb.

Fix this bug by adding corresponding usb_free_urb in ath9k_hif_usb_dealloc_tx_urbs other and hif_usb_stop.

Reported-by [email protected]
Fixes 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()")
---
 drivers/net/wireless/ath/ath9k/hif_usb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/ath9k/hif_usb.c +0 -0
index 860da13bfb6a..bda91ff3289b 100644

drivers/net/wireless/ath/ath9k/hif_usb.c static void hif_usb_stop(void *hif_handle) · line 460

Quoted 4 lines
drivers/net/wireless/ath/ath9k/hif_usb.c +1 -0
@@ -457,6 +457,7 @@ static void hif_usb_stop(void *hif_handle)
                usb_kill_urb(tx_buf->urb);
                list_del(&tx_buf->list);
                usb_free_urb(tx_buf->urb);
+               usb_free_urb(tx_buf->urb);

Ok, so if I'm reading this correctly, before the first usb_free_urb() call, we have two references to the urb at tx_buf->urb.

Why?

Isn't the better fix here to detangle why there's more than one reference to it and resolve it that way? This looks like a hack to fix something much more fundamentally broken.

Thanks,

Signature · 4 lines
Julian Calaby

Email: [email protected]
Profile: http://www.google.com/profiles/julian.calaby/
#4 lore raw
Quoted 33 lines · Julian Calaby

Hi Dongliang,

(Drive-by review, I know almost nothing about the code in question)

Quoted 20 lines · Dongliang Mu

The commit 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()") adds three usb_get_urb in ath9k_hif_usb_dealloc_tx_urbs and usb_free_urb.

Fix this bug by adding corresponding usb_free_urb in ath9k_hif_usb_dealloc_tx_urbs other and hif_usb_stop.

Reported-by [email protected]
Fixes 03fb92a432ea ("ath9k: hif_usb: fix race condition between usb_get_urb() and usb_kill_anchored_urbs()")
---
 drivers/net/wireless/ath/ath9k/hif_usb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/ath9k/hif_usb.c +0 -0
index 860da13bfb6a..bda91ff3289b 100644

drivers/net/wireless/ath/ath9k/hif_usb.c static void hif_usb_stop(void *hif_handle) · line 460

Quoted 4 lines
drivers/net/wireless/ath/ath9k/hif_usb.c +1 -0
@@ -457,6 +457,7 @@ static void hif_usb_stop(void *hif_handle)
                usb_kill_urb(tx_buf->urb);
                list_del(&tx_buf->list);
                usb_free_urb(tx_buf->urb);
+               usb_free_urb(tx_buf->urb);

Ok, so if I'm reading this correctly, before the first usb_free_urb() call, we have two references to the urb at tx_buf->urb.

Quoted 5 lines

Why?

Isn't the better fix here to detangle why there's more than one reference to it and resolve it that way? This looks like a hack to fix something much more fundamentally broken.

Yeah, this looks very suspicious.

One more thing: also the patch should be tested with real hardware. I'm worried that people are just trying to fix a syzbot warning and not really considering how it works in real life. That's why I'm extra careful with syzbot patches for wireless drivers.

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

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