[PATCH 5.17 0536/1126] rtw88: fix use after free in rtw_hw_scan_update_probe_req()

Greg Kroah-Hartman
2022-04-05T09:32:02Z

From: Dan Carpenter <dan.carpenter@oracle.com>

[ Upstream commit a954f29aea5d2cf58feedf83235edf3367229a37 ]

This code needs to use skb_queue_walk_safe() instead of skb_queue_walk()
because it frees the list iterator.

Fixes: d95984b5580d ("rtw88: fix memory overrun and memory leak during hw_scan")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220203082532.GA25151@kili
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/net/wireless/realtek/rtw88/fw.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw88/fw.c b/drivers/net/wireless/realtek/rtw88/fw.c
index ce9535cce723..4c8e5ea5d069 100644
--- a/drivers/net/wireless/realtek/rtw88/fw.c
+++ b/drivers/net/wireless/realtek/rtw88/fw.c
@@ -1853,7 +1853,7 @@ static int _rtw_hw_scan_update_probe_req(struct rtw_dev *rtwdev, u8 num_probes,
rtwdev->scan_info.probe_pg_size = page_offset;
out:
kfree(buf);
- skb_queue_walk(probe_req_list, skb)
+ skb_queue_walk_safe(probe_req_list, skb, tmp)
kfree_skb(skb);

return ret;
@@ -1864,7 +1864,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, bands = 0;
int ret;

@@ -1889,7 +1889,7 @@ static int rtw_hw_scan_update_probe_req(struct rtw_dev *rtwdev,
return _rtw_hw_scan_update_probe_req(rtwdev, num * bands, &list);

out:
- skb_queue_walk(&list, skb)
+ skb_queue_walk_safe(&list, skb, tmp)
kfree_skb(skb);

return ret;
--
2.34.1