Skip to contentSkip to conversation

wifi: wcn36xx: firmware trust boundary hardening

PATCH Applied Tristan Madani 3 participants 11 messages Apr 21 – Jun 6 Qualcomm WCN36XX wireless driver

lore
Share & tools
lore
#0 lore raw

v3 cover wifi: wcn36xx: firmware trust boundary hardening

From: Tristan Madani <[email protected]>

This series adds missing bounds checks for firmware-controlled fields in the Qualcomm wcn36xx driver.

Patch 1 prevents heap overflow from oversized HAL responses. Patch 2 validates PRINT_REG_INFO count. Patch 3 checks trigger BA response length.

Changes in v3:
- Regenerated from wireless-next with proper git format-patch.

Changes in v2:
- No code changes from v1.

Tristan Madani (3):
wifi: wcn36xx: fix heap overflow from oversized firmware HAL response
wifi: wcn36xx: fix OOB read from firmware count in PRINT_REG_INFO
indication
wifi: wcn36xx: fix OOB read from short trigger BA firmware response

 drivers/net/wireless/ath/wcn36xx/smd.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v3 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.

Fixes 8e84c2582169 ("wcn36xx: mac80211 driver for Qualcomm WCN3660/WCN3680 hardware")

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +4 -0
index 813553edcb789..f65328329f4f0 100644
@@ -3293,6 +3293,10 @@ int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
 	case WCN36XX_HAL_EXIT_IMPS_RSP:
 	case WCN36XX_HAL_UPDATE_CHANNEL_LIST_RSP:
 	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);
Signature · 1 line
2.47.3
#5 lore raw

PATCH v3 2/3 wifi: wcn36xx: fix OOB read from firmware count in PRINT_REG_INFO indication

In reply to Tristan Madani

From: 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.

Fixes 43efa3c0f241 ("wcn36xx: Implement print_reg indication")

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +6 -0
index f65328329f4f0..2a0c946d81095 100644
@@ -2805,6 +2805,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);
Signature · 1 line
2.47.3
#7 lore raw

PATCH v3 3/3 wifi: wcn36xx: fix OOB read from short trigger BA firmware response

In reply to Tristan Madani

From: 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.

Fixes 16be1ac55944 ("wcn36xx: Parse trigger_ba response properly")

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +3 -0
index 2a0c946d81095..c0b477345832b 100644
@@ -2599,6 +2599,9 @@ static int wcn36xx_smd_trigger_ba_rsp(void *buf, int len, struct add_ba_info *ba
 	if (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++) {
Signature · 1 line
2.47.3
maintainer
#8 lore raw

Re: [PATCH v3 3/3] wifi: wcn36xx: fix OOB read from short trigger BA firmware response

Hi Tristan,

Quoted 8 lines · Tristan Madani

From: 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.

Quoted 4 lines

Add validation that the response includes the candidate data.

Fixes 16be1ac55944 ("wcn36xx: Parse trigger_ba response properly")

In previous series, Johannes pointed you to:
https://docs.kernel.org/process/coding-assistants.html

This document describes the Assisted-by: tag, which should be added for AI usage tracking purposes.

Quoted 28 lines

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +3 -1
index 2a0c946d81095..c0b477345832b 100644
@@ -2599,6 +2599,9 @@ static int wcn36xx_smd_trigger_ba_rsp(void *buf, int len, struct add_ba_info *ba
        if (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++) {
--

2.47.3

maintainer Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] wifi: wcn36xx: fix heap overflow from oversized firmware HAL response

In reply to Tristan Madani
Quoted 8 lines · Tristan Madani

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.

Quoted 4 lines

Add a bounds check on the response length.

Fixes 8e84c2582169 ("wcn36xx: mac80211 driver for Qualcomm WCN3660/WCN3680 hardware")
Quoted 29 lines

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +4 -1
index 813553edcb789..f65328329f4f0 100644
@@ -3293,6 +3293,10 @@ int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
        case WCN36XX_HAL_EXIT_IMPS_RSP:
        case WCN36XX_HAL_UPDATE_CHANNEL_LIST_RSP:
        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);
--

2.47.3

maintainer Reviewed-by on v3 3/3
#9 lore raw

Re: [PATCH v3 3/3] wifi: wcn36xx: fix OOB read from short trigger BA firmware response

In reply to Tristan Madani
Quoted 8 lines · Tristan Madani

From: 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.

Quoted 4 lines

Add validation that the response includes the candidate data.

Fixes 16be1ac55944 ("wcn36xx: Parse trigger_ba response properly")
Quoted 28 lines

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +3 -1
index 2a0c946d81095..c0b477345832b 100644
@@ -2599,6 +2599,9 @@ static int wcn36xx_smd_trigger_ba_rsp(void *buf, int len, struct add_ba_info *ba
        if (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++) {
--

2.47.3

#3 lore raw

Re: [PATCH v3 1/3] wifi: wcn36xx: fix heap overflow from oversized firmware HAL response

In reply to Tristan Madani
Quoted 27 lines · Tristan Madani

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.

Fixes 8e84c2582169 ("wcn36xx: mac80211 driver for Qualcomm WCN3660/WCN3680 hardware")

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +0 -0
index 813553edcb789..f65328329f4f0 100644

drivers/net/wireless/ath/wcn36xx/smd.c int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev, · line 3302

Quoted 10 lines
drivers/net/wireless/ath/wcn36xx/smd.c +4 -0
@@ -3293,6 +3293,10 @@ int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
 	case WCN36XX_HAL_EXIT_IMPS_RSP:
 	case WCN36XX_HAL_UPDATE_CHANNEL_LIST_RSP:
 	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);

AI review points out that this logic will bypass the complete() meaning callers waiting for completion will be stuck (either forever or until the specified timeout expires). It proposes setting len = 0 instead of break and having each waiter deal with the issue that wcn->hal_rsp_len is 0.

Further probing gave the observation that there is only one waiter wcn36xx_smd_send_and_wait() so there isn't a "wait forever" scenario.

It also confirmed that setting wcn->hal_rsp_len = 0 would subsequently be processed by wcn36xx_smd_rsp_status_check() which would return -EIO due to len < sizeof(header) + sizeof(status_rsp).

So setting len = 0 and still calling complete() would avoid the timeout and would cause -EIO vs -ETIME to be propagated.

I can go either way with this since it is not expected to occur.

/jeff

maintainer
#4 lore raw

Re: [PATCH v3 1/3] wifi: wcn36xx: fix heap overflow from oversized firmware HAL response

Hi Jeff,

Quoted 48 lines · Jeff Johnson
Quoted 27 lines · Tristan Madani

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.

Fixes 8e84c2582169 ("wcn36xx: mac80211 driver for Qualcomm WCN3660/WCN3680 hardware")

---
Changes in v3:
- Regenerated from wireless-next with proper git format-patch to produce valid index hashes (v2 had post-processed index lines).

Changes in v2:
- No code changes from v1.

 drivers/net/wireless/ath/wcn36xx/smd.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/wireless/ath/wcn36xx/smd.c +0 -0
index 813553edcb789..f65328329f4f0 100644

drivers/net/wireless/ath/wcn36xx/smd.c int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev, · line 3302

Quoted 10 lines
drivers/net/wireless/ath/wcn36xx/smd.c +4 -0
@@ -3293,6 +3293,10 @@ int wcn36xx_smd_rsp_process(struct rpmsg_device *rpdev,
      case WCN36XX_HAL_EXIT_IMPS_RSP:
      case WCN36XX_HAL_UPDATE_CHANNEL_LIST_RSP:
      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);

AI review points out that this logic will bypass the complete() meaning callers waiting for completion will be stuck (either forever or until the specified timeout expires). It proposes setting len = 0 instead of break and having each waiter deal with the issue that wcn->hal_rsp_len is 0.

Further probing gave the observation that there is only one waiter wcn36xx_smd_send_and_wait() so there isn't a "wait forever" scenario.

Quoted 8 lines

It also confirmed that setting wcn->hal_rsp_len = 0 would subsequently be processed by wcn36xx_smd_rsp_status_check() which would return -EIO due to len < sizeof(header) + sizeof(status_rsp).

So setting len = 0 and still calling complete() would avoid the timeout and would cause -EIO vs -ETIME to be propagated.

I can go either way with this since it is not expected to occur.

Thanks, the above analysis is indeed correct, but let's make it simple and go as is, with the timeout.

Regards,
Loic

Reviewed-by Loic Poulain on v3 2/3
#6 lore raw

Re: [PATCH v3 2/3] wifi: wcn36xx: fix OOB read from firmware count in PRINT_REG_INFO indication

In reply to Tristan Madani
Quoted 11 lines · Tristan Madani

From: 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.

Fixes 43efa3c0f241 ("wcn36xx: Implement print_reg indication")

Propagating from v2 so that b4 will pick it up...

Applied
#10 lore raw
In reply to Tristan Madani
Quoted 8 lines · Tristan Madani

This series adds missing bounds checks for firmware-controlled fields in the Qualcomm wcn36xx driver.

Patch 1 prevents heap overflow from oversized HAL responses. Patch 2 validates PRINT_REG_INFO count. Patch 3 checks trigger BA response length.

[...]

Applied, thanks!

[1/3] wifi: wcn36xx: fix heap overflow from oversized firmware HAL response

      commit: 88a240d86d3d64521f9194abe185ac71cc74d0bd
[2/3] wifi: wcn36xx: fix OOB read from firmware count in PRINT_REG_INFO indication
      commit: df2187acfca6c6cca372c5d35f42394d9c270b09
[3/3] wifi: wcn36xx: fix OOB read from short trigger BA firmware response
      commit: b5e6f21923ca89d90256e7346301056f6502691e

Best regards,

Signature · 1 line
Jeff Johnson <[email protected]>