From 6dbcac8c4b645600161feafc5576657905f15d65 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Tue, 5 May 2020 13:46:26 +0200 Subject: [PATCH] hfa384x_usb: fix buffer overflow The driver trusts the data_len coming from the hardware without verification. That means that this opens a vector by which an attacker can smash 64K of the heap. Signed-off-by: Oliver Neukum --- drivers/staging/wlan-ng/hfa384x_usb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c index fa1bf8b069fd..5b6497d8c9e2 100644 --- a/drivers/staging/wlan-ng/hfa384x_usb.c +++ b/drivers/staging/wlan-ng/hfa384x_usb.c @@ -3353,9 +3353,9 @@ static void hfa384x_int_rxmonitor(struct wlandevice *wlandev, struct hfa384x_usb_rxfrm *rxfrm) { struct hfa384x_rx_frame *rxdesc = &rxfrm->desc; - unsigned int hdrlen = 0; - unsigned int datalen = 0; - unsigned int skblen = 0; + unsigned int hdrlen; + unsigned int datalen; + unsigned int skblen; u8 *datap; u16 fc; struct sk_buff *skb; @@ -3413,8 +3413,10 @@ static void hfa384x_int_rxmonitor(struct wlandevice *wlandev, */ skb_put_data(skb, &rxdesc->frame_control, hdrlen); - /* If any, copy the data from the card to the skb */ - if (datalen > 0) { + /* If any, copy the data from the card to the skb, + * as long as it fits, lest we smash a buffer + */ + if (datalen > 0 && datalen <= skblen - hdrlen) { datap = skb_put_data(skb, rxfrm->data, datalen); /* check for unencrypted stuff if WEP bit set. */ -- 2.16.4