Skip to contentSkip to conversation

rtlwifi: rtl8188ee: avoid accessing the data mapped to streaming DMA

PATCH Superseded Jia-Ju Bai 3 participants 4 messages Nov 18, 2020 – Nov 19, 2020

Subsystems (3)
lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH v2 1/4 rtlwifi: rtl8188ee: avoid accessing the data mapped to streaming DMA

In rtl88ee_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 677:
dma_addr_t mapping = dma_map_single(..., skb->data, ...);

On line 680, skb->data is assigned to hdr after cast:
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);

Then hdr->frame_control is accessed on line 681:
__le16 fc = hdr->frame_control;

This DMA access may cause data inconsistency between CPU and hardwre.

To fix this bug, hdr->frame_control is accessed before the DMA mapping.

---
 drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c +3 -3
index b9775eec4c54..c948dafa0c80 100644
@@ -674,12 +674,12 @@ void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
 	u8 fw_queue = QSLT_BEACON;
 	__le32 *pdesc = (__le32 *)pdesc8;
 
-	dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
-					    skb->len, DMA_TO_DEVICE);
-
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
 	__le16 fc = hdr->frame_control;
 
+	dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
+					    skb->len, DMA_TO_DEVICE);
+
 	if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) {
 		rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
 			"DMA mapping error\n");
Signature · 1 line
2.17.1
maintainer Acked-by on v2 1/4
#1 lore raw
Quoted 7 lines · Jia-Ju Bai

In rtl88ee_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 677:
  dma_addr_t mapping = dma_map_single(..., skb->data, ...);

On line 680, skb->data is assigned to hdr after cast:
  struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);

Quoted 8 lines

Then hdr->frame_control is accessed on line 681:
  __le16 fc = hdr->frame_control;

This DMA access may cause data inconsistency between CPU and hardwre.

To fix this bug, hdr->frame_control is accessed before the DMA mapping.

This patchset looks good to me.
Thank you.

Quoted 25 lines

---
 drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c | 6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c +0 -0
index b9775eec4c54..c948dafa0c80 100644
@@ -674,12 +674,12 @@ void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
  	u8 fw_queue = QSLT_BEACON;
  	__le32 *pdesc = (__le32 *)pdesc8;

drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c +0 -3
-	dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
-					    skb->len, DMA_TO_DEVICE);
-

  struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data); __le16 fc = hdr->frame_control;

drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c +3 -0
+	dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
+					    skb->len, DMA_TO_DEVICE);
+

  if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) { rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE, "DMA mapping error\n");

#2 lore raw
In reply to Jia-Ju Bai
Quoted 10 lines · Jia-Ju Bai

In rtl88ee_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 677:

   dma_addr_t mapping = dma_map_single(..., skb->data, ...);

On line 680, skb->data is assigned to hdr after cast:

   struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);

Then hdr->frame_control is accessed on line 681:

   __le16 fc = hdr->frame_control;
Quoted 8 lines

This DMA access may cause data inconsistency between CPU and hardwre.

To fix this bug, hdr->frame_control is accessed before the DMA mapping.

---
  drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)

What changed between v1 and v2?

As outlined in Documentation/process/submitting-patches.rst, you should add a '---' marker and descrive what was changed. I usually summarize the changes, but it is also possible to provide a diffstat of the changes as the above file shows.

Larry

Quoted 22 lines
drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c +3 -3
index b9775eec4c54..c948dafa0c80 100644
@@ -674,12 +674,12 @@ void rtl88ee_tx_fill_cmddesc(struct ieee80211_hw *hw,
  	u8 fw_queue = QSLT_BEACON;
  	__le32 *pdesc = (__le32 *)pdesc8;
 
-	dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
-					    skb->len, DMA_TO_DEVICE);
-
  	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
  	__le16 fc = hdr->frame_control;
 
+	dma_addr_t mapping = dma_map_single(&rtlpci->pdev->dev, skb->data,
+					    skb->len, DMA_TO_DEVICE);
+
  	if (dma_mapping_error(&rtlpci->pdev->dev, mapping)) {
  		rtl_dbg(rtlpriv, COMP_SEND, DBG_TRACE,
  			"DMA mapping error\n");
author
#3 lore raw

Thanks for the advice.
I have added the description of the changes and resent the patches.

Best wishes,
Jia-Ju Bai

Quoted 24 lines · Larry Finger
Quoted 10 lines · Jia-Ju Bai

In rtl88ee_tx_fill_cmddesc(), skb->data is mapped to streaming DMA on line 677:
   dma_addr_t mapping = dma_map_single(..., skb->data, ...);

On line 680, skb->data is assigned to hdr after cast:
   struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);

Then hdr->frame_control is accessed on line 681:
   __le16 fc = hdr->frame_control;

Quoted 8 lines

This DMA access may cause data inconsistency between CPU and hardwre.

To fix this bug, hdr->frame_control is accessed before the DMA mapping.

---
  drivers/net/wireless/realtek/rtlwifi/rtl8188ee/trx.c | 6 +++---

  1 file changed, 3 insertions(+), 3 deletions(-)

What changed between v1 and v2?

As outlined in Documentation/process/submitting-patches.rst, you should add a '---' marker and descrive what was changed. I usually summarize the changes, but it is also possible to provide a diffstat of the changes as the above file shows.