Skip to contentSkip to conversation

usbnet: dereference after null check in usbnet_start_xmit() and __usbnet_read_cmd()

PATCH In review Vivek Kumar Bhagat 2 participants 3 messages Aug 19, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbnet: dereference after null check in usbnet_start_xmit() and __usbnet_read_cmd()

usbnet_start_xmit() - If info->tx_fixup is not defined by class driver, NULL check does not happen for skb pointer and leads to NULL dereference. __usbnet_read_cmd() - if data pointer is passed as NULL, memcpy will dereference NULL pointer.

---
 drivers/net/usb/usbnet.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/usb/usbnet.c +4 -1
index 3c86b10..ec4d224 100644
@@ -1294,6 +1294,8 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
 
 	if (skb)
 		skb_tx_timestamp(skb);
+	else
+		goto drop;
 
 	// some devices want funky USB-level framing, for
 	// win32 driver (usually) and/or hardware quirks
@@ -1906,7 +1908,8 @@ static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
 		buf = kmalloc(size, GFP_KERNEL);
 		if (!buf)
 			goto out;
-	}
+	} else
+		goto out;
 
 	err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
 			      cmd, reqtype, value, index, buf, size,
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 4 lines · Vivek Kumar Bhagat

usbnet_start_xmit() - If info->tx_fixup is not defined by class driver, NULL check does not happen for skb pointer and leads to NULL dereference. __usbnet_read_cmd() - if data pointer is passed as NULL, memcpy will dereference NULL pointer.

That's two completely different issues. Mixing them in a single patch is only confusing things.

Quoted 10 lines
---
 drivers/net/usb/usbnet.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/usb/usbnet.c +0 -0
index 3c86b10..ec4d224 100644

drivers/net/usb/usbnet.c netdev_tx_t usbnet_start_xmit (struct sk_buff *skb, · line 1301

Quoted 8 lines
drivers/net/usb/usbnet.c +2 -0
@@ -1294,6 +1294,8 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
 
 	if (skb)
 		skb_tx_timestamp(skb);
+	else
+		goto drop;
 
 	// some devices want funky USB-level framing, for
 	// win32 driver (usually) and/or hardware quirks

This is wrong. There are usbnet minidrivers depending on info->tx_fixup being called with a NULL skb.

drivers/net/usb/usbnet.c static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, · line 1915

Quoted 10 lines
drivers/net/usb/usbnet.c +2 -1
@@ -1906,7 +1908,8 @@ static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
 		buf = kmalloc(size, GFP_KERNEL);
 		if (!buf)
 			goto out;
-	}
+	} else
+		goto out;
 
 	err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
 			      cmd, reqtype, value, index, buf, size,

This is also wrong. It makes __usbnet_read_cmd() return -ENOMEM if called with a NULL data pointer. I don't know if it is used, but it's perfectly valid to call __usbnet_read_cmd() with data == NULL if size == 0. No memcpy will happen in this case because usb_control_msg can only return 0 or an error

Please don't submit any more such patches without proper justification. You cannot trust that someone will actually take the time to sanity check your changes. Patches claiming to fix a NULL dereference should at least provide an oops.

Bjørn

#2 lore raw
Quoted 10 lines · Bjørn Mork
Quoted 8 lines · Vivek Kumar Bhagat
drivers/net/usb/usbnet.c +2 -1
@@ -1906,7 +1908,8 @@ static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype,
 		buf = kmalloc(size, GFP_KERNEL);
 		if (!buf)
 			goto out;
-	}
+	} else
+		goto out;
 
Quoted 9 lines

drivers/net/usb/usbnet.c static int __usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, · line 1915

Quoted 2 lines
drivers/net/usb/usbnet.c +0 -0
 	err = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
 			      cmd, reqtype, value, index, buf, size,

This is also wrong. It makes __usbnet_read_cmd() return -ENOMEM if called with a NULL data pointer. I don't know if it is used, but it's perfectly valid to call __usbnet_read_cmd() with data == NULL if size == 0. No memcpy will happen in this case because usb_control_msg can only return 0 or an error

Just for the record - a simple grep for usbnet_read_cmd shows that at least drivers/net/usb/plusb.c depends on the current behaviour:

static inline int
pl_vendor_req(struct usbnet *dev, u8 req, u8 val, u8 index) {
return usbnet_read_cmd(dev, req,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, val, index, NULL, 0);
}

Bjørn