Skip to content

Commit 8f9dcc2

Browse files
a-zakijmberg-intel
authored andcommitted
mac80211: fix a memory leak where sta_info is not freed
The following is from a system that went OOM due to a memory leak: wlan0: Allocated STA 74:83:c2:64:0b:87 wlan0: Allocated STA 74:83:c2:64:0b:87 wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_add_sta) wlan0: Adding new IBSS station 74:83:c2:64:0b:87 wlan0: moving STA 74:83:c2:64:0b:87 to state 2 wlan0: moving STA 74:83:c2:64:0b:87 to state 3 wlan0: Inserted STA 74:83:c2:64:0b:87 wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_work) wlan0: Adding new IBSS station 74:83:c2:64:0b:87 wlan0: moving STA 74:83:c2:64:0b:87 to state 2 wlan0: moving STA 74:83:c2:64:0b:87 to state 3 . . wlan0: expiring inactive not authorized STA 74:83:c2:64:0b:87 wlan0: moving STA 74:83:c2:64:0b:87 to state 2 wlan0: moving STA 74:83:c2:64:0b:87 to state 1 wlan0: Removed STA 74:83:c2:64:0b:87 wlan0: Destroyed STA 74:83:c2:64:0b:87 The ieee80211_ibss_finish_sta() is called twice on the same STA from 2 different locations. On the second attempt, the allocated STA is not destroyed creating a kernel memory leak. This is happening because sta_info_insert_finish() does not call sta_info_free() the second time when the STA already exists (returns -EEXIST). Note that the caller sta_info_insert_rcu() assumes STA is destroyed upon errors. Same fix is applied to -ENOMEM. Signed-off-by: Ahmed Zaki <anzaki@gmail.com> Link: https://lore.kernel.org/r/20211002145329.3125293-1-anzaki@gmail.com [change the error path label to use the existing code] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 942bd10 commit 8f9dcc2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/mac80211/sta_info.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,13 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
644644
/* check if STA exists already */
645645
if (sta_info_get_bss(sdata, sta->sta.addr)) {
646646
err = -EEXIST;
647-
goto out_err;
647+
goto out_cleanup;
648648
}
649649

650650
sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
651651
if (!sinfo) {
652652
err = -ENOMEM;
653-
goto out_err;
653+
goto out_cleanup;
654654
}
655655

656656
local->num_sta++;
@@ -706,8 +706,8 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
706706
out_drop_sta:
707707
local->num_sta--;
708708
synchronize_net();
709+
out_cleanup:
709710
cleanup_single_sta(sta);
710-
out_err:
711711
mutex_unlock(&local->sta_mtx);
712712
kfree(sinfo);
713713
rcu_read_lock();

0 commit comments

Comments
 (0)