Skip to contentSkip to conversation

rtw88: fix potential NULL skb access in TX ISR

PATCH In review [email protected] 3 participants 5 messages Jan 7, 2020 – Jan 26, 2020 Realtek wireless driver (rtw88)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtw88: fix potential NULL skb access in TX ISR

From: Yan-Hsuan Chuang <[email protected]>

Sometimes the TX queue may be empty and we could possible dequeue a NULL pointer, crash the kernel. If the skb is NULL then there is nothing to do, just leave the ISR.

And the TX queue should not be empty here, so print an error to see if there is anything wrong for DMA ring.

Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")
---
 drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/pci.c +5 -0
index a58e8276a41a..a6746b5a9ff2 100644
@@ -832,6 +832,11 @@ static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,
 
 	while (count--) {
 		skb = skb_dequeue(&ring->queue);
+		if (!skb) {
+			rtw_err(rtwdev, "failed to dequeue %d skb TX queue %d, BD=0x%08x, rp %d -> %d\n",
+				count, hw_queue, bd_idx, ring->r.rp, cur_rp);
+			break;
+		}
 		tx_data = rtw_pci_get_tx_data(skb);
 		pci_unmap_single(rtwpci->pdev, tx_data->dma, skb->len,
 				 PCI_DMA_TODEVICE);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 33 lines · On Tue, Jan 7, 2020 at 4:08 PM <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

Sometimes the TX queue may be empty and we could possible dequeue a NULL pointer, crash the kernel. If the skb is NULL then there is nothing to do, just leave the ISR.

And the TX queue should not be empty here, so print an error to see if there is anything wrong for DMA ring.

Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")
---
 drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/pci.c +5 -1
index a58e8276a41a..a6746b5a9ff2 100644
@@ -832,6 +832,11 @@ static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,
 
        while (count--) {
                skb = skb_dequeue(&ring->queue);
+               if (!skb) {
+                       rtw_err(rtwdev, "failed to dequeue %d skb TX queue %d, BD=0x%08x, rp %d -> %d\n",
+                               count, hw_queue, bd_idx, ring->r.rp, cur_rp);
+                       break;
+               }
                tx_data = rtw_pci_get_tx_data(skb);
                pci_unmap_single(rtwpci->pdev, tx_data->dma, skb->len,
                                 PCI_DMA_TODEVICE);
--
Quoted 2 lines

2.17.1

Maybe we can simply do 'while (count -- && !skb_queue_empty(&ring->queue))' to achieve the same thing? I don't think it worths to raise an error unless the count is expected to exactly match the queue length in any
circumstances.

Chris

#2 lore raw

From: Chris Chiu

Quoted 44 lines

Subject: Re: [PATCH] rtw88: fix potential NULL skb access in TX ISR

Quoted 10 lines · On Tue, Jan 7, 2020 at 4:08 PM <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

Sometimes the TX queue may be empty and we could possible dequeue a NULL pointer, crash the kernel. If the skb is NULL then there is nothing to do, just leave the ISR.

And the TX queue should not be empty here, so print an error to see if there is anything wrong for DMA ring.

Review

Quoted 7 lines
Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")
---
 drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/net/wireless/realtek/rtw88/pci.c

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev,

Quoted 4 lines

index a58e8276a41a..a6746b5a9ff2 100644

drivers/net/wireless/realtek/rtw88/pci.c +0 -0
@@ -832,6 +832,11 @@ static void rtw_pci_tx_isr(struct rtw_dev *rtwdev,

struct rtw_pci *rtwpci,

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,

Quoted 5 lines
drivers/net/wireless/realtek/rtw88/pci.c +2 -0
        while (count--) {
                skb = skb_dequeue(&ring->queue);
+               if (!skb) {
+                       rtw_err(rtwdev, "failed to dequeue %d skb TX

queue %d, BD=0x%08x, rp %d -> %d\n",

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, · line 836

Quoted 1 line
drivers/net/wireless/realtek/rtw88/pci.c +1 -0
+                               count, hw_queue, bd_idx, ring->r.rp,

cur_rp);

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,

Quoted 4 lines
drivers/net/wireless/realtek/rtw88/pci.c +2 -0
+                       break;
+               }
                tx_data = rtw_pci_get_tx_data(skb);
                pci_unmap_single(rtwpci->pdev, tx_data->dma,

skb->len,

Quoted 4 lines
drivers/net/wireless/realtek/rtw88/pci.c +0 -1
                                 PCI_DMA_TODEVICE);
--

2.17.1

Quoted 6 lines

Maybe we can simply do 'while (count -- && !skb_queue_empty(&ring->queue))' to achieve the same thing? I don't think it worths to raise an error unless the count is expected to exactly match the queue length in any
circumstances.

Yes, I expected that the queue length should match with the DMA ring. And so I printed an error to see why the count mismatched.

Yan-Hsuan

#3 lore raw
Quoted 53 lines · Tony Chuang

From: Chris Chiu

Quoted 44 lines

Subject: Re: [PATCH] rtw88: fix potential NULL skb access in TX ISR

Quoted 10 lines · On Tue, Jan 7, 2020 at 4:08 PM <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

Sometimes the TX queue may be empty and we could possible dequeue a NULL pointer, crash the kernel. If the skb is NULL then there is nothing to do, just leave the ISR.

And the TX queue should not be empty here, so print an error to see if there is anything wrong for DMA ring.

Review

Quoted 7 lines
Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")
---
 drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/net/wireless/realtek/rtw88/pci.c

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev,

Quoted 4 lines

index a58e8276a41a..a6746b5a9ff2 100644

drivers/net/wireless/realtek/rtw88/pci.c +0 -0
@@ -832,6 +832,11 @@ static void rtw_pci_tx_isr(struct rtw_dev *rtwdev,

struct rtw_pci *rtwpci,

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,

Quoted 5 lines
drivers/net/wireless/realtek/rtw88/pci.c +2 -0
        while (count--) {
                skb = skb_dequeue(&ring->queue);
+               if (!skb) {
+                       rtw_err(rtwdev, "failed to dequeue %d skb TX

queue %d, BD=0x%08x, rp %d -> %d\n",

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, · line 836

Quoted 1 line
drivers/net/wireless/realtek/rtw88/pci.c +1 -0
+                               count, hw_queue, bd_idx, ring->r.rp,

cur_rp);

drivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,

Quoted 4 lines
drivers/net/wireless/realtek/rtw88/pci.c +2 -0
+                       break;
+               }
                tx_data = rtw_pci_get_tx_data(skb);
                pci_unmap_single(rtwpci->pdev, tx_data->dma,

skb->len,

Quoted 4 lines
drivers/net/wireless/realtek/rtw88/pci.c +0 -1
                                 PCI_DMA_TODEVICE);
--

2.17.1

Quoted 6 lines

Maybe we can simply do 'while (count -- && !skb_queue_empty(&ring->queue))' to achieve the same thing? I don't think it worths to raise an error unless the count is expected to exactly match the queue length in any
circumstances.

Quoted 4 lines

Yes, I expected that the queue length should match with the DMA ring. And so I printed an error to see why the count mismatched.

Yan-Hsuan

Maybe you can spin lock around skb_dequeue and skb_enqueue to prevent some possible race conditions?

Chris

#4 lore raw
In reply to [email protected]
Quoted 11 lines · <[email protected]> wrote:

From: Yan-Hsuan Chuang <[email protected]>

Sometimes the TX queue may be empty and we could possible dequeue a NULL pointer, crash the kernel. If the skb is NULL then there is nothing to do, just leave the ISR.

And the TX queue should not be empty here, so print an error to see if there is anything wrong for DMA ring.

Fixes e3037485c68e ("rtw88: new Realtek 802.11ac driver")

Patch applied to wireless-drivers-next.git, thanks.

f4f84ff8377d rtw88: fix potential NULL skb access in TX ISR

Signature · 3 lines
https://patchwork.kernel.org/patch/11320567/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches