rtw88: fix potential NULL skb access in TX ISR
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.
--- drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/pci.c +5 -0
@@ -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
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")Signed-off-by Yan-Hsuan Chuang <[email protected]>--- drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/wireless/realtek/rtw88/pci.c +5
-1@@ -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
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")Signed-off-by Yan-Hsuan Chuang <[email protected]>--- drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++ 1 file changed, 5 insertions(+)(quoted diff) +0
-0
b/drivers/net/wireless/realtek/rtw88/pci.cdrivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev,
Quoted 4 lines
index
a58e8276a41a..a6746b5a9ff2100644drivers/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
-0while (count--) { skb =skb_dequeue (&ring->queue); +if (!skb) { + rtw_err(rtwdev, "failed to dequeue %d skb TXqueue %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
-1PCI_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
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")Signed-off-by Yan-Hsuan Chuang <[email protected]>--- drivers/net/wireless/realtek/rtw88/pci.c | 5 +++++ 1 file changed, 5 insertions(+)(quoted diff) +0
-0
b/drivers/net/wireless/realtek/rtw88/pci.cdrivers/net/wireless/realtek/rtw88/pci.c static void rtw_pci_tx_isr(struct rtw_dev *rtwdev,
Quoted 4 lines
index
a58e8276a41a..a6746b5a9ff2100644drivers/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
-0while (count--) { skb =skb_dequeue (&ring->queue); +if (!skb) { + rtw_err(rtwdev, "failed to dequeue %d skb TXqueue %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
-1PCI_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
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")Signed-off-by Yan-Hsuan Chuang <[email protected]>
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