All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.10 0/1] mac80211: fix a memory leak where sta_info is not freed
@ 2022-08-09 16:02 Viacheslav Sablin
  2022-08-09 16:02 ` [PATCH 5.10 1/1] " Viacheslav Sablin
  0 siblings, 1 reply; 3+ messages in thread
From: Viacheslav Sablin @ 2022-08-09 16:02 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: Viacheslav Sablin, Ahmed Zaki, Johannes Berg, Alexey Khoroshilov,
	ldv-project

Syzkaller reports memory leak issue at ieee80211_ibss_rx_no_sta() 
in 5.10 stable releases. The problem has been fixed by the following patch 
which can be cleanly applied to the 5.10 branch.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

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

* [PATCH 5.10 1/1] mac80211: fix a memory leak where sta_info is not freed
  2022-08-09 16:02 [PATCH 5.10 0/1] mac80211: fix a memory leak where sta_info is not freed Viacheslav Sablin
@ 2022-08-09 16:02 ` Viacheslav Sablin
  2022-08-15 13:01   ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Viacheslav Sablin @ 2022-08-09 16:02 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: Viacheslav Sablin, Ahmed Zaki, Johannes Berg, Alexey Khoroshilov,
	ldv-project

From: Ahmed Zaki <anzaki@gmail.com>

commit 8f9dcc29566626f683843ccac6113a12208315ca upstream.

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>
Signed-off-by: Viacheslav Sablin <sablin@ispras.ru>
---
 net/mac80211/sta_info.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index e18c3855f616..461c03737da8 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -645,13 +645,13 @@ 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)) {
 		err = -EEXIST;
-		goto out_err;
+		goto out_cleanup;
 	}
 
 	sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
 	if (!sinfo) {
 		err = -ENOMEM;
-		goto out_err;
+		goto out_cleanup;
 	}
 
 	local->num_sta++;
@@ -707,8 +707,8 @@ static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
  out_drop_sta:
 	local->num_sta--;
 	synchronize_net();
+ out_cleanup:
 	cleanup_single_sta(sta);
- out_err:
 	mutex_unlock(&local->sta_mtx);
 	kfree(sinfo);
 	rcu_read_lock();
-- 
2.30.2


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

* Re: [PATCH 5.10 1/1] mac80211: fix a memory leak where sta_info is not freed
  2022-08-09 16:02 ` [PATCH 5.10 1/1] " Viacheslav Sablin
@ 2022-08-15 13:01   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-08-15 13:01 UTC (permalink / raw)
  To: Viacheslav Sablin
  Cc: stable, Ahmed Zaki, Johannes Berg, Alexey Khoroshilov,
	ldv-project

On Tue, Aug 09, 2022 at 07:02:45PM +0300, Viacheslav Sablin wrote:
> From: Ahmed Zaki <anzaki@gmail.com>
> 
> commit 8f9dcc29566626f683843ccac6113a12208315ca upstream.
> 
> 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>
> Signed-off-by: Viacheslav Sablin <sablin@ispras.ru>
> ---
>  net/mac80211/sta_info.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

This is also needed in 5.15.y, so added there as well.  thanks,

greg k-h

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

end of thread, other threads:[~2022-08-15 13:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-09 16:02 [PATCH 5.10 0/1] mac80211: fix a memory leak where sta_info is not freed Viacheslav Sablin
2022-08-09 16:02 ` [PATCH 5.10 1/1] " Viacheslav Sablin
2022-08-15 13:01   ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.