Skip to contentSkip to conversation

rtl8192cu: Fixes for leaks and deadlock

PATCH In review Reto Schneider 3 participants 7 messages Jun 22, 2020 – Jul 15, 2020 Realtek wireless driver (rtlwifi family)

lore
Share & tools
lore
#0 lore raw

cover rtl8192cu: Fixes for leaks and deadlock

Issues have been found on a Realtek RTL8188CUS/Atmel AT91SAM9G25 (ARMv5) machine. Testing has been done on the same.

Reto Schneider (3):
rtl8192cu: Fix deadlock
rtl8192cu: Prevent leaking urb
rtl8192cu: Free ieee80211_hw if probing fails

 drivers/net/wireless/realtek/rtlwifi/usb.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/3 rtl8192cu: Fix deadlock

Prevent code from calling itself indirectly, causing the driver to hang and consume 100% CPU.

Without this fix, the following script can bring down a single CPU system:

```
while true; do
  rmmod rtl8192cu
  modprobe rtl8192cu
done
```
---
 drivers/net/wireless/realtek/rtlwifi/usb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtlwifi/usb.c +4 -2
index c66c6dc00378..d3bbfc0171f6 100644
@@ -680,8 +680,10 @@ static void _rtl_usb_cleanup_rx(struct ieee80211_hw *hw)
 	tasklet_kill(&rtlusb->rx_work_tasklet);
 	cancel_work_sync(&rtlpriv->works.lps_change_work);
 
-	flush_workqueue(rtlpriv->works.rtl_wq);
-	destroy_workqueue(rtlpriv->works.rtl_wq);
+	if (rtlpriv->works.rtl_wq) {
+		destroy_workqueue(rtlpriv->works.rtl_wq);
+		rtlpriv->works.rtl_wq = NULL;
+	}
 
 	skb_queue_purge(&rtlusb->rx_queue);
 
Signature · 1 line
2.20.1
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] rtl8192cu: Fix deadlock

Quoted 5 lines · Reto Schneider

Prevent code from calling itself indirectly, causing the driver to hang and consume 100% CPU.

Without this fix, the following script can bring down a single CPU system:

Quoted 8 lines
```
while true; do
   rmmod rtl8192cu
   modprobe rtl8192cu
done
```

I have one small comment. Patches for the rtlwifi family of drivers have patch subjects of the form [PATCH] rtlwifi: rtl8192cu: blah blah. I'll let Kalle decide if he wants ignore my comment, manually change the subjects, or request a V2. Otherwise all 3 patches are OK.

Larry

#3 lore raw

Re: [PATCH 1/3] rtl8192cu: Fix deadlock

Quoted 13 lines · Larry Finger
Quoted 12 lines · Reto Schneider

Prevent code from calling itself indirectly, causing the driver to hang and consume 100% CPU.

Without this fix, the following script can bring down a single CPU system:

```
while true; do
   rmmod rtl8192cu
   modprobe rtl8192cu
done
```
Quoted 6 lines
Quoted 1 line

I have one small comment. Patches for the rtlwifi family of drivers have patch subjects of the form [PATCH] rtlwifi: rtl8192cu: blah blah. I'll let Kalle decide if he wants ignore my comment, manually change the subjects, or request a V2. Otherwise all 3 patches are OK.

I can fix the titles during commit.

Signature · 1 line
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#4 lore raw

Re: [PATCH 1/3] rtlwifi: rtl8192cu: Fix deadlock

In reply to Reto Schneider
Quoted 12 lines · Reto Schneider

Prevent code from calling itself indirectly, causing the driver to hang and consume 100% CPU.

Without this fix, the following script can bring down a single CPU system:

```
while true; do
  rmmod rtl8192cu
  modprobe rtl8192cu
done
```
Quoted 2 lines

3 patches applied to wireless-drivers-next.git, thanks.

ec89032cd148 rtlwifi: rtl8192cu: Fix deadlock 03128643eb54 rtlwifi: rtl8192cu: Prevent leaking urb a7f7c15e945a rtlwifi: rtl8192cu: Free ieee80211_hw if probing fails

Signature · 3 lines
https://patchwork.kernel.org/patch/11617759/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#5 lore raw

PATCH 2/3 rtl8192cu: Prevent leaking urb

In reply to Reto Schneider

If usb_submit_urb fails the allocated urb should be unanchored and released.

---
 drivers/net/wireless/realtek/rtlwifi/usb.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtlwifi/usb.c +4 -1
index d3bbfc0171f6..1a9fcb2697bf 100644
@@ -720,8 +720,11 @@ static int _rtl_usb_receive(struct ieee80211_hw *hw)
 
 		usb_anchor_urb(urb, &rtlusb->rx_submitted);
 		err = usb_submit_urb(urb, GFP_KERNEL);
-		if (err)
+		if (err) {
+			usb_unanchor_urb(urb);
+			usb_free_urb(urb);
 			goto err_out;
+		}
 		usb_free_urb(urb);
 	}
 	return 0;
Signature · 1 line
2.20.1
#6 lore raw

PATCH 3/3 rtl8192cu: Free ieee80211_hw if probing fails

In reply to Reto Schneider

In case of an error, no one will use the allocated structure. Call ieee80211_free_hw, same as in rtl_usb_disconnect.

---
 drivers/net/wireless/realtek/rtlwifi/usb.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/realtek/rtlwifi/usb.c +1 -0
index 1a9fcb2697bf..d05e709536ea 100644
@@ -1087,6 +1087,7 @@ int rtl_usb_probe(struct usb_interface *intf,
 	usb_put_dev(udev);
 	complete(&rtlpriv->firmware_loading_complete);
 	kfree(rtlpriv->usb_data);
+	ieee80211_free_hw(hw);
 	return -ENODEV;
 }
 EXPORT_SYMBOL(rtl_usb_probe);
Signature · 1 line
2.20.1