wifi: mt76: mt7925: fix UAF and skb leak in mt7925_mcu_rx_event()
Subsystems (3)
PATCH 1/1 wifi: mt76: mt7925: fix UAF and skb leak in mt7925_mcu_rx_event()
mt7925_mcu_rx_event() caches rxd = (struct mt7925_mcu_rxd *)skb->data before calling skb_linearize(skb). When skb is non-linear, skb_linearize() reallocates skb->head via pskb_expand_head() and frees the old packet buffer, leaving rxd dangling into freed memory when rxd->option is subsequently dereferenced.
In addition, mt7925_queue_rx_skb() transfers full ownership of skb to mt7925_mcu_rx_event(), so returning directly when skb_linearize() fails leaks skb.
Free skb on skb_linearize() failure and assign rxd from skb->data only after skb_linearize() succeeds, matching sibling mt7921_mcu_rx_event() after commit 4361f1660101 ("wifi: mt76: mt7921: fix memory leak when skb_linearize fails in mcu rx event").
---
I am trying out new Clang static analysis checks for kernel bug classes, and they flagged this code as possibly buggy. The findings were triaged/fixed and commit descriptions were drafted with help of AI, then checked against linux-next (not runtime-tested on hardware).
Thanks,
Elkin
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +6 -2
@@ -715,10 +715,14 @@ mt7925_mcu_uni_rx_unsolicited_event(struct mt792x_dev *dev,void mt7925_mcu_rx_event (struct mt792x_dev *dev,struct sk_buff *skb) { -struct mt7925_mcu_rxd *rxd = (struct mt7925_mcu_rxd *)skb->data; +struct mt7925_mcu_rxd *rxd; -if (skb_linearize (skb)) +if (skb_linearize (skb)) { +dev_kfree_skb (skb);return ; + } + + rxd = (struct mt7925_mcu_rxd *)skb->data;if (rxd->option &MCU_UNI_CMD_UNSOLICITED_EVENT ) {mt7925_mcu_uni_rx_unsolicited_event (dev, skb);
Signature · 1 line
2.56.1.839.g22a8290db9-goog