wifi: rsi: fix multiple firmware descriptor validation issues
v2 cover wifi: rsi: fix multiple firmware descriptor validation issues
From: Tristan Madani <[email protected]>
Hi Johannes,
Note: this is a v2 resubmission. The original was sent via Gmail which caused HTML rendering issues. This version uses git send-email for proper plain-text formatting.
The rsi91x driver trusts several firmware-controlled fields without validation across SDIO and USB transport paths. Five issues found:
Proposed fixes in the following patches.
Thanks,
Tristan
PATCH v2 1/5 wifi: rsi: fix OOB read from firmware offset field in SDIO RX path
From: Tristan Madani <[email protected]>
The firmware-controlled offset field in rsi_read_pkt() is validated only when rcv_pkt_len is zero (USB path). For the SDIO path, rcv_pkt_len is always positive, so the check is skipped entirely. A crafted offset can cause out-of-bounds reads past the 8192-byte pktbuffer when computing queue number, length, extended descriptor, and data pointers.
Add a transport-independent bounds check to reject offset values that exceed the frame's actual_length.
---drivers/net/wireless/rsi/rsi_91x_main.c | 5 +++++
1 file changed, 5 insertions(+)
drivers/net/wireless/rsi/rsi_91x_main.c +6 -0
@@ -171,6 +171,11 @@ int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len)if (!rcv_pkt_len && offset >RSI_MAX_RX_USB_PKT_SIZE -FRAME_DESC_SZ ) goto fail; +if (offset > actual_length) { +rsi_dbg (ERR_ZONE , +"%s: offset %u exceeds length %u\n" , + __func__, offset, actual_length); + goto fail; + } queueno =rsi_get_queueno (frame_desc, offset);
length = rsi_get_length(frame_desc, offset);
PATCH v2 2/5 wifi: rsi: fix integer underflow from firmware extended_desc in rsi_prepare_skb()
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The firmware-controlled extended_desc value is subtracted from pkt_len without bounds checking. When extended_desc exceeds pkt_len, the u32 subtraction wraps, causing either a failed allocation (DoS) or an out-of-bounds heap read via the subsequent memcpy from buffer + payload_offset. Both SDIO and USB paths are affected.
Add a bounds check to reject packets where extended_desc exceeds pkt_len.
---drivers/net/wireless/rsi/rsi_91x_main.c | 5 +++++
1 file changed, 5 insertions(+)
drivers/net/wireless/rsi/rsi_91x_main.c +5 -0
@@ -136,6 +136,11 @@ static struct sk_buff *rsi_prepare_skb(struct rsi_common *common, pkt_len =RSI_RCV_BUFFER_LEN *4 ; } +if (extended_desc > pkt_len) { +rsi_dbg (ERR_ZONE ,"%s: extended_desc %u > pkt_len %u\n" , + __func__, extended_desc, pkt_len); +return NULL ; + } pkt_len -= extended_desc; skb =dev_alloc_skb (pkt_len +FRAME_DESC_SZ );if (skb ==NULL )
PATCH v2 3/5 wifi: rsi: fix OOB read from firmware-claimed length exceeding actual frame size
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The firmware-controlled length field (12-bit, up to 4095) from the RX descriptor is used as the memcpy size in rsi_prepare_skb(). No check ensures this claimed length fits within the actual received data. A malicious or malfunctioning firmware can cause out-of-bounds reads past the RX buffer, leaking kernel heap contents into skbs delivered to mac80211.
Add a bounds check in rsi_read_pkt() to reject frames where offset + length exceeds actual_length.
---drivers/net/wireless/rsi/rsi_91x_main.c | 6 ++++++
1 file changed, 6 insertions(+)
drivers/net/wireless/rsi/rsi_91x_main.c +6 -0
@@ -179,6 +179,12 @@ int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len) queueno =rsi_get_queueno (frame_desc, offset); length =rsi_get_length (frame_desc, offset); +if (offset + length > actual_length) { +rsi_dbg (ERR_ZONE , +"%s: frame overflows: offset %u + len %u > actual %u\n" , + __func__, offset, length, actual_length); + goto fail; + }/* Extended descriptor is valid for WLAN queues only */ if (queueno ==RSI_WIFI_DATA_Q || queueno ==RSI_WIFI_MGMT_Q ) extended_desc = rsi_get_extended_desc(frame_desc,
PATCH v2 4/5 wifi: rsi: fix OOB read from firmware pad_bytes in management RX path
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
The firmware-controlled pad_bytes value (u8, from descriptor byte 4) is used to shift the skb_put_data() source pointer forward in rsi_mgmt_pkt_to_core(). While the existing msg_len -= pad_bytes check catches the case where pad_bytes >= msg_len, it does not prevent a large pad_bytes from shifting the read window into heap memory beyond the actual packet data. The resulting kernel heap contents are delivered to mac80211 as a management frame.
Add validation that pad_bytes does not exceed half of msg_len. Alignment padding in 802.11 management frames is typically 0-3 bytes, so any value exceeding msg_len / 2 indicates a corrupted descriptor.
---drivers/net/wireless/rsi/rsi_91x_mgmt.c | 6 ++++++
1 file changed, 6 insertions(+)
drivers/net/wireless/rsi/rsi_91x_mgmt.c +6 -0
@@ -490,6 +490,12 @@ static int rsi_mgmt_pkt_to_core(struct rsi_common *common,u8 pad_bytes = msg[4 ];struct sk_buff *skb; +if (pad_bytes > msg_len /2 ) { +rsi_dbg (MGMT_RX_ZONE , +"%s: pad_bytes %u too large for msg_len %d\n" , + __func__, pad_bytes, msg_len); +return -EINVAL ; + }if (!adapter->sc_nvifs)return -ENOLINK ;
PATCH v2 5/5 wifi: rsi: fix infinite loop when firmware sends zero-length packet
In reply to Tristan MadaniFrom: Tristan Madani <[email protected]>
rsi_read_pkt() reads actual_length from the frame descriptor as a u16. When the firmware returns actual_length == 0, the loop's index and rcv_pkt_len counters never change, creating an infinite kernel loop.
Check for zero actual_length immediately after reading it from the descriptor and bail out if invalid.
---drivers/net/wireless/rsi/rsi_91x_main.c | 3 +++
1 file changed, 3 insertions(+)
drivers/net/wireless/rsi/rsi_91x_main.c +3 -0
@@ -168,6 +168,9 @@ int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len) do { frame_desc = &rx_pkt[index]; actual_length = *(u16 *)&frame_desc[0]; + if (!actual_length) + goto fail; + offset = *(u16 *)&frame_desc[2]; if (!rcv_pkt_len && offset > RSI_MAX_RX_USB_PKT_SIZE - FRAME_DESC_SZ)
--
2.43.0