From: Daniil Dulov <d.dulov@aladdin.ru>
To: Johannes Berg <johannes.berg@intel.com>
Cc: Daniil Dulov <d.dulov@aladdin.ru>, Kees Cook <kees@kernel.org>,
"Emmanuel Grumbach" <emmanuel.grumbach@intel.com>,
Miri Korenblit <miriam.rachel.korenblit@intel.com>,
"John W. Linville" <linville@tuxdriver.com>,
Daniel Drake <dsd@gentoo.org>, <linux-wireless@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org>
Subject: [PATCH] wifi: zd1211rw: Fix potential data race in zd_mac_tx_to_dev()
Date: Wed, 4 Jun 2025 13:13:56 +0300 [thread overview]
Message-ID: <20250604101356.6292-1-d.dulov@aladdin.ru> (raw)
There is a potential data race in zd_mac_tx_to_dev(). For example, it is
possible for filter_ack() to clear the ack_wait_queue right after
zd_mac_tx_to_dev() checks that queue has more than 50 elements, but before
it dequeues any skb. This results in skb_dequeue() returns NULL and the
pointer is dereferenced in zd_mac_tx_status().
In order to avoid potential data races and leading dereference of a NULL
pointer, acquire the queue lock before any work with the queue is done and
replace all skb_* calls with their lockless version.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: 459c51ad6e1f ("zd1211rw: port to mac80211")
Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
---
drivers/net/wireless/zydas/zd1211rw/zd_mac.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/zydas/zd1211rw/zd_mac.c b/drivers/net/wireless/zydas/zd1211rw/zd_mac.c
index 9653dbaac3c0..e7e0d1b7b9ab 100644
--- a/drivers/net/wireless/zydas/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zydas/zd1211rw/zd_mac.c
@@ -568,6 +568,7 @@ void zd_mac_tx_to_dev(struct sk_buff *skb, int error)
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
struct ieee80211_hw *hw = info->rate_driver_data[0];
struct zd_mac *mac = zd_hw_mac(hw);
+ unsigned long flags;
ieee80211_tx_info_clear_status(info);
@@ -581,13 +582,17 @@ void zd_mac_tx_to_dev(struct sk_buff *skb, int error)
} else {
struct sk_buff_head *q = &mac->ack_wait_queue;
- skb_queue_tail(q, skb);
+ spin_lock_irqsave(&q->lock, flags);
+
+ __skb_queue_tail(q, skb);
while (skb_queue_len(q) > ZD_MAC_MAX_ACK_WAITERS) {
- zd_mac_tx_status(hw, skb_dequeue(q),
+ zd_mac_tx_status(hw, __skb_dequeue(q),
mac->ack_pending ? mac->ack_signal : 0,
NULL);
mac->ack_pending = 0;
}
+
+ spin_unlock_irqrestore(&q->lock, flags);
}
}
--
2.34.1
next reply other threads:[~2025-06-04 10:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-04 10:13 Daniil Dulov [this message]
2025-06-11 9:35 ` [PATCH] wifi: zd1211rw: Fix potential data race in zd_mac_tx_to_dev() Johannes Berg
2025-06-16 12:36 ` Daniil Dulov
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=20250604101356.6292-1-d.dulov@aladdin.ru \
--to=d.dulov@aladdin.ru \
--cc=dsd@gentoo.org \
--cc=emmanuel.grumbach@intel.com \
--cc=johannes.berg@intel.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=lvc-project@linuxtesting.org \
--cc=miriam.rachel.korenblit@intel.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