[PATCH] wifi: libertas: reject short monitor TX frames

Kai Kuang kuangkai at kylinos.cn
Mon Nov 16 02:16:15 PST 2026


In monitor mode, lbs_hard_start_xmit() casts skb->data to a radiotap TX
header, skips that header and then copies the 802.11 destination address
from offset 4 in the remaining frame.  The generic length check only
rejects zero-length and oversized skbs, so a short monitor frame is read
past the end of the skb data.  If the frame is shorter than the radiotap
header, the subtraction that computes pkt_len also underflows, turning
the following memcpy() into a large out-of-bounds read of the skb and a
write past the end of tx_pending_buf.

Require enough bytes for the radiotap TX header and the destination
address field before using the monitor-mode header layout.  The check
runs while driver_lock is held and before the TX queues are stopped, so
the drop path reuses the existing "goto free" cleanup; placing it after
the lock is dropped would unlock driver_lock twice and leave
tx_pending_len set to -1 with the queues stopped.

This addresses the same out-of-bounds read that the earlier submission
linked below was meant to fix, but was reverted because it performed the
check after driver_lock had already been released.

Link: https://patch.msgid.link/20260704011140.37639-1-pengpeng@iscas.ac.cn
Signed-off-by: Kai Kuang <kuangkai at kylinos.cn>
---
 drivers/net/wireless/marvell/libertas/tx.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/net/wireless/marvell/libertas/tx.c b/drivers/net/wireless/marvell/libertas/tx.c
index 27304a98787d..6ad7a5067f2a 100644
--- a/drivers/net/wireless/marvell/libertas/tx.c
+++ b/drivers/net/wireless/marvell/libertas/tx.c
@@ -88,6 +88,22 @@ netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		goto free;
 	}
 
+	/*
+	 * A monitor frame carries a radiotap TX header followed by the
+	 * 802.11 header; the destination address is copied from offset 4
+	 * of the latter.  Drop frames too short for that layout instead of
+	 * reading past the end of skb data or underflowing pkt_len.
+	 *
+	 * This must happen while driver_lock is held and before the queues
+	 * are stopped, so that the "goto free" path above stays consistent.
+	 */
+	if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR &&
+	    skb->len < sizeof(struct tx_radiotap_hdr) + 4 + ETH_ALEN) {
+		lbs_deb_tx("tx err: short monitor frame %d\n", skb->len);
+		dev->stats.tx_dropped++;
+		dev->stats.tx_errors++;
+		goto free;
+	}
 
 	netif_stop_queue(priv->dev);
 	if (priv->mesh_dev)



More information about the libertas-dev mailing list