Skip to contentSkip to conversation

wifi: mwifiex: bound SDIO fw dump count by memory table size

PATCH Superseded Tianchu Chen 2 participants 3 messages Sep 4 – Sep 25

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: mwifiex: bound SDIO fw dump count by memory table size

From: Tianchu Chen <[email protected]>

mwifiex_sdio_fw_dump() reads the number of memory regions (dump_num) from a device register and uses it to index the static 15-entry mem_type_mapping_tbl[] without any bounds check. A bogus device can report a dump_num larger than the table, making each loop iteration store a vmalloc pointer and a device-controlled size past the end of the table into adjacent .data (up to ~5.7KB when dump_num is 255).

The dump path runs after command timeouts or firmware crashes, so a bogus device can first force an error to trigger the dump and then report a bogus dump_num.

Aborting the dump only loses the firmware snapshot; the card reset that follows is unaffected, so error recovery still completes.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 54881c6b37c8d ("mwifiex: add firmware dump feature for SDIO")
Assisted-by LLM
---
 drivers/net/wireless/marvell/mwifiex/sdio.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/marvell/mwifiex/sdio.c +5 -0
index f039d6f19183a..e40ca40418b30 100644
@@ -2795,6 +2795,11 @@ static void mwifiex_sdio_fw_dump(struct mwifiex_adapter *adapter)
 		mwifiex_dbg(adapter, ERROR, "SDIO read memory length err\n");
 		goto done;
 	}
+	if (dump_num > ARRAY_SIZE(mem_type_mapping_tbl)) {
+		mwifiex_dbg(adapter, ERROR,
+			    "Invalid fw dump num: %d\n", dump_num);
+		goto done;
+	}
 
 	/* Read the length of every memory which will dump */
 	for (idx = 0; idx < dump_num; idx++) {
Signature · 1 line
2.51.0
#1 lore raw
Quoted 46 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

mwifiex_sdio_fw_dump() reads the number of memory regions (dump_num) from a device register and uses it to index the static 15-entry mem_type_mapping_tbl[] without any bounds check. A bogus device can report a dump_num larger than the table, making each loop iteration store a vmalloc pointer and a device-controlled size past the end of the table into adjacent .data (up to ~5.7KB when dump_num is 255).

The dump path runs after command timeouts or firmware crashes, so a bogus device can first force an error to trigger the dump and then report a bogus dump_num.

Aborting the dump only loses the firmware snapshot; the card reset that follows is unaffected, so error recovery still completes.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 54881c6b37c8d ("mwifiex: add firmware dump feature for SDIO")
Assisted-by LLM
---
 drivers/net/wireless/marvell/mwifiex/sdio.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/marvell/mwifiex/sdio.c +5 -0
index f039d6f19183a..e40ca40418b30 100644
@@ -2795,6 +2795,11 @@ static void mwifiex_sdio_fw_dump(struct mwifiex_adapter *adapter)
 mwifiex_dbg(adapter, ERROR, "SDIO read memory length err\n");
 goto done;
 }
+ if (dump_num > ARRAY_SIZE(mem_type_mapping_tbl)) {
+ mwifiex_dbg(adapter, ERROR,
+ "Invalid fw dump num: %d\n", dump_num);
+ goto done;
+ }
 
 /* Read the length of every memory which will dump */
 for (idx = 0; idx < dump_num; idx++) {
Signature · 1 line
2.51.0

Hi,

I noticed that this patch is marked as "Changes Requested" in Wireless Patchwork, but I haven't received any review comments.

Could you please point me to the requested changes or the relevant review message? I am happy to send a v2 once I know what should be improved.

Best regards,

Tianchu

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Tianchu Chen
Quoted 16 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

mwifiex_sdio_fw_dump() reads the number of memory regions (dump_num) from a device register and uses it to index the static 15-entry mem_type_mapping_tbl[] without any bounds check. A bogus device can report a dump_num larger than the table, making each loop iteration store a vmalloc pointer and a device-controlled size past the end of the table into adjacent .data (up to ~5.7KB when dump_num is 255).

The dump path runs after command timeouts or firmware crashes, so a bogus device can first force an error to trigger the dump and then report a bogus dump_num.

Aborting the dump only loses the firmware snapshot; the card reset that follows is unaffected, so error recovery still completes.

Quoted 6 lines

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 54881c6b37c8d ("mwifiex: add firmware dump feature for SDIO")
Assisted-by LLM

I'm not sure if we're in the business of distrusting SDIO registers, but sure?

We also read this same register a bit later and use it for computing potentially-enormous buffers to allocate and fill. Dunno if we consider OOM a potential vulnerability (or infinite loop / DoS, or ...).