marvell: mwifiex: two possible ABBA deadlocks
Subsystems (3)
Hello,
My static analysis tool reports two possible ABBA deadlocks in the mwifiex driver in Linux 5.10:
# DEADLOCK 1:mwifiex_dequeue_tx_packet() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 1432 (Lock A) mwifiex_send_addba() spin_lock_bh(&priv->sta_list_spinlock); --> Line 608 (Lock B)
mwifiex_process_sta_tx_pause() spin_lock_bh(&priv->sta_list_spinlock); --> Line 398 (Lock B) mwifiex_update_ralist_tx_pause() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 941 (Lock A)
When mwifiex_dequeue_tx_packet() and mwifiex_process_sta_tx_pause() are concurrently executed, the deadlock can occur.
# DEADLOCK 2:mwifiex_dequeue_tx_packet() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 1432 (Lock A) mwifiex_send_addba() spin_lock_bh(&priv->sta_list_spinlock); --> Line 608 (Lock B)
mwifiex_process_uap_tx_pause() spin_lock_bh(&priv->sta_list_spinlock); --> Line 363 (Lock B) mwifiex_update_ralist_tx_pause() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 941 (Lock A)
When mwifiex_dequeue_tx_packet() and mwifiex_process_uap_tx_pause() are concurrently executed, the deadlock can occur.
I am not quite sure whether these possible deadlocks are real and how to fix them if they are real. Any feedback would be appreciated, thanks :)
Best wishes,
Jia-Ju Bai
Brian Norris
maintainerPATCH 1/1 mwifiex: Fix possible ABBA deadlock
Quoting Jia-Ju Bai <[email protected]>:
mwifiex_dequeue_tx_packet()
spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 1432 (Lock A)
mwifiex_send_addba()
spin_lock_bh(&priv->sta_list_spinlock); --> Line 608 (Lock B) mwifiex_process_sta_tx_pause()
spin_lock_bh(&priv->sta_list_spinlock); --> Line 398 (Lock B)
mwifiex_update_ralist_tx_pause()
spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 941 (Lock A)Similar report for mwifiex_process_uap_tx_pause().
While the locking expectations in this driver are a bit unclear, the Fixed commit only intended to protect the sta_ptr, so we can drop the lock as soon as we're done with it.
IIUC, this deadlock cannot actually happen, because command event processing (which calls mwifiex_process_sta_tx_pause()) is sequentialized with TX packet processing (e.g., mwifiex_dequeue_tx_packet()) via the main loop (mwifiex_main_process()). But it's good not to leave this potential issue lurking.
---
Quoted 3 lines · Jia-Ju Bai
I am not quite sure whether these possible deadlocks are real and how to fix them if they are real.
Any feedback would be appreciated, thanks :)
I think these are at least theoretically real, and so we should take something like the $subject patch probably. But I don't believe we can actually hit this due to the main-loop structure of this driver.
Anyway, see the surrounding patch.
Thanks,
Brian
drivers/net/wireless/marvell/mwifiex/sta_event.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/sta_event.c +6 -2
@@ -365,10 +365,12 @@ static void mwifiex_process_uap_tx_pause(struct mwifiex_private *priv, sta_ptr =mwifiex_get_sta_entry (priv, tp->peermac);if (sta_ptr && sta_ptr->tx_pause != tp->tx_pause) { sta_ptr->tx_pause = tp->tx_pause; +spin_unlock_bh (&priv->sta_list_spinlock);mwifiex_update_ralist_tx_pause (priv, tp->peermac, tp->tx_pause); + }else { +spin_unlock_bh (&priv->sta_list_spinlock); } -spin_unlock_bh (&priv->sta_list_spinlock); } }
@@ -400,11 +402,13 @@ static void mwifiex_process_sta_tx_pause(struct mwifiex_private *priv, sta_ptr =mwifiex_get_sta_entry (priv, tp->peermac);if (sta_ptr && sta_ptr->tx_pause != tp->tx_pause) { sta_ptr->tx_pause = tp->tx_pause; +spin_unlock_bh (&priv->sta_list_spinlock);mwifiex_update_ralist_tx_pause (priv, tp->peermac, tp->tx_pause); + }else { +spin_unlock_bh (&priv->sta_list_spinlock); } -spin_unlock_bh (&priv->sta_list_spinlock); } } }
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
Re: [PATCH] mwifiex: Fix possible ABBA deadlock
Hi Brian,
Thanks for your reply and explanation!
The patch looks good to me :)
Best wishes,
Jia-Ju Bai
Quoted 81 lines · Brian Norris
Quoting Jia-Ju Bai <[email protected]>:
mwifiex_dequeue_tx_packet() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 1432 (Lock A) mwifiex_send_addba() spin_lock_bh(&priv->sta_list_spinlock); --> Line 608 (Lock B) mwifiex_process_sta_tx_pause() spin_lock_bh(&priv->sta_list_spinlock); --> Line 398 (Lock B) mwifiex_update_ralist_tx_pause() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 941 (Lock A)Similar report for
mwifiex_process_uap_tx_pause().While the locking expectations in this driver are a bit unclear, the Fixed commit only intended to protect the
sta_ptr, so we can drop the lock as soon as we're done with it.IIUC, this deadlock cannot actually happen, because command event processing (which calls
mwifiex_process_sta_tx_pause()) is sequentialized with TX packet processing (e.g.,mwifiex_dequeue_tx_packet()) via the main loop (mwifiex_main_process()). But it's good not to leave this potential issue lurking.Fixes ("f0f7c2275fb9 mwifiex: minor cleanups w/ sta_list_spinlock in cfg80211.c")Cc Douglas Anderson <[email protected]>Reported-by TOTE Robot <[email protected]>Signed-off-by Brian Norris <[email protected]>---
Quoted 3 lines · Jia-Ju Bai
I am not quite sure whether these possible deadlocks are real and how to fix them if they are real.
Any feedback would be appreciated, thanks :)I think these are at least theoretically real, and so we should take something like the $subject patch probably. But I don't believe we can actually hit this due to the main-loop structure of this driver.
Anyway, see the surrounding patch.
Thanks,
Briandrivers/net/wireless/marvell/mwifiex/sta_event.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/net/wireless/marvell/mwifiex/sta_event.c +6
-2@@ -365,10 +365,12 @@ static void mwifiex_process_uap_tx_pause(struct mwifiex_private *priv, sta_ptr =mwifiex_get_sta_entry (priv, tp->peermac);if (sta_ptr && sta_ptr->tx_pause != tp->tx_pause) { sta_ptr->tx_pause = tp->tx_pause; +spin_unlock_bh (&priv->sta_list_spinlock);mwifiex_update_ralist_tx_pause (priv, tp->peermac, tp->tx_pause); + }else { +spin_unlock_bh (&priv->sta_list_spinlock); } -spin_unlock_bh (&priv->sta_list_spinlock); } }@@ -400,11 +402,13 @@ static void mwifiex_process_sta_tx_pause(struct mwifiex_private *priv, sta_ptr =mwifiex_get_sta_entry (priv, tp->peermac);if (sta_ptr && sta_ptr->tx_pause != tp->tx_pause) { sta_ptr->tx_pause = tp->tx_pause; +spin_unlock_bh (&priv->sta_list_spinlock);mwifiex_update_ralist_tx_pause (priv, tp->peermac, tp->tx_pause); + }else { +spin_unlock_bh (&priv->sta_list_spinlock); } -spin_unlock_bh (&priv->sta_list_spinlock); } } }
Re: [PATCH] mwifiex: Fix possible ABBA deadlock
In reply to Brian NorrisHi,
Quoted 41 lines · Brian Norris
Quoting Jia-Ju Bai <[email protected]>:
mwifiex_dequeue_tx_packet()spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 1432 (Lock A) mwifiex_send_addba() spin_lock_bh(&priv->sta_list_spinlock); --> Line 608 (Lock B)
mwifiex_process_sta_tx_pause()spin_lock_bh(&priv->sta_list_spinlock); --> Line 398 (Lock B) mwifiex_update_ralist_tx_pause() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 941 (Lock A)Similar report for
mwifiex_process_uap_tx_pause().While the locking expectations in this driver are a bit unclear, the Fixed commit only intended to protect the
sta_ptr, so we can drop the lock as soon as we're done with it.IIUC, this deadlock cannot actually happen, because command event processing (which calls
mwifiex_process_sta_tx_pause()) is sequentialized with TX packet processing (e.g.,mwifiex_dequeue_tx_packet()) via the main loop (mwifiex_main_process()). But it's good not to leave this potential issue lurking.Fixes ("f0f7c2275fb9 mwifiex: minor cleanups w/ sta_list_spinlock in cfg80211.c")Cc Douglas Anderson <[email protected]>Reported-by TOTE Robot <[email protected]>Signed-off-by Brian Norris <[email protected]>---
Quoted 3 lines · Jia-Ju Bai
I am not quite sure whether these possible deadlocks are real and how to fix them if they are real.
Any feedback would be appreciated, thanks :)I think these are at least theoretically real, and so we should take something like the $subject patch probably. But I don't believe we can actually hit this due to the main-loop structure of this driver.
Quoted 8 lines
Anyway, see the surrounding patch.
Thanks,
Briandrivers/net/wireless/marvell/mwifiex/sta_event.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Though I'm by no means an expert on this code and I wrote the patch in question a long time ago, this seems reasonable to me. Thanks for fixing.
Re: [PATCH] mwifiex: Fix possible ABBA deadlock
In reply to Brian NorrisQuoted 24 lines · Brian Norris
Quoting Jia-Ju Bai <[email protected]>:
mwifiex_dequeue_tx_packet()spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 1432 (Lock A) mwifiex_send_addba() spin_lock_bh(&priv->sta_list_spinlock); --> Line 608 (Lock B)
mwifiex_process_sta_tx_pause()spin_lock_bh(&priv->sta_list_spinlock); --> Line 398 (Lock B) mwifiex_update_ralist_tx_pause() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 941 (Lock A)Similar report for
mwifiex_process_uap_tx_pause().While the locking expectations in this driver are a bit unclear, the Fixed commit only intended to protect the
sta_ptr, so we can drop the lock as soon as we're done with it.IIUC, this deadlock cannot actually happen, because command event processing (which calls
mwifiex_process_sta_tx_pause()) is sequentialized with TX packet processing (e.g.,mwifiex_dequeue_tx_packet()) via the main loop (mwifiex_main_process()). But it's good not to leave this potential issue lurking.
Quoted 6 lines
Fixes ("f0f7c2275fb9 mwifiex: minor cleanups w/ sta_list_spinlock in cfg80211.c")Cc Douglas Anderson <[email protected]>Reported-by TOTE Robot <[email protected]>Signed-off-by Brian Norris <[email protected]>Reviewed-by Douglas Anderson <[email protected]>
Fixes tag is in wrong format, should be:
I'll fix it during commit.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/YaV0pllJ5p/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Re: mwifiex: Fix possible ABBA deadlock
In reply to Brian NorrisQuoted 24 lines · Brian Norris
Quoting Jia-Ju Bai <[email protected]>:
mwifiex_dequeue_tx_packet()spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 1432 (Lock A) mwifiex_send_addba() spin_lock_bh(&priv->sta_list_spinlock); --> Line 608 (Lock B)
mwifiex_process_sta_tx_pause()spin_lock_bh(&priv->sta_list_spinlock); --> Line 398 (Lock B) mwifiex_update_ralist_tx_pause() spin_lock_bh(&priv->wmm.ra_list_spinlock); --> Line 941 (Lock A)Similar report for
mwifiex_process_uap_tx_pause().While the locking expectations in this driver are a bit unclear, the Fixed commit only intended to protect the
sta_ptr, so we can drop the lock as soon as we're done with it.IIUC, this deadlock cannot actually happen, because command event processing (which calls
mwifiex_process_sta_tx_pause()) is sequentialized with TX packet processing (e.g.,mwifiex_dequeue_tx_packet()) via the main loop (mwifiex_main_process()). But it's good not to leave this potential issue lurking.
Quoted 6 lines
Fixes f0f7c2275fb9 ("mwifiex: minor cleanups w/ sta_list_spinlock in cfg80211.c")Cc Douglas Anderson <[email protected]>Reported-by TOTE Robot <[email protected]>Signed-off-by Brian Norris <[email protected]>Reviewed-by Douglas Anderson <[email protected]>
Patch applied to wireless-drivers-next.git, thanks.
1b8bb8919ef8 mwifiex: Fix possible ABBA deadlock
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/YaV0pllJ5p/[email protected]/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches