diff mbox series

[v3] rtw88: check for validity before using a pointer

Message ID YcWK1jxnd3vGdmCq@debian-BULLSEYE-live-builder-AMD64 (mailing list archive)
State Superseded
Delegated to: Kalle Valo
Headers show
Series [v3] rtw88: check for validity before using a pointer | expand

Commit Message

Muhammad Usama Anjum Dec. 24, 2021, 8:54 a.m. UTC
ieee80211_probereq_get() can return NULL. Pointer skb should be checked
for validty before use. If it is not valid, list of skbs needs to be
freed.

Fixes: 10d162b2ed39 ("rtw88: 8822c: add ieee80211_ops::hw_scan")
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

---
v3:
Use skb_queue_walk instead of skb_queue_walk_safe
v2:
Free the list in case of error
---
 drivers/net/wireless/realtek/rtw88/fw.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Ping-Ke Shih Dec. 24, 2021, 9 a.m. UTC | #1
> -----Original Message-----
> From: Muhammad Usama Anjum <usama.anjum@collabora.com>
> Sent: Friday, December 24, 2021 4:55 PM
> To: Yan-Hsuan Chuang <tony0620emma@gmail.com>; Kalle Valo <kvalo@kernel.org>; David S. Miller
> <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>; Pkshih <pkshih@realtek.com>; Bernie Huang
> <phhuang@realtek.com>; open list:REALTEK WIRELESS DRIVER (rtw88) <linux-wireless@vger.kernel.org>; open
> list:NETWORKING DRIVERS <netdev@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>
> Cc: usama.anjum@collabora.com; kernel@collabora.com
> Subject: [PATCH v3] rtw88: check for validity before using a pointer
> 
> ieee80211_probereq_get() can return NULL. Pointer skb should be checked
> for validty before use. If it is not valid, list of skbs needs to be
> freed.
> 
> Fixes: 10d162b2ed39 ("rtw88: 8822c: add ieee80211_ops::hw_scan")
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

Acked-by: Ping-Ke Shih <pkshih@realtek.com>

[...]
Ping-Ke Shih Jan. 21, 2022, 7:14 a.m. UTC | #2
> -----Original Message-----
> From: Pkshih <pkshih@realtek.com>
> Sent: Friday, December 24, 2021 5:01 PM
> To: Muhammad Usama Anjum <usama.anjum@collabora.com>; Yan-Hsuan Chuang <tony0620emma@gmail.com>; Kalle
> Valo <kvalo@kernel.org>; David S. Miller <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>; Bernie
> Huang <phhuang@realtek.com>; open list:REALTEK WIRELESS DRIVER (rtw88) <linux-wireless@vger.kernel.org>;
> open list:NETWORKING DRIVERS <netdev@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>
> Cc: kernel@collabora.com
> Subject: RE: [PATCH v3] rtw88: check for validity before using a pointer
> 
> > -----Original Message-----
> > From: Muhammad Usama Anjum <usama.anjum@collabora.com>
> > Sent: Friday, December 24, 2021 4:55 PM
> > To: Yan-Hsuan Chuang <tony0620emma@gmail.com>; Kalle Valo <kvalo@kernel.org>; David S. Miller
> > <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>; Pkshih <pkshih@realtek.com>; Bernie Huang
> > <phhuang@realtek.com>; open list:REALTEK WIRELESS DRIVER (rtw88) <linux-wireless@vger.kernel.org>; open
> > list:NETWORKING DRIVERS <netdev@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>
> > Cc: usama.anjum@collabora.com; kernel@collabora.com
> > Subject: [PATCH v3] rtw88: check for validity before using a pointer
> >
> > ieee80211_probereq_get() can return NULL. Pointer skb should be checked
> > for validty before use. If it is not valid, list of skbs needs to be
> > freed.
> >
> > Fixes: 10d162b2ed39 ("rtw88: 8822c: add ieee80211_ops::hw_scan")
> > Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> 
> Acked-by: Ping-Ke Shih <pkshih@realtek.com>
> 
> [...]
> 

I take this patch into my patchset [1], because my new patches are based this patch
related to fixes of hw_scan.

[1] https://lore.kernel.org/linux-wireless/20220121070813.9656-2-pkshih@realtek.com/T/#u

--
Ping-Ke
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c
index 2f7c036f9022..b56dc43229d2 100644
--- a/drivers/net/wireless/realtek/rtw88/fw.c
+++ b/drivers/net/wireless/realtek/rtw88/fw.c
@@ -1866,11 +1866,19 @@  static int rtw_hw_scan_update_probe_req(struct rtw_dev *rtwdev,
 					     req->ssids[i].ssid,
 					     req->ssids[i].ssid_len,
 					     req->ie_len);
+		if (!skb)
+			goto out;
 		rtw_append_probe_req_ie(rtwdev, skb, &list, rtwvif);
 		kfree_skb(skb);
 	}
 
 	return _rtw_hw_scan_update_probe_req(rtwdev, num, &list);
+
+out:
+	skb_queue_walk(&list, skb)
+		kfree_skb(skb);
+
+	return -ENOMEM;
 }
 
 static int rtw_add_chan_info(struct rtw_dev *rtwdev, struct rtw_chan_info *info,