Skip to contentSkip to conversation

wifi: zero-pad SDIO writes to avoid leaking heap data

PATCH In review Tristan Madani 2 participants 4 messages Nov 2 – Nov 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover wifi: zero-pad SDIO writes to avoid leaking heap data

From: Tristan Madani <[email protected]>

Several wireless drivers round up the length passed to sdio_memcpy_toio() / sdio_writesb() for alignment purposes but do not clear the padding bytes. The SDIO controller then reads past the original buffer into adjacent heap memory, sending stale kernel data to the wireless device.

Fix brcmfmac (4-byte alignment) and rsi (block alignment) by zero-filling the gap before the write.

A third patch for rtw88 hits the same class of bug but needs a rebase and will follow separately.

Tristan Madani (2):
wifi: brcmfmac: zero-pad SDIO write to 4-byte boundary
wifi: rsi: zero-pad SDIO TX to block boundary

 drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 3 +++
 drivers/net/wireless/rsi/rsi_91x_sdio.c                   | 3 +++
 2 files changed, 6 insertions(+)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/2 wifi: brcmfmac: zero-pad SDIO write to 4-byte boundary

From: Tristan Madani <[email protected]>

brcmf_sdiod_skbuff_write() rounds skb->len up to the next 4-byte boundary and passes the larger size to sdio_memcpy_toio(). The 1-3 extra bytes come from heap memory past skb->data, leaking stale kernel data to the wireless device.

Zero-fill the padding before the SDIO write.

Fixes 8f13c87ccc49 ("brcmfmac: Split brcmf_sdiod_buffrw function up.")
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c +3 -0
index 71c2f99cdb711..c6dd4148a44ce 100644
@@ -323,6 +323,9 @@ static int brcmf_sdiod_skbuff_write(struct brcmf_sdio_dev *sdiodev,
 	req_sz = skb->len + 3;
 	req_sz &= (uint)~3;
 
+	if (req_sz > skb->len)
+		memset(skb->data + skb->len, 0, req_sz - skb->len);
+
 	err = sdio_memcpy_toio(func, addr, ((u8 *)(skb->data)), req_sz);
 
 	if (err == -ENOMEDIUM)
Signature · 1 line
2.47.3
#3 lore raw

PATCH 2/2 wifi: rsi: zero-pad SDIO TX to block boundary

In reply to Tristan Madani

From: Tristan Madani <[email protected]>

rsi_sdio_host_intf_write_pkt() rounds the packet length up to the SDIO block size and passes the larger length to rsi_sdio_write_register_multiple(). When the packet is not block-aligned, the SDIO controller reads past the original data into adjacent heap memory, leaking stale kernel data to the wireless device.

Zero-fill the padding before the SDIO write.

Fixes dad0d04fa7ba ("rsi: Add RS9113 wireless driver")
---
 drivers/net/wireless/rsi/rsi_91x_sdio.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/rsi/rsi_91x_sdio.c +3 -0
index bfa386b820d89..8bfb08306d03c 100644
@@ -772,6 +772,9 @@ static int rsi_sdio_host_intf_write_pkt(struct rsi_hw *adapter,
 	address = (num_blocks * block_size | (queueno << 12));
 	length  = num_blocks * block_size;
 
+	if (length > len)
+		memset((u8 *)pkt + len, 0, length - len);
+
 	status = rsi_sdio_write_register_multiple(adapter,
 						  address,
 						  (u8 *)pkt,
Signature · 1 line
2.47.3
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH wireless 1/2] wifi: brcmfmac: zero-pad SDIO write to 4-byte boundary

In reply to Tristan Madani
Quoted 11 lines · Tristan Madani

From: Tristan Madani <[email protected]>

brcmf_sdiod_skbuff_write() rounds skb->len up to the next 4-byte boundary and passes the larger size to sdio_memcpy_toio(). The 1-3 extra bytes come from heap memory past skb->data, leaking stale kernel data to the wireless device.

Zero-fill the padding before the SDIO write.

Fixes 8f13c87ccc49 ("brcmfmac: Split brcmf_sdiod_buffrw function up.")
Quoted 4 lines
---
  drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c | 3 +++
  1 file changed, 3 insertions(+)