linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mac80211: fix a memory leak where sta_info is not freed
@ 2021-10-02 14:53 Ahmed Zaki
  2021-11-15 10:06 ` Johannes Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmed Zaki @ 2021-10-02 14:53 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linux-wireless, anzaki

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>
---
 net/mac80211/sta_info.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 2b5acb37587f..35fb885040b1 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -640,12 +640,14 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
 
 	/* check if STA exists already */
 	if (sta_info_get_bss(sdata, sta->sta.addr)) {
+		sta_info_free(local, sta);
 		err = -EEXIST;
 		goto out_err;
 	}
 
 	sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
 	if (!sinfo) {
+		sta_info_free(local, sta);
 		err = -ENOMEM;
 		goto out_err;
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mac80211: fix a memory leak where sta_info is not freed
  2021-10-02 14:53 [PATCH] mac80211: fix a memory leak where sta_info is not freed Ahmed Zaki
@ 2021-11-15 10:06 ` Johannes Berg
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Berg @ 2021-11-15 10:06 UTC (permalink / raw)
  To: Ahmed Zaki; +Cc: linux-wireless

On Sat, 2021-10-02 at 08:53 -0600, Ahmed Zaki wrote:
> 
> +++ b/net/mac80211/sta_info.c
> @@ -640,12 +640,14 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
>  
>  	/* check if STA exists already */
>  	if (sta_info_get_bss(sdata, sta->sta.addr)) {
> +		sta_info_free(local, sta);
>  		err = -EEXIST;
>  		goto out_err;
>  	}
>  
>  	sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
>  	if (!sinfo) {
> +		sta_info_free(local, sta);
>  		err = -ENOMEM;
>  		goto out_err;
>  	}

We already have a "out_drop_sta", that calls cleanup_single_sta(), so
shouldn't we just add a label there ("out_free_sta") just before
cleanup_single_sta() and then we don't need the extra call?

johannes

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-15 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-02 14:53 [PATCH] mac80211: fix a memory leak where sta_info is not freed Ahmed Zaki
2021-11-15 10:06 ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).