lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230628022121.1010517-1-islituo@gmail.com>
Date:   Wed, 28 Jun 2023 10:21:21 +0800
From:   Tuo Li <islituo@...il.com>
To:     srini.raju@...elifi.com, kvalo@...nel.org
Cc:     linux-wireless@...r.kernel.org, linux-kernel@...r.kernel.org,
        baijiaju1990@...look.com, Tuo Li <islituo@...il.com>,
        BassCheck <bass@...a.edu.cn>
Subject: [PATCH] wifi: plfxlc: Fix possible data races in rx_urb_complete()

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@...a.edu.cn>
Signed-off-by: Tuo Li <islituo@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ