From: Tuo Li <islituo@gmail.com>
To: srini.raju@purelifi.com, kvalo@kernel.org
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
baijiaju1990@outlook.com, Tuo Li <islituo@gmail.com>,
BassCheck <bass@buaa.edu.cn>
Subject: [PATCH] wifi: plfxlc: Fix possible data races in rx_urb_complete()
Date: Wed, 28 Jun 2023 10:21:21 +0800 [thread overview]
Message-ID: <20230628022121.1010517-1-islituo@gmail.com> (raw)
The variable tx->submitted_urbs is often protected by the lock tx->lock
when is accessed. Here is an example in plfxlc_usb_disable_tx():
spin_lock_irqsave(&tx->lock, flags);
WARN_ON(!skb_queue_empty(&tx->submitted_skbs));
WARN_ON(tx->submitted_urbs != 0);
tx->submitted_urbs = 0;
spin_unlock_irqrestore(&tx->lock, flags);
However, it is accessed without holding the lock tx->lock in
rx_urb_complete():
if (tx->submitted_urbs++ < PURELIFI_URB_RETRY_MAX) --> Line 108
tx->submitted_urbs++ --> Line 110
tx->submitted_urbs = 0 --> Line 114
And thus data races can occur.
To fix these possible data races, a lock and unlock pair is added when
accessing the variable tx->submitted_urbs in rx_urb_complete().
Reported-by: BassCheck <bass@buaa.edu.cn>
Signed-off-by: Tuo Li <islituo@gmail.com>
---
drivers/net/wireless/purelifi/plfxlc/usb.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/net/wireless/purelifi/plfxlc/usb.c b/drivers/net/wireless/purelifi/plfxlc/usb.c
index 76d0a778636a..44152a615c0e 100644
--- a/drivers/net/wireless/purelifi/plfxlc/usb.c
+++ b/drivers/net/wireless/purelifi/plfxlc/usb.c
@@ -69,6 +69,7 @@ static void handle_rx_packet(struct plfxlc_usb *usb, const u8 *buffer,
static void rx_urb_complete(struct urb *urb)
{
struct plfxlc_usb_tx *tx;
+ unsigned long flags;
struct plfxlc_usb *usb;
unsigned int length;
const u8 *buffer;
@@ -105,13 +106,16 @@ static void rx_urb_complete(struct urb *urb)
return;
default:
dev_dbg(plfxlc_urb_dev(urb), "urb %p error %d\n", urb, urb->status);
+ spin_lock_irqsave(&tx->lock, flags);
if (tx->submitted_urbs++ < PURELIFI_URB_RETRY_MAX) {
dev_dbg(plfxlc_urb_dev(urb), "urb %p resubmit %d", urb,
tx->submitted_urbs++);
+ spin_unlock_irqrestore(&tx->lock, flags);
goto resubmit;
} else {
dev_dbg(plfxlc_urb_dev(urb), "urb %p max resubmits reached", urb);
tx->submitted_urbs = 0;
+ spin_unlock_irqrestore(&tx->lock, flags);
return;
}
}
--
2.34.1
next reply other threads:[~2023-06-28 2:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-28 2:21 Tuo Li [this message]
2023-06-28 4:54 ` [PATCH] wifi: plfxlc: Fix possible data races in rx_urb_complete() Dmitry Antipov
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=20230628022121.1010517-1-islituo@gmail.com \
--to=islituo@gmail.com \
--cc=baijiaju1990@outlook.com \
--cc=bass@buaa.edu.cn \
--cc=kvalo@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=srini.raju@purelifi.com \
/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