Skip to contentSkip to conversation

brcmfmac: add basic validation of shared RAM address

PATCH In review Rafał Miłecki 3 participants 7 messages Feb 20, 2019 – Feb 21, 2019 Broadcom BRCM80211 IEEE802.11 wireless drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 brcmfmac: add basic validation of shared RAM address

From: Rafał Miłecki <[email protected]>

While experimenting with firmware loading I ended up in a state of firmware reporting shared RAM address 0x04000001. It was causing:

[   94.448015] Unable to handle kernel paging request at virtual address cd680001

due to reading out of the mapped memory.

This patch adds some basic validation to avoid kernel crashes due to the unexpected firmware behavior.

---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +6 -0
index 257f919c52cc..58a6bc379358 100644
@@ -1560,6 +1560,12 @@ static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
 		brcmf_err(bus, "FW failed to initialize\n");
 		return -ENODEV;
 	}
+	if (sharedram_addr < devinfo->ci->rambase ||
+	    sharedram_addr >= devinfo->ci->rambase + devinfo->ci->ramsize) {
+		brcmf_err(bus, "Invalid shared RAM address 0x%08x\n",
+			  sharedram_addr);
+		return -ENODEV;
+	}
 	brcmf_dbg(PCIE, "Shared RAM addr: 0x%08x\n", sharedram_addr);
 
 	return (brcmf_pcie_init_share_ram_info(devinfo, sharedram_addr));
Signature · 1 line
2.20.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

While experimenting with firmware loading I ended up in a state of firmware reporting shared RAM address 0x04000001. It was causing:

[   94.448015] Unable to handle kernel paging request at virtual address cd680001

due to reading out of the mapped memory.

This patch adds some basic validation to avoid kernel crashes due to the unexpected firmware behavior.

Quoted 4 lines
---
  drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 6 ++++++
  1 file changed, 6 insertions(+)
#2 lore raw
In reply to Rafał Miłecki
Quoted 4 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

While experimenting with firmware loading I ended up in a state of firmware reporting shared RAM address 0x04000001. It was causing:

Quoted 8 lines
[   94.448015] Unable to handle kernel paging request at virtual address cd680001

due to reading out of the mapped memory.

This patch adds some basic validation to avoid kernel crashes due to the unexpected firmware behavior.

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

e0a8ef4d7b43 brcmfmac: add basic validation of shared RAM address

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

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
#3 lore raw
In reply to Rafał Miłecki
Quoted 9 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

While experimenting with firmware loading I ended up in a state of firmware reporting shared RAM address 0x04000001. It was causing:

[   94.448015] Unable to handle kernel paging request at virtual address cd680001

due to reading out of the mapped memory.

This patch adds some basic validation to avoid kernel crashes due to the unexpected firmware behavior.

For a reference for the further hackers. That has been caused by a BCMA_CORE_SYS_MEM core on my BCM4366/4 not being up.

maintainer
#4 lore raw
Quoted 8 lines · Rafał Miłecki
Quoted 7 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

While experimenting with firmware loading I ended up in a state of firmware reporting shared RAM address 0x04000001. It was causing:

[   94.448015] Unable to handle kernel paging request at virtual address cd680001

due to reading out of the mapped memory.

Quoted 5 lines
Quoted 2 lines

This patch adds some basic validation to avoid kernel crashes due to the unexpected firmware behavior.

For a reference for the further hackers. That has been caused by a BCMA_CORE_SYS_MEM core on my BCM4366/4 not being up.

Thanks, Rafał

Does that happen all the time or in some specific scenario. Anyway, it seems like we need to add a check in brcmf_chip_sysmem_ramsize() and bringup the core if needed. Although, I am curious in what the state the other cores are at that time. Might need a chip-wide reset.

Regards,
Arend

#5 lore raw
Quoted 15 lines · Arend Van Spriel
Quoted 8 lines · Rafał Miłecki
Quoted 7 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

While experimenting with firmware loading I ended up in a state of firmware reporting shared RAM address 0x04000001. It was causing:

[   94.448015] Unable to handle kernel paging request at virtual address cd680001

due to reading out of the mapped memory.

Quoted 5 lines
Quoted 2 lines

This patch adds some basic validation to avoid kernel crashes due to the unexpected firmware behavior.

For a reference for the further hackers. That has been caused by a BCMA_CORE_SYS_MEM core on my BCM4366/4 not being up.

Quoted 6 lines

Thanks, Rafał

Does that happen all the time or in some specific scenario. Anyway, it seems like we need to add a check in brcmf_chip_sysmem_ramsize() and bringup the core if needed. Although, I am curious in what the state the other cores are at that time. Might need a chip-wide reset.

It happens after brcmf_pcie_reset_device() which is probably a 100% expected case ;)

Normally brcmfmac does not call brcmf_pcie_reset_device() between brcmf_chip_sysmem_ramsize() and the brcmf_pcie_download_fw_nvram() so it was only my hacking that caused that issue for me.

Signature · 1 line
Rafał
maintainer
#6 lore raw
Quoted 19 lines · Rafał Miłecki
Quoted 17 lines · Arend Van Spriel
Quoted 8 lines · Rafał Miłecki
Quoted 7 lines · Rafał Miłecki

From: Rafał Miłecki <[email protected]>

While experimenting with firmware loading I ended up in a state of firmware reporting shared RAM address 0x04000001. It was causing:

[   94.448015] Unable to handle kernel paging request at virtual address cd680001

due to reading out of the mapped memory.

Quoted 5 lines
Quoted 2 lines

This patch adds some basic validation to avoid kernel crashes due to the unexpected firmware behavior.

For a reference for the further hackers. That has been caused by a BCMA_CORE_SYS_MEM core on my BCM4366/4 not being up.

Thanks, Rafał

Quoted 7 lines
Quoted 4 lines

Does that happen all the time or in some specific scenario. Anyway, it seems like we need to add a check in brcmf_chip_sysmem_ramsize() and bringup the core if needed. Although, I am curious in what the state the other cores are at that time. Might need a chip-wide reset.

It happens after brcmf_pcie_reset_device() which is probably a 100% expected case ;)

Did not check what that function exactly does, but could be expected.

Quoted 3 lines

Normally brcmfmac does not call brcmf_pcie_reset_device() between brcmf_chip_sysmem_ramsize() and the brcmf_pcie_download_fw_nvram() so it was only my hacking that caused that issue for me.

Ah. Can only wish you happy hacking then ;-)

Gr. AvS