Skip to contentSkip to conversation

wireless: mt76: mt7921: Fix use-after-free in fw features query.

PATCH In review Lorenzo Bianconi 3 participants 5 messages Mar 22, 2023 – Mar 31, 2023

Subsystems (2)
lore
Share & tools
lore

Lorenzo Bianconi

author maintainer
#0 lore raw

PATCH v3 1/1 wireless: mt76: mt7921: Fix use-after-free in fw features query.

From: Ben Greear <[email protected]>

Stop referencing 'features' memory after release_firmware is called.

Fixes this crash:

RIP: 0010:mt7921_check_offload_capability+0x17d
mt7921_pci_probe+0xca/0x4b0

...

---
Changes since v2:
- get rid of the comments

---
 drivers/net/wireless/mediatek/mt76/mt7921/init.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/init.c +5 -2
index 80c71acfe159..cc94531185da 100644
@@ -171,12 +171,12 @@ mt7921_mac_init_band(struct mt7921_dev *dev, u8 band)
 
 u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
 {
-	struct mt7921_fw_features *features = NULL;
 	const struct mt76_connac2_fw_trailer *hdr;
 	struct mt7921_realease_info *rel_info;
 	const struct firmware *fw;
 	int ret, i, offset = 0;
 	const u8 *data, *end;
+	u8 offload_caps = 0;
 
 	ret = request_firmware(&fw, fw_wm, dev);
 	if (ret)
@@ -208,7 +208,10 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
 		data += sizeof(*rel_info);
 
 		if (rel_info->tag == MT7921_FW_TAG_FEATURE) {
+			struct mt7921_fw_features *features;
+
 			features = (struct mt7921_fw_features *)data;
+			offload_caps = features->data;
 			break;
 		}
 
@@ -218,7 +221,7 @@ u8 mt7921_check_offload_capability(struct device *dev, const char *fw_wm)
 out:
 	release_firmware(fw);
 
-	return features ? features->data : 0;
+	return offload_caps;
 }
 EXPORT_SYMBOL_GPL(mt7921_check_offload_capability);
 
Signature · 1 line
2.39.2
#2 lore raw
Quoted 5 lines · Felix Fietkau
Quoted 4 lines · Lorenzo Bianconi

From: Ben Greear <[email protected]>

Stop referencing 'features' memory after release_firmware is called.

Quoted 8 lines
Quoted 8 lines

Fixes this crash:

RIP: 0010:mt7921_check_offload_capability+0x17d
mt7921_pci_probe+0xca/0x4b0

...

The title should have "wifi:", not "wireless:".

Quoted 1 line

Felix, do you mean I should take this to wireless tree?

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
maintainer
#3 lore raw
Quoted 13 lines · Kalle Valo
Quoted 11 lines · Felix Fietkau
Quoted 10 lines · Lorenzo Bianconi

From: Ben Greear <[email protected]>

Stop referencing 'features' memory after release_firmware is called.

Fixes this crash:

RIP: 0010:mt7921_check_offload_capability+0x17d
mt7921_pci_probe+0xca/0x4b0

...

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

The title should have "wifi:", not "wireless:".

Quoted 1 line

Felix, do you mean I should take this to wireless tree?

Sure

- Felix

#4 lore raw

Re: [v3] wifi: mt76: mt7921: Fix use-after-free in fw features query.

In reply to Lorenzo Bianconi
Quoted 6 lines · Lorenzo Bianconi

From: Ben Greear <[email protected]>

Stop referencing 'features' memory after release_firmware is called.

Fixes this crash:

Quoted 7 lines
RIP: 0010:mt7921_check_offload_capability+0x17d
mt7921_pci_probe+0xca/0x4b0

...

Patch applied to wireless.git, thanks.

2ceb76f734e3 wifi: mt76: mt7921: Fix use-after-free in fw features query.

Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/patch/51fd8f76494348aa9ecbf0abc471ebe47a983dfd.1679502607.git.lorenzo@kernel.org/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches