Skip to contentSkip to conversation

wifi: cfg80211: fix a possible memory leak

PATCH In review Dinh Nguyen 2 participants 2 messages Nov 1, 2022 – Dec 1, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: cfg80211: fix a possible memory leak

Klockworks reported a possible memory leak when cfg80211_inform_single_bss_data() return on an error and ies is left allocated.

Fixes 0e227084aee3 ("cfg80211: clarify BSS probe response vs. beacon data")
---
 net/wireless/scan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/wireless/scan.c +3 -1
index 806a5f1330ff..3c81dc17e079 100644
@@ -2015,8 +2015,10 @@ cfg80211_inform_single_bss_data(struct wiphy *wiphy,
 
 	signal_valid = data->chan == channel;
 	res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid, ts);
-	if (!res)
+	if (!res) {
+		kfree(ies);
 		return NULL;
+	}
 
 	if (channel->band == NL80211_BAND_60GHZ) {
 		bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK;
Signature · 1 line
2.25.1
maintainer
#1 lore raw
Quoted 2 lines · Dinh Nguyen

Klockworks

You probably mean "klocwork" :)

Quoted 15 lines

reported a possible memory leak when
cfg80211_inform_single_bss_data() return on an error and ies is left allocated.

Fixes 0e227084aee3 ("cfg80211: clarify BSS probe response vs. beacon data")
---
 net/wireless/scan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/wireless/scan.c +0 -0
index 806a5f1330ff..3c81dc17e079 100644

net/wireless/scan.c cfg80211_inform_single_bss_data(struct wiphy *wiphy, · line 2022

Quoted 9 lines
net/wireless/scan.c +3 -1
@@ -2015,8 +2015,10 @@ cfg80211_inform_single_bss_data(struct wiphy *wiphy,
 
 	signal_valid = data->chan == channel;
 	res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid, ts);
-	if (!res)
+	if (!res) {
+		kfree(ies);
 		return NULL;
+	}
 

To be honest this makes me a bit nervous - the function will take over ownership of the tmp BSS in many cases if not all. Not saying it doesn't have a bug, but at least one case inside of it *does* free it even in the case of returning NULL and then you have a double-free?

So I think you didn't look at the code closely enough. Please do check and follow up with a proper fix.

johannes