Skip to contentSkip to conversation

SER: mt7925: race condition in mt7925e_mac_reset allows compromised WiFi firmware to trigger host sk_buff use-after-free

PATCH Superseded Eason Lai 2 participants 4 messages Oct 12 – Oct 14

Subsystems (2)
lore
Share & tools
lore

Eason Lai

author
#0 lore raw

PATCH 1/1 SER: mt7925: race condition in mt7925e_mac_reset allows compromised WiFi firmware to trigger host sk_buff use-after-free

From: Jeff Hsu <[email protected]>

Fix racing condition in reset handler result sk_buff use-after-free

---
 drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +3 -1
index c3db814b2788..555eeb74d023 100644
@@ -73,9 +73,11 @@ void mt7925_tx_token_put(struct mt792x_dev *dev)
 int mt7925e_mac_reset(struct mt792x_dev *dev)
 {
 	const struct mt792x_irq_map *irq_map = dev->irq_map;
+	struct mt76_phy *mphy = &dev->mt76.phy;
 	int i, err;
 
-	mt792xe_mcu_drv_pmctrl(dev);
+	__mt792xe_mcu_drv_pmctrl(dev);
+	clear_bit(MT76_STATE_PM, &mphy->state);
 
 	mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
 
Signature · 1 line
2.45.2
#1 lore raw

drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c void mt7925_tx_token_put(struct mt792x_dev *dev) · line 80

Quoted 3 lines · Eason Lai
drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +2 -1
-	mt792xe_mcu_drv_pmctrl(dev);
+	__mt792xe_mcu_drv_pmctrl(dev);
+	clear_bit(MT76_STATE_PM, &mphy->state);

Eason,

A heads-up, since this one is on me: my d12a54be2604 in mt76 changed the line this patch replaces, so it won't apply there or on wireless-next as is. That commit makes the reset return early if the driver can't take ownership back. If you want to keep that, it would look something like:

	err = __mt792xe_mcu_drv_pmctrl(dev);
	if (err)
		return err;

	clear_bit(MT76_STATE_PM, &mphy->state);

Devin

#2 lore raw
Quoted 7 lines · Devin Wittmayer

A heads-up, since this one is on me: my d12a54be2604 in mt76 changed the line this patch replaces, so it won't apply there or on wireless-next as is. That commit makes the reset return early if the driver can't take ownership back. If you want to keep that, it would look something like:

Quoted 7 lines

        err = __mt792xe_mcu_drv_pmctrl(dev);
        if (err)
                return err;

        clear_bit(MT76_STATE_PM, &mphy->state);

Devin

Hi Devin,

Thanks for the heads-up.
v2 will be rebased and incorporate your suggested change.

Thanks,
Eason

author
#3 lore raw

PATCH v2 1/1 wifi: mt76: mt7925: race condition in mt7925e_mac_reset allows compromised WiFi firmware to trigger host sk_buff use-after-free

In reply to Eason Lai

From: Jeff Hsu <[email protected]>

Fix racing condition in reset handler result sk_buff use-after-free

---
v2: Rebase the code, due to code conflict with previous change in d12a54be2604

---
 drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +4 -1
index 18f125bf3df4..bc8f741e9426 100644
@@ -71,12 +71,15 @@ void mt7925_tx_token_put(struct mt792x_dev *dev)
 int mt7925e_mac_reset(struct mt792x_dev *dev)
 {
 	const struct mt792x_irq_map *irq_map = dev->irq_map;
+	struct mt76_phy *mphy = &dev->mt76.phy;
 	int i, err;
 
-	err = mt792xe_mcu_drv_pmctrl(dev);
+	err = __mt792xe_mcu_drv_pmctrl(dev);
 	if (err)
 		return err;
 
+	clear_bit(MT76_STATE_PM, &mphy->state);
+
 	mt76_connac_free_pending_tx_skbs(&dev->pm, NULL);
 
 	mt76_wr(dev, dev->irq_map->host_irq_enable, 0);
Signature · 1 line
2.45.2