diff mbox series

rtw88: check for validity before using pointer

Message ID YcS3D2lwMd0Kox3z@debian-BULLSEYE-live-builder-AMD64 (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series rtw88: check for validity before using pointer | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Muhammad Usama Anjum Dec. 23, 2021, 5:51 p.m. UTC
ieee80211_probereq_get() can return NULL. Pointer skb should be checked
for validty before use.

Fixes: 10d162b2ed39 ("rtw88: 8822c: add ieee80211_ops::hw_scan")
Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
---
 drivers/net/wireless/realtek/rtw88/fw.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Ping-Ke Shih Dec. 24, 2021, 12:28 a.m. UTC | #1
> -----Original Message-----
> From: Muhammad Usama Anjum <usama.anjum@collabora.com>
> Sent: Friday, December 24, 2021 1:51 AM
> 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] rtw88: check for validity before using pointer
> 
> ieee80211_probereq_get() can return NULL. Pointer skb should be checked
> for validty before use.
> 
> Fixes: 10d162b2ed39 ("rtw88: 8822c: add ieee80211_ops::hw_scan")
> Signed-off-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
>  drivers/net/wireless/realtek/rtw88/fw.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c
> index 2f7c036f9022..0fc05a810d05 100644
> --- a/drivers/net/wireless/realtek/rtw88/fw.c
> +++ b/drivers/net/wireless/realtek/rtw88/fw.c
> @@ -1866,6 +1866,8 @@ 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)
> +			return -ENOMEM;
>  		rtw_append_probe_req_ie(rtwdev, skb, &list, rtwvif);
>  		kfree_skb(skb);
>  	}

Without properly freeing skb(s) in list, it leads memory leak.
We need something below to free them:

	if (!skb)
		goto out;

	[...]

out:
	skb_queue_walk(&list, skb)
		kfree_skb(skb);

	return -ENOMEM;

So, NACK this patch.

--
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..0fc05a810d05 100644
--- a/drivers/net/wireless/realtek/rtw88/fw.c
+++ b/drivers/net/wireless/realtek/rtw88/fw.c
@@ -1866,6 +1866,8 @@  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)
+			return -ENOMEM;
 		rtw_append_probe_req_ie(rtwdev, skb, &list, rtwvif);
 		kfree_skb(skb);
 	}