linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data,Re: [PATCH] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data
@ 2018-12-09 20:17 Mathias Payer
  0 siblings, 0 replies; 3+ messages in thread
From: Mathias Payer @ 2018-12-09 20:17 UTC (permalink / raw)
  To: David Miller; +Cc: gregkh, netdev, linux-usb, bigeasy, benquike

> The whole kernel is full of situations where an int is returned and if it's
> negative it's an error.  Why is this location so different?
> 
> Just check < 0 and be done with it.

OK, whatever you prefer.

I've attached the updated patch. (Greg, please add your Signed-off-by).

Best,
Mathias

commit 78e4a03cd3ae7c8f5957a170bc054fd89d7600f1
Author: Mathias Payer <mathias.payer@nebelwelt.net>
Date:   Sun Dec 9 16:45:09 2018 +0100

    NET: hso: Fix OOB memory access in hso_probe/hso_get_config_data in hso.c
    
    From: Hui Peng <benquike@gmail.com>
    
    The function hso_probe reads if_num from the USB device (as an u8) and uses
    it without a length check to index an array, resulting in an OOB memory read
    in hso_probe or hso_get_config_data. Added a length check for both locations
    and updated hso_probe to bail on error.
    
    This issue has been assigned CVE-2018-19985.
    
    Reported-by: Hui Peng <benquike@gmail.com>
    Reported-by: Mathias Payer <mathias.payer@nebelwelt.net>
    Signed-off-by: Hui Peng <benquike@gmail.com>
    Signed-off-by: Mathias Payer <mathias.payer@nebelwelt.net>

diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 184c24baca15..d6916f787fce 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -2807,6 +2807,12 @@ static int hso_get_config_data(struct usb_interface *interface)
 		return -EIO;
 	}
 
+	/* check if we have a valid interface */
+	if (if_num > 16) {
+		kfree(config_data);
+		return -EINVAL;
+	}
+
 	switch (config_data[if_num]) {
 	case 0x0:
 		result = 0;
@@ -2877,10 +2883,18 @@ static int hso_probe(struct usb_interface *interface,
 
 	/* Get the interface/port specification from either driver_info or from
 	 * the device itself */
-	if (id->driver_info)
+	if (id->driver_info) {
+		/* if_num is controlled by the device, driver_info is a 0 terminated
+		 * array. Make sure, the access is in bounds! */
+		for (i = 0; i <= if_num; ++i)
+			if (((u32 *)(id->driver_info))[i] == 0)
+				goto exit;
 		port_spec = ((u32 *)(id->driver_info))[if_num];
-	else
+	} else {
 		port_spec = hso_get_config_data(interface);
+		if (port_spec < 0)
+			goto exit;
+	}
 
 	/* Check if we need to switch to alt interfaces prior to port
 	 * configuration */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data,Re: [PATCH] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data
@ 2018-12-09 20:40 David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2018-12-09 20:40 UTC (permalink / raw)
  To: mathias.payer; +Cc: gregkh, netdev, linux-usb, bigeasy, benquike

From: Mathias Payer <mathias.payer@nebelwelt.net>
Date: Sun, 9 Dec 2018 21:17:58 +0100

> I've attached the updated patch. (Greg, please add your Signed-off-by).

Patches should be posted inline, not as attachments as per
process/submitting-patches.rst

^ permalink raw reply	[flat|nested] 3+ messages in thread

* USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data,Re: [PATCH] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data
@ 2018-12-10  7:18 Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2018-12-10  7:18 UTC (permalink / raw)
  To: Mathias Payer; +Cc: David Miller, netdev, linux-usb, bigeasy, benquike

On Sun, Dec 09, 2018 at 09:17:58PM +0100, Mathias Payer wrote:
> > The whole kernel is full of situations where an int is returned and if it's
> > negative it's an error.  Why is this location so different?
> > 
> > Just check < 0 and be done with it.
> 
> OK, whatever you prefer.

My fault, I was tired and suggested the other way...

> I've attached the updated patch. (Greg, please add your Signed-off-by).

Patches can't be attached, I'll fix this up and resend, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-10  7:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-10  7:18 USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data,Re: [PATCH] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data Greg Kroah-Hartman
  -- strict thread matches above, loose matches on Subject: below --
2018-12-09 20:40 David Miller
2018-12-09 20:17 Mathias Payer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).