* [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk @ 2026-01-27 13:10 Minu Jin 2026-01-27 14:15 ` Greg KH 2026-01-28 11:38 ` Dan Carpenter 0 siblings, 2 replies; 4+ messages in thread From: Minu Jin @ 2026-01-27 13:10 UTC (permalink / raw) To: gregkh Cc: bqn9090, dan.carpenter, abrahamadekunle50, straube.linux, bryant.boatright, davidzalman.101, linux-staging, linux-kernel, Minu Jin 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> --- Hi, I noticed this lock-unlock pattern in expire_timeout_chk() while studying the code and it looked like a potential race condition. I've refactored the code to use a local list so we can handle the cleanup after releasing the lock. What do you think about this approach? Any feedback is appreciated. drivers/staging/rtl8723bs/core/rtw_ap.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c index 67197c7d4a4d..5947f6363ab0 100644 --- a/drivers/staging/rtl8723bs/core/rtw_ap.c +++ b/drivers/staging/rtl8723bs/core/rtw_ap.c @@ -179,6 +179,9 @@ void expire_timeout_chk(struct adapter *padapter) u8 chk_alive_num = 0; char chk_alive_list[NUM_STA]; int i; + struct list_head free_list; + + INIT_LIST_HEAD(&free_list); spin_lock_bh(&pstapriv->auth_list_lock); @@ -190,19 +193,21 @@ void expire_timeout_chk(struct adapter *padapter) if (psta->expire_to > 0) { psta->expire_to--; if (psta->expire_to == 0) { - list_del_init(&psta->auth_list); + list_move(&psta->auth_list, &free_list); pstapriv->auth_list_cnt--; - - spin_unlock_bh(&pstapriv->auth_list_lock); - - rtw_free_stainfo(padapter, psta); - - spin_lock_bh(&pstapriv->auth_list_lock); } } } spin_unlock_bh(&pstapriv->auth_list_lock); + + /* free free_list */ + list_for_each_safe(plist, tmp, &free_list) { + psta = list_entry(plist, struct sta_info, auth_list); + list_del_init(&psta->auth_list); + rtw_free_stainfo(padapter, psta); + } + psta = NULL; spin_lock_bh(&pstapriv->asoc_list_lock); -- 2.43.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk 2026-01-27 13:10 [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk Minu Jin @ 2026-01-27 14:15 ` Greg KH 2026-01-27 17:05 ` Minu Jin 2026-01-28 11:38 ` Dan Carpenter 1 sibling, 1 reply; 4+ messages in thread From: Greg KH @ 2026-01-27 14:15 UTC (permalink / raw) To: Minu Jin Cc: bqn9090, dan.carpenter, abrahamadekunle50, straube.linux, bryant.boatright, davidzalman.101, linux-staging, linux-kernel On Tue, Jan 27, 2026 at 10:10:35PM +0900, Minu Jin wrote: > 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> > --- > Hi, > > I noticed this lock-unlock pattern in expire_timeout_chk() while > studying the code and it looked like a potential race condition. > > I've refactored the code to use a local list so we can handle the > cleanup after releasing the lock. What do you think about this approach? > > Any feedback is appreciated. > > drivers/staging/rtl8723bs/core/rtw_ap.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c > index 67197c7d4a4d..5947f6363ab0 100644 > --- a/drivers/staging/rtl8723bs/core/rtw_ap.c > +++ b/drivers/staging/rtl8723bs/core/rtw_ap.c > @@ -179,6 +179,9 @@ void expire_timeout_chk(struct adapter *padapter) > u8 chk_alive_num = 0; > char chk_alive_list[NUM_STA]; > int i; > + struct list_head free_list; > + > + INIT_LIST_HEAD(&free_list); > > spin_lock_bh(&pstapriv->auth_list_lock); > > @@ -190,19 +193,21 @@ void expire_timeout_chk(struct adapter *padapter) > if (psta->expire_to > 0) { > psta->expire_to--; > if (psta->expire_to == 0) { > - list_del_init(&psta->auth_list); > + list_move(&psta->auth_list, &free_list); > pstapriv->auth_list_cnt--; > - > - spin_unlock_bh(&pstapriv->auth_list_lock); > - > - rtw_free_stainfo(padapter, psta); > - > - spin_lock_bh(&pstapriv->auth_list_lock); > } > } > } > > spin_unlock_bh(&pstapriv->auth_list_lock); > + > + /* free free_list */ > + list_for_each_safe(plist, tmp, &free_list) { > + psta = list_entry(plist, struct sta_info, auth_list); > + list_del_init(&psta->auth_list); > + rtw_free_stainfo(padapter, psta); > + } Looks sane, can you test it to verify it works properly? thanks, greg k-h ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk 2026-01-27 14:15 ` Greg KH @ 2026-01-27 17:05 ` Minu Jin 0 siblings, 0 replies; 4+ messages in thread From: Minu Jin @ 2026-01-27 17:05 UTC (permalink / raw) To: Greg KH Cc: bqn9090, dan.carpenter, abrahamadekunle50, straube.linux, bryant.boatright, davidzalman.101, linux-staging, linux-kernel, hansg On Tue, Jan 27, 2026 at 03:15:24PM +0100, Greg KH wrote: > On Tue, Jan 27, 2026 at 10:10:35PM +0900, Minu Jin wrote: > > 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> > > --- > > Hi, > > > > I noticed this lock-unlock pattern in expire_timeout_chk() while > > studying the code and it looked like a potential race condition. > > > > I've refactored the code to use a local list so we can handle the > > cleanup after releasing the lock. What do you think about this approach? > > > > Any feedback is appreciated. > > > > drivers/staging/rtl8723bs/core/rtw_ap.c | 19 ++++++++++++------- > > 1 file changed, 12 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c > > index 67197c7d4a4d..5947f6363ab0 100644 > > --- a/drivers/staging/rtl8723bs/core/rtw_ap.c > > +++ b/drivers/staging/rtl8723bs/core/rtw_ap.c > > @@ -179,6 +179,9 @@ void expire_timeout_chk(struct adapter *padapter) > > u8 chk_alive_num = 0; > > char chk_alive_list[NUM_STA]; > > int i; > > + struct list_head free_list; > > + > > + INIT_LIST_HEAD(&free_list); > > > > spin_lock_bh(&pstapriv->auth_list_lock); > > > > @@ -190,19 +193,21 @@ void expire_timeout_chk(struct adapter *padapter) > > if (psta->expire_to > 0) { > > psta->expire_to--; > > if (psta->expire_to == 0) { > > - list_del_init(&psta->auth_list); > > + list_move(&psta->auth_list, &free_list); > > pstapriv->auth_list_cnt--; > > - > > - spin_unlock_bh(&pstapriv->auth_list_lock); > > - > > - rtw_free_stainfo(padapter, psta); > > - > > - spin_lock_bh(&pstapriv->auth_list_lock); > > } > > } > > } > > > > spin_unlock_bh(&pstapriv->auth_list_lock); > > + > > + /* free free_list */ > > + list_for_each_safe(plist, tmp, &free_list) { > > + psta = list_entry(plist, struct sta_info, auth_list); > > + list_del_init(&psta->auth_list); > > + rtw_free_stainfo(padapter, psta); > > + } > > Looks sane, can you test it to verify it works properly? > > thanks, > > greg k-h Hi Greg, Thanks for the review. I have verified the patch with Smatch and performed build tests it does not produce any errors or warnings. About the runtime test, I have analyzed the logic as follows: Within the first loop, expired entries are simply moved to a local free_list. Since we no longer release and re-acquire the lock inside this loop, the integrity of the shared auth_list is perfectly preserved while iterating. The actual cleanup (rtw_free_stainfo) is performed only after all entries have been isolated into the local list and the lock has been released. While I don't have the physical hardware to verify this myself, I noticed that Hans de Goede has a working test environment for this driver. I've added him to the CC list and would be very grateful if he or anyone else with the hardware could give this a quick test. Minu Jin ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk 2026-01-27 13:10 [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk Minu Jin 2026-01-27 14:15 ` Greg KH @ 2026-01-28 11:38 ` Dan Carpenter 1 sibling, 0 replies; 4+ messages in thread From: Dan Carpenter @ 2026-01-28 11:38 UTC (permalink / raw) To: Minu Jin Cc: gregkh, bqn9090, abrahamadekunle50, straube.linux, bryant.boatright, davidzalman.101, linux-staging, linux-kernel On Tue, Jan 27, 2026 at 10:10:35PM +0900, Minu Jin wrote: > 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> > --- > Hi, > > I noticed this lock-unlock pattern in expire_timeout_chk() while > studying the code and it looked like a potential race condition. > > I've refactored the code to use a local list so we can handle the > cleanup after releasing the lock. What do you think about this approach? > > Any feedback is appreciated. > > drivers/staging/rtl8723bs/core/rtw_ap.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c > index 67197c7d4a4d..5947f6363ab0 100644 > --- a/drivers/staging/rtl8723bs/core/rtw_ap.c > +++ b/drivers/staging/rtl8723bs/core/rtw_ap.c > @@ -179,6 +179,9 @@ void expire_timeout_chk(struct adapter *padapter) > u8 chk_alive_num = 0; > char chk_alive_list[NUM_STA]; > int i; > + struct list_head free_list; > + > + INIT_LIST_HEAD(&free_list); A couple minor style nits. Use LIST_HEAD(free_list) to do this in the initializer. > > spin_lock_bh(&pstapriv->auth_list_lock); > > @@ -190,19 +193,21 @@ void expire_timeout_chk(struct adapter *padapter) > if (psta->expire_to > 0) { > psta->expire_to--; > if (psta->expire_to == 0) { > - list_del_init(&psta->auth_list); > + list_move(&psta->auth_list, &free_list); > pstapriv->auth_list_cnt--; > - > - spin_unlock_bh(&pstapriv->auth_list_lock); > - > - rtw_free_stainfo(padapter, psta); > - > - spin_lock_bh(&pstapriv->auth_list_lock); > } > } > } > > spin_unlock_bh(&pstapriv->auth_list_lock); > + > + /* free free_list */ Delete this comment. It's obvious. > + list_for_each_safe(plist, tmp, &free_list) { Use list_for_each_entry_safe(). regards, dan carpenter > + psta = list_entry(plist, struct sta_info, auth_list); > + list_del_init(&psta->auth_list); > + rtw_free_stainfo(padapter, psta); > + } > + > psta = NULL; ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-28 11:38 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-01-27 13:10 [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk Minu Jin 2026-01-27 14:15 ` Greg KH 2026-01-27 17:05 ` Minu Jin 2026-01-28 11:38 ` Dan Carpenter
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox