public inbox for linux-wireless@vger.kernel.org
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: kvalo@codeaurora.org, davem@davemloft.net,
	gregkh@linuxfoundation.org, allison@lohutok.net,
	saurav.girepunje@gmail.com, tglx@linutronix.de, will@kernel.org
Cc: linux-wireless@vger.kernel.org, b43-dev@lists.infradead.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] b43: Fix possible a data race in b43_op_tx()
Date: Sun, 12 Jan 2020 00:14:55 +0800	[thread overview]
Message-ID: <20200111161455.26587-1-baijiaju1990@gmail.com> (raw)

The functions b43_op_tx() and b43_tx_work() may be concurrently executed.

In b43_tx_work(), the variable wl->tx_queue_stopped[queue_num] is
accessed with holding a mutex lock wl->mutex. But in b43_op_tx(), the
identical variable wl->tx_queue_stopped[skb->queue_mapping] is accessed
without holding this mutex lock. Thus, a possible data race may occur.

To fix this data race, in b43_op_tx(), the variable 
wl->tx_queue_stopped[skb->queue_mapping] is accessed with holding the 
mutex lock wl->mutex.

This data race is found by the runtime testing of our tool DILP-2.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/net/wireless/broadcom/b43/main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/b43/main.c b/drivers/net/wireless/broadcom/b43/main.c
index 39da1a4c30ac..adedb38f50f2 100644
--- a/drivers/net/wireless/broadcom/b43/main.c
+++ b/drivers/net/wireless/broadcom/b43/main.c
@@ -3625,6 +3625,11 @@ static void b43_op_tx(struct ieee80211_hw *hw,
 		      struct sk_buff *skb)
 {
 	struct b43_wl *wl = hw_to_b43_wl(hw);
+	bool stopped;
+
+	mutex_lock(&wl->mutex);
+	stopped = wl->tx_queue_stopped[skb->queue_mapping];
+	mutex_unlock(&wl->mutex);
 
 	if (unlikely(skb->len < 2 + 2 + 6)) {
 		/* Too short, this can't be a valid frame. */
@@ -3634,7 +3639,7 @@ static void b43_op_tx(struct ieee80211_hw *hw,
 	B43_WARN_ON(skb_shinfo(skb)->nr_frags);
 
 	skb_queue_tail(&wl->tx_queue[skb->queue_mapping], skb);
-	if (!wl->tx_queue_stopped[skb->queue_mapping]) {
+	if (!stopped) {
 		ieee80211_queue_work(wl->hw, &wl->tx_work);
 	} else {
 		ieee80211_stop_queue(wl->hw, skb->queue_mapping);
-- 
2.17.1


             reply	other threads:[~2020-01-11 16:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-11 16:14 Jia-Ju Bai [this message]
2020-01-11 17:15 ` [PATCH] b43: Fix possible a data race in b43_op_tx() Michael Büsch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200111161455.26587-1-baijiaju1990@gmail.com \
    --to=baijiaju1990@gmail.com \
    --cc=allison@lohutok.net \
    --cc=b43-dev@lists.infradead.org \
    --cc=davem@davemloft.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=saurav.girepunje@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox