On Tue, 15 Feb 2022, Johannes Berg wrote:
> >
> > ieee80211_tx_h_select_key() is performing a series of RCU dereferences,
> > but none of the callers seems to be taking RCU read-side lock; let's
> > acquire the lock in ieee80211_tx_h_select_key() itself.
> >
> but but ...
>
> > ieee80211_tx_dequeue+0x1a7/0x1260 [mac80211 911c23e2351c0ae60b597a67b1204a5ea955e365]
> > rtw89_core_txq_work+0x1a6/0x420 [rtw89_core b39ba493f2e517ad75e0f8187ecc24edf58bbbea]
>
> /**
> * ieee80211_tx_dequeue - dequeue a packet from a software tx queue
> *
> * @hw: pointer as obtained from ieee80211_alloc_hw()
> * @txq: pointer obtained from station or virtual interface, or from
> * ieee80211_next_txq()
> *
> * Returns the skb if successful, %NULL if no frame was available.
> *
> * Note that this must be called in an rcu_read_lock() critical section,
> * which can only be released after the SKB was handled. Some pointers in
> [...]
>
> -> driver bug?
Right you are, thanks.
CCing Ping-Ke Shih; find updated fix below.
From: Jiri Kosina <[email protected]>
Subject: [PATCH] rtw89: fix RCU usage in rtw89_core_txq_push()
ieee80211_tx_h_select_key() is performing a series of RCU dereferences,
but rtw89_core_txq_push() is calling it (via ieee80211_tx_dequeue_ni())
without RCU read-side lock held; fix that.
This addresses the splat below.
=============================
WARNING: suspicious RCU usage
5.17.0-rc4-00003-gccad664b7f14 #3 Tainted: G E
-----------------------------
net/mac80211/tx.c:593 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
2 locks held by kworker/u33:0/184:
#0: ffff9c0b14811d38 ((wq_completion)rtw89_tx_wq){+.+.}-{0:0}, at: process_one_work+0x258/0x660
#1: ffffb97380cf3e78 ((work_completion)(&rtwdev->txq_work)){+.+.}-{0:0}, at: process_one_work+0x258/0x660
stack backtrace:
CPU: 8 PID: 184 Comm: kworker/u33:0 Tainted: G E 5.17.0-rc4-00003-gccad664b7f14 #3 473b49ab0e7c2d6af2900c756bfd04efd7a9de13
Hardware name: LENOVO 20UJS2B905/20UJS2B905, BIOS R1CET63W(1.32 ) 04/09/2021
Workqueue: rtw89_tx_wq rtw89_core_txq_work [rtw89_core]
Call Trace:
<TASK>
dump_stack_lvl+0x58/0x71
ieee80211_tx_h_select_key+0x2c0/0x530 [mac80211 911c23e2351c0ae60b597a67b1204a5ea955e365]
ieee80211_tx_dequeue+0x1a7/0x1260 [mac80211 911c23e2351c0ae60b597a67b1204a5ea955e365]
rtw89_core_txq_work+0x1a6/0x420 [rtw89_core b39ba493f2e517ad75e0f8187ecc24edf58bbbea]
process_one_work+0x2d8/0x660
worker_thread+0x39/0x3e0
? process_one_work+0x660/0x660
kthread+0xe5/0x110
? kthread_complete_and_exit+0x20/0x20
ret_from_fork+0x22/0x30
</TASK>
=============================
WARNING: suspicious RCU usage
5.17.0-rc4-00003-gccad664b7f14 #3 Tainted: G E
-----------------------------
net/mac80211/tx.c:607 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
2 locks held by kworker/u33:0/184:
#0: ffff9c0b14811d38 ((wq_completion)rtw89_tx_wq){+.+.}-{0:0}, at: process_one_work+0x258/0x660
#1: ffffb97380cf3e78 ((work_completion)(&rtwdev->txq_work)){+.+.}-{0:0}, at: process_one_work+0x258/0x660
stack backtrace:
CPU: 8 PID: 184 Comm: kworker/u33:0 Tainted: G E 5.17.0-rc4-00003-gccad664b7f14 #3 473b49ab0e7c2d6af2900c756bfd04efd7a9de13
Hardware name: LENOVO 20UJS2B905/20UJS2B905, BIOS R1CET63W(1.32 ) 04/09/2021
Workqueue: rtw89_tx_wq rtw89_core_txq_work [rtw89_core]
Call Trace:
<TASK>
dump_stack_lvl+0x58/0x71
ieee80211_tx_h_select_key+0x464/0x530 [mac80211 911c23e2351c0ae60b597a67b1204a5ea955e365]
ieee80211_tx_dequeue+0x1a7/0x1260 [mac80211 911c23e2351c0ae60b597a67b1204a5ea955e365]
rtw89_core_txq_work+0x1a6/0x420 [rtw89_core b39ba493f2e517ad75e0f8187ecc24edf58bbbea]
process_one_work+0x2d8/0x660
worker_thread+0x39/0x3e0
? process_one_work+0x660/0x660
kthread+0xe5/0x110
? kthread_complete_and_exit+0x20/0x20
ret_from_fork+0x22/0x30
</TASK>
Signed-off-by: Jiri Kosina <[email protected]>
---
drivers/net/wireless/realtek/rtw89/core.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c
index a0737eea9f81..9632e7f218dd 100644
--- a/drivers/net/wireless/realtek/rtw89/core.c
+++ b/drivers/net/wireless/realtek/rtw89/core.c
@@ -1509,11 +1509,12 @@ static void rtw89_core_txq_push(struct rtw89_dev *rtwdev,
unsigned long i;
int ret;
+ rcu_read_lock();
for (i = 0; i < frame_cnt; i++) {
skb = ieee80211_tx_dequeue_ni(rtwdev->hw, txq);
if (!skb) {
rtw89_debug(rtwdev, RTW89_DBG_TXRX, "dequeue a NULL skb\n");
- return;
+ goto out;
}
rtw89_core_txq_check_agg(rtwdev, rtwtxq, skb);
ret = rtw89_core_tx_write(rtwdev, vif, sta, skb, NULL);
@@ -1523,6 +1524,8 @@ static void rtw89_core_txq_push(struct rtw89_dev *rtwdev,
break;
}
}
+out:
+ rcu_read_unlock();
}
static u32 rtw89_check_and_reclaim_tx_resource(struct rtw89_dev *rtwdev, u8 tid)
--
Jiri Kosina
SUSE Labs
Jiri Kosina <[email protected]> writes:
> On Tue, 15 Feb 2022, Johannes Berg wrote:
>
>> >
>> > ieee80211_tx_h_select_key() is performing a series of RCU dereferences,
>> > but none of the callers seems to be taking RCU read-side lock; let's
>> > acquire the lock in ieee80211_tx_h_select_key() itself.
>> >
>> but but ...
>>
>> > ieee80211_tx_dequeue+0x1a7/0x1260 [mac80211 911c23e2351c0ae60b597a67b1204a5ea955e365]
>> > rtw89_core_txq_work+0x1a6/0x420 [rtw89_core b39ba493f2e517ad75e0f8187ecc24edf58bbbea]
>>
>> /**
>> * ieee80211_tx_dequeue - dequeue a packet from a software tx queue
>> *
>> * @hw: pointer as obtained from ieee80211_alloc_hw()
>> * @txq: pointer obtained from station or virtual interface, or from
>> * ieee80211_next_txq()
>> *
>> * Returns the skb if successful, %NULL if no frame was available.
>> *
>> * Note that this must be called in an rcu_read_lock() critical section,
>> * which can only be released after the SKB was handled. Some pointers in
>> [...]
>>
>> -> driver bug?
>
> Right you are, thanks.
>
> CCing Ping-Ke Shih; find updated fix below.
>
>
>
>
> From: Jiri Kosina <[email protected]>
> Subject: [PATCH] rtw89: fix RCU usage in rtw89_core_txq_push()
>
> ieee80211_tx_h_select_key() is performing a series of RCU dereferences,
> but rtw89_core_txq_push() is calling it (via ieee80211_tx_dequeue_ni())
> without RCU read-side lock held; fix that.
I think we have discussed this before, but patchwork can't handle
patches the way you embed them in email discussions:
https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/
Please resubmit.
--
https://patchwork.kernel.org/project/linux-wireless/list/
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
On Tue, 15 Feb 2022, Kalle Valo wrote:
> I think we have discussed this before, but patchwork can't handle
> patches the way you embed them in email discussions:
>
> https://patchwork.kernel.org/project/linux-wireless/patch/[email protected]/
>
> Please resubmit.
Ok, I've resubmitted in a separate thread
https://lore.kernel.org/r/[email protected]
Thanks,
--
Jiri Kosina
SUSE Labs