Skip to contentSkip to conversation

wifi: nxpwifi: fix UAF after skb_realloc_headroom() in bridged RX

PATCH New Elkin Cruz 1 participant 1 message Nov 25

Subsystems (3)
lore
Share & tools
lore

Elkin Cruz

author
#0 lore raw

PATCH 1/1 wifi: nxpwifi: fix UAF after skb_realloc_headroom() in bridged RX

In nxpwifi_uap_queue_bridged_pkt(), uap_rx_pd and rx_pkt_hdr point into the original skb->data buffer. If skb_headroom(skb) is less than NXPWIFI_MIN_DATA_HEADER_LEN, skb_realloc_headroom() allocates a new skb and kfree_skb() frees the old skb, leaving uap_rx_pd and rx_pkt_hdr dangling when updating station and bridge statistics (in addition to rx_pkt_hdr->eth803_hdr.h_source having been partially overwritten in the SNAP-to-Ethernet-II header move).

Cache rx_rate and ht_info from uap_rx_pd once packet bounds are verified and read h_source and h_dest via p_ethhdr = (void *)skb->data after the headroom reallocation block.

Fixes 73b01e57ed3e ("wifi: nxp: add nxpwifi driver for IW61x")

---

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/nxp/nxpwifi/uap_txrx.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/net/wireless/nxp/nxpwifi/uap_txrx.c +9 -4
index 840dddfc4f5a..c3191575db17 100644
@@ -84,6 +84,7 @@ nxpwifi_uap_queue_bridged_pkt(struct nxpwifi_private *priv,
 	int hdr_chop;
 	struct ethhdr *p_ethhdr;
 	struct nxpwifi_sta_node *src_node;
+	u8 rx_rate, ht_info;
 	int index;
 
 	uap_rx_pd = (struct uap_rxpd *)(skb->data);
@@ -105,6 +106,9 @@ nxpwifi_uap_queue_bridged_pkt(struct nxpwifi_private *priv,
 		return;
 	}
 
+	rx_rate = uap_rx_pd->rx_rate;
+	ht_info = uap_rx_pd->ht_info;
+
 	if ((!memcmp(&rx_pkt_hdr->rfc1042_hdr, bridge_tunnel_header,
 		     sizeof(bridge_tunnel_header))) ||
 	    (!memcmp(&rx_pkt_hdr->rfc1042_hdr, rfc1042_header,
@@ -178,18 +182,19 @@ nxpwifi_uap_queue_bridged_pkt(struct nxpwifi_private *priv,
 	tx_info->bss_type = priv->bss_type;
 	tx_info->flags |= NXPWIFI_BUF_FLAG_BRIDGED_PKT;
 
+	p_ethhdr = (void *)skb->data;
 	rcu_read_lock();
-	src_node = nxpwifi_get_sta_entry(priv, rx_pkt_hdr->eth803_hdr.h_source);
+	src_node = nxpwifi_get_sta_entry(priv, p_ethhdr->h_source);
 	if (src_node) {
 		src_node->stats.last_rx = jiffies;
 		src_node->stats.rx_bytes += skb->len;
 		src_node->stats.rx_packets++;
-		src_node->stats.last_tx_rate = uap_rx_pd->rx_rate;
-		src_node->stats.last_tx_htinfo = uap_rx_pd->ht_info;
+		src_node->stats.last_tx_rate = rx_rate;
+		src_node->stats.last_tx_htinfo = ht_info;
 	}
 	rcu_read_unlock();
 
-	if (is_unicast_ether_addr(rx_pkt_hdr->eth803_hdr.h_dest)) {
+	if (is_unicast_ether_addr(p_ethhdr->h_dest)) {
 		/*
 		 * Update bridge packet statistics as the
 		 * packet is not going to kernel/upper layer.
Signature · 1 line
2.56.1.839.g22a8290db9-goog