diff mbox series

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

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

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Muhammad Usama Anjum Dec. 24, 2021, 7:35 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 to not memory leak.

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

---
v2:
Free the list in case of error
---
 drivers/net/wireless/realtek/rtw88/fw.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Ping-Ke Shih Dec. 24, 2021, 7:51 a.m. UTC | #1
> -----Original Message-----
> From: Muhammad Usama Anjum <usama.anjum@collabora.com>
> Sent: Friday, December 24, 2021 3:36 PM
> To: 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>; Pkshih
> <pkshih@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 v2] 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 to not memory leak.
> 
> Fixes: 10d162b2ed39 ("rtw88: 8822c: add ieee80211_ops::hw_scan")
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> 
> ---
> v2:
> Free the list in case of error
> ---
>  drivers/net/wireless/realtek/rtw88/fw.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c
> index 2f7c036f9022..7e1fab7afb69 100644
> --- a/drivers/net/wireless/realtek/rtw88/fw.c
> +++ b/drivers/net/wireless/realtek/rtw88/fw.c
> @@ -1857,7 +1857,7 @@ static int rtw_hw_scan_update_probe_req(struct rtw_dev *rtwdev,
>  {
>  	struct cfg80211_scan_request *req = rtwvif->scan_req;
>  	struct sk_buff_head list;
> -	struct sk_buff *skb;
> +	struct sk_buff *skb, *tmp;
>  	u8 num = req->n_ssids, i;
> 
>  	skb_queue_head_init(&list);
> @@ -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_safe(&list, skb, tmp)

Don't you think skb_queue_walk() is enough? Because we don't need to do
skb_unlink() in the loop.

> +		kfree_skb(skb);
> +
> +	return -ENOMEM;
>  }
> 
>  static int rtw_add_chan_info(struct rtw_dev *rtwdev, struct rtw_chan_info *info,
> --

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..7e1fab7afb69 100644
--- a/drivers/net/wireless/realtek/rtw88/fw.c
+++ b/drivers/net/wireless/realtek/rtw88/fw.c
@@ -1857,7 +1857,7 @@  static int rtw_hw_scan_update_probe_req(struct rtw_dev *rtwdev,
 {
 	struct cfg80211_scan_request *req = rtwvif->scan_req;
 	struct sk_buff_head list;
-	struct sk_buff *skb;
+	struct sk_buff *skb, *tmp;
 	u8 num = req->n_ssids, i;
 
 	skb_queue_head_init(&list);
@@ -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_safe(&list, skb, tmp)
+		kfree_skb(skb);
+
+	return -ENOMEM;
 }
 
 static int rtw_add_chan_info(struct rtw_dev *rtwdev, struct rtw_chan_info *info,