Skip to content

Commit 5b0ec94

Browse files
committed
mac80211: fix memory leak in register_hw() error path
Move the internal scan request allocation below the last sanity check in ieee80211_register_hw() to avoid leaking memory if the sanity check actually triggers. Reported-by: ZHAO Gang <gamerh2o@gmail.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent ef04a29 commit 5b0ec94

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎net/mac80211/main.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -846,17 +846,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
846846
/* TODO: consider VHT for RX chains, hopefully it's the same */
847847
}
848848

849-
local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
850-
sizeof(void *) * channels, GFP_KERNEL);
851-
if (!local->int_scan_req)
852-
return -ENOMEM;
853-
854-
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
855-
if (!local->hw.wiphy->bands[band])
856-
continue;
857-
local->int_scan_req->rates[band] = (u32) -1;
858-
}
859-
860849
/* if low-level driver supports AP, we also support VLAN */
861850
if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
862851
hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
@@ -880,6 +869,17 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
880869
return -EINVAL;
881870
}
882871

872+
local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
873+
sizeof(void *) * channels, GFP_KERNEL);
874+
if (!local->int_scan_req)
875+
return -ENOMEM;
876+
877+
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
878+
if (!local->hw.wiphy->bands[band])
879+
continue;
880+
local->int_scan_req->rates[band] = (u32) -1;
881+
}
882+
883883
#ifndef CONFIG_MAC80211_MESH
884884
/* mesh depends on Kconfig, but drivers should set it if they want */
885885
local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);

0 commit comments

Comments
 (0)