Skip to content

Commit 02df7c6

Browse files
Jminugregkh
authored andcommitted
staging: rtl8723bs: fix potential race in expire_timeout_chk
The expire_timeout_chk function currently do lock and unlock inside the loop before calling rtw_free_stainfo(). This can be risky as the list might be changed when the lock is briefly released. To fix this, move expired sta_info entries into a local free_list while holding the lock, and then perform the actual freeing after the lock is released. Signed-off-by: Minu Jin <s9430939@naver.com> Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://patch.msgid.link/20260131171153.3729458-1-s9430939@naver.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8ae0398 commit 02df7c6

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

drivers/staging/rtl8723bs/core/rtw_ap.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ void expire_timeout_chk(struct adapter *padapter)
178178
struct sta_priv *pstapriv = &padapter->stapriv;
179179
u8 chk_alive_num = 0;
180180
char chk_alive_list[NUM_STA];
181+
struct sta_info *psta_tmp;
182+
LIST_HEAD(free_list);
181183
int i;
182184

183185
spin_lock_bh(&pstapriv->auth_list_lock);
@@ -190,19 +192,19 @@ void expire_timeout_chk(struct adapter *padapter)
190192
if (psta->expire_to > 0) {
191193
psta->expire_to--;
192194
if (psta->expire_to == 0) {
193-
list_del_init(&psta->auth_list);
195+
list_move(&psta->auth_list, &free_list);
194196
pstapriv->auth_list_cnt--;
195-
196-
spin_unlock_bh(&pstapriv->auth_list_lock);
197-
198-
rtw_free_stainfo(padapter, psta);
199-
200-
spin_lock_bh(&pstapriv->auth_list_lock);
201197
}
202198
}
203199
}
204200

205201
spin_unlock_bh(&pstapriv->auth_list_lock);
202+
203+
list_for_each_entry_safe(psta, psta_tmp, &free_list, auth_list) {
204+
list_del_init(&psta->auth_list);
205+
rtw_free_stainfo(padapter, psta);
206+
}
207+
206208
psta = NULL;
207209

208210
spin_lock_bh(&pstapriv->asoc_list_lock);

0 commit comments

Comments
 (0)