Skip to contentSkip to conversation

wifi: libertas: fix integer underflow in process_cmdrequest()

PATCH New Amir Mohammad Jahangirzad 1 participant 1 message Apr 18 Marvell libertas wireless driver

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: libertas: fix integer underflow in process_cmdrequest()

The existing validation only checks if recvlength exceeds LBS_CMD_BUFFER_SIZE, but doesn't check the lower bound. When a USB device sends a response shorter than MESSAGE_HEADER_LEN, the subtraction (recvlength - MESSAGE_HEADER_LEN) wraps to a huge value, causing memcpy to corrupt the heap.
Add the same lower bound check that libertas_tf already has.

---
 drivers/net/wireless/marvell/libertas/if_usb.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/libertas/if_usb.c +3 -2
index 8a6bf1365..42d3fd32e 100644
@@ -625,9 +625,10 @@ static inline void process_cmdrequest(int recvlength, uint8_t *recvbuff,
 	unsigned long flags;
 	u8 i;
 
-	if (recvlength > LBS_CMD_BUFFER_SIZE) {
+	if (recvlength < MESSAGE_HEADER_LEN ||
+	    recvlength > LBS_CMD_BUFFER_SIZE) {
 		lbs_deb_usbd(&cardp->udev->dev,
-			     "The receive buffer is too large\n");
+			     "The receive buffer is invalid: %d\n", recvlength);
 		kfree_skb(skb);
 		return;
 	}
Signature · 1 line
2.53.0