wifi: brcmfmac: pcie: handle randbuf allocation failure

Message ID 20240301135134.29577-1-duoming@zju.edu.cn
State New
Headers
Series wifi: brcmfmac: pcie: handle randbuf allocation failure |

Commit Message

Duoming Zhou March 1, 2024, 1:51 p.m. UTC
  The kzalloc() in brcmf_pcie_download_fw_nvram() will return
null if the physical memory has run out. As a result, if we
use get_random_bytes() to generate random bytes in the randbuf,
the null pointer dereference bug will happen.

Return -ENOMEM from brcmf_pcie_download_fw_nvram() if kzalloc()
fails for randbuf.

Fixes: 91918ce88d9f ("wifi: brcmfmac: pcie: Provide a buffer of random bytes to the device")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 2 ++
 1 file changed, 2 insertions(+)
  

Patch

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index d7fb88bb6ae..5ab9c902e49 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -1730,6 +1730,8 @@  static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
 
 			address -= rand_len;
 			randbuf = kzalloc(rand_len, GFP_KERNEL);
+			if (!randbuf)
+				return -ENOMEM;
 			get_random_bytes(randbuf, rand_len);
 			memcpy_toio(devinfo->tcm + address, randbuf, rand_len);
 			kfree(randbuf);