ff3cb7be532cc0f0c9bced894da163a84ba1aad0
[openwrt/staging/hauke.git] /
1 From 4db561ae4a90c2d0e15996634567559e292dc9e5 Mon Sep 17 00:00:00 2001
2 From: Ahmed Zaki <anzaki@gmail.com>
3 Date: Sat, 2 Oct 2021 08:53:29 -0600
4 Subject: [PATCH] mac80211: fix a memory leak where sta_info is not freed
5
6 commit 8f9dcc29566626f683843ccac6113a12208315ca upstream.
7
8 The following is from a system that went OOM due to a memory leak:
9
10 wlan0: Allocated STA 74:83:c2:64:0b:87
11 wlan0: Allocated STA 74:83:c2:64:0b:87
12 wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_add_sta)
13 wlan0: Adding new IBSS station 74:83:c2:64:0b:87
14 wlan0: moving STA 74:83:c2:64:0b:87 to state 2
15 wlan0: moving STA 74:83:c2:64:0b:87 to state 3
16 wlan0: Inserted STA 74:83:c2:64:0b:87
17 wlan0: IBSS finish 74:83:c2:64:0b:87 (---from ieee80211_ibss_work)
18 wlan0: Adding new IBSS station 74:83:c2:64:0b:87
19 wlan0: moving STA 74:83:c2:64:0b:87 to state 2
20 wlan0: moving STA 74:83:c2:64:0b:87 to state 3
21 .
22 .
23 wlan0: expiring inactive not authorized STA 74:83:c2:64:0b:87
24 wlan0: moving STA 74:83:c2:64:0b:87 to state 2
25 wlan0: moving STA 74:83:c2:64:0b:87 to state 1
26 wlan0: Removed STA 74:83:c2:64:0b:87
27 wlan0: Destroyed STA 74:83:c2:64:0b:87
28
29 The ieee80211_ibss_finish_sta() is called twice on the same STA from 2
30 different locations. On the second attempt, the allocated STA is not
31 destroyed creating a kernel memory leak.
32
33 This is happening because sta_info_insert_finish() does not call
34 sta_info_free() the second time when the STA already exists (returns
35 -EEXIST). Note that the caller sta_info_insert_rcu() assumes STA is
36 destroyed upon errors.
37
38 Same fix is applied to -ENOMEM.
39
40 Signed-off-by: Ahmed Zaki <anzaki@gmail.com>
41 Link: https://lore.kernel.org/r/20211002145329.3125293-1-anzaki@gmail.com
42 [change the error path label to use the existing code]
43 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
44 Signed-off-by: Viacheslav Sablin <sablin@ispras.ru>
45 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
46 ---
47 net/mac80211/sta_info.c | 6 +++---
48 1 file changed, 3 insertions(+), 3 deletions(-)
49
50 --- a/net/mac80211/sta_info.c
51 +++ b/net/mac80211/sta_info.c
52 @@ -646,13 +646,13 @@ static int sta_info_insert_finish(struct
53 /* check if STA exists already */
54 if (sta_info_get_bss(sdata, sta->sta.addr)) {
55 err = -EEXIST;
56 - goto out_err;
57 + goto out_cleanup;
58 }
59
60 sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
61 if (!sinfo) {
62 err = -ENOMEM;
63 - goto out_err;
64 + goto out_cleanup;
65 }
66
67 local->num_sta++;
68 @@ -708,8 +708,8 @@ static int sta_info_insert_finish(struct
69 out_drop_sta:
70 local->num_sta--;
71 synchronize_net();
72 + out_cleanup:
73 cleanup_single_sta(sta);
74 - out_err:
75 mutex_unlock(&local->sta_mtx);
76 kfree(sinfo);
77 rcu_read_lock();