wifi: wcn36xx: fix OOB reads and heap overflow from firmware responses
v2 cover wifi: wcn36xx: fix OOB reads and heap overflow from firmware responses
From: Tristan Madani <[email protected]>
Hi Loic,
Note: this is a v2 resubmission. The original was sent via Gmail which caused HTML rendering issues. This version uses git send-email for proper plain-text formatting.
Three issues in wcn36xx HAL firmware response handling, including a heap overflow in the main response dispatcher:
Proposed fixes in the following patches.
Thanks,
Tristan
PATCH v2 1/3 wifi: wcn36xx: fix heap overflow from oversized firmware HAL response
From: Tristan Madani <[email protected]>
The firmware response dispatcher copies all synchronous HAL responses into the 4096-byte hal_buf without validating the response length. A response exceeding WCN36XX_HAL_BUF_SIZE causes a heap buffer overflow with firmware-controlled content.
Add a bounds check on the response length.
---drivers/net/wireless/ath/wcn36xx/smd.c | 5 +++++
1 file changed, 5 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +4 -0
@@ -3296,6 +3296,11 @@ int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,case WCN36XX_HAL_ADD_BCN_FILTER_RSP : +if (len >WCN36XX_HAL_BUF_SIZE ) { +wcn36xx_warn ("HAL response too large: %d\n" , len); +break ; + }memcpy (wcn->hal_buf, buf, len); wcn->hal_rsp_len = len;complete (&wcn->hal_rsp_compl);
PATCH v2 2/3 wifi: wcn36xx: fix OOB read from firmware count in PRINT_REG_INFO indication
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The firmware-controlled rsp->count field is used as the loop bound for indexing into the flexible rsp->regs[] array without validation against the message length. A count exceeding the actual data causes out-of- bounds reads from the heap-allocated message buffer.
Add a check that count fits within the received message.
---drivers/net/wireless/ath/wcn36xx/smd.c | 6 ++++++
1 file changed, 6 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +6 -0
@@ -2803,6 +2803,12 @@ static int wcn36xx_smd_print_reg_info_ind(struct wcn36xx *wcn,return -EIO ; } +if (rsp->count > (len -sizeof (*rsp)) /sizeof (rsp->regs[0 ])) { +wcn36xx_warn ("Truncated print reg info indication: count %u, len %zu\n" , + rsp->count, len); +return -EIO ; + } +wcn36xx_dbg (WCN36XX_DBG_HAL ,"reginfo indication, scenario: 0x%x reason: 0x%x\n" , rsp->scenario, rsp->reason);
PATCH v2 3/3 wifi: wcn36xx: fix OOB read from short trigger BA firmware response
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The firmware response length is only checked against sizeof(*rsp) (20 bytes), but when candidate_cnt >= 1, a 22-byte candidate struct is read at buf + 20 without verifying the response contains it. This causes an out-of-bounds read of stale heap data, corrupting the BA session state.
Add validation that the response includes the candidate data.
---drivers/net/wireless/ath/wcn36xx/smd.c | 3 +++
1 file changed, 3 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +3 -0
@@ -2599,6 +2599,9 @@ static int wcn36xx_smd_trigger_ba_rsp(void *buf, int len, struct add_ba_info *baif (rsp->candidate_cnt <1 )return rsp->status ? rsp->status : -EINVAL ; +if (len <sizeof (*rsp) +sizeof (*candidate)) +return -EINVAL ; + candidate = (struct wcn36xx_hal_trigger_ba_rsp_candidate *)(buf +sizeof (*rsp));for (i =0 ; i <STACFG_MAX_TC ; i++) {