Skip to contentSkip to conversation

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

DISCUSSION Vivek Kumar Bhagat 2 participants 2 messages Aug 20, 2015

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

Dear Bjorn,

Quoted 2 lines
Quoted 2 lines

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

I am using ax88179_178a driver and not familiar with usbnet minidrivers. When ax88179_tx_fixup() is called with NULL skb from usbnet_start_xmit(), I get a kernel crash.

    Backtrace:
    09:14:569>[0-553.5598] [<befaa194>] (ax88179_tx_fixup+0x0/0x16c [ax88179_178a]) from [<befef7a8>] (usbnet_start_xmit+0xa
    09:14:569>0/0x420 [usbnet])
    09:14:570>[0-553.5711]  r6:cb5ec280 r5:00000000 r4:cb5ebd40
    09:14:572>[0-553.5755] [<befef708>] (usbnet_start_xmit+0x0/0x420 [usbnet]) from [<c0400040>] (dev_hard_start_xmit+0x2ec/
    09:14:572>0x558)
    09:14:572>[0-553.5858] [<c03ffd54>] (dev_hard_start_xmit+0x0/0x558)

In case skb NULL check can not be added in usbnet_start_xmit() then NULL check is required in ax88179_tx_fixup() or asix_tx_fixup().

Quoted 4 lines
Quoted 4 lines

This is also wrong. It makes __usbnet_read_cmd() return -ENOMEM if called with a NULL data pointer.
No memcpy will happen in this case because usb_control_msg can only return 0 or an error

Yes, some of the USB control message is sent from host to gadget without expecting any data in return. This is my mistake. I apologise for this.

Best Regards,
Vivek

------- Original Message -------
Sender : Bjørn Mork<[email protected]>
Date : Aug 19, 2015 17:21 (GMT+05:30)
Title : Re: [PATCH] usbnet: dereference after null check in usbnet_start_xmit() and __usbnet_read_cmd()

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
Signed-off-by Vivek Kumar Bhagat
---
 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

#1 lore raw
Quoted 14 lines · Vivek Kumar Bhagat

Dear Bjorn,

Quoted 2 lines
Quoted 2 lines

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

I am using ax88179_178a driver and not familiar with usbnet minidrivers. When ax88179_tx_fixup() is called with NULL skb from usbnet_start_xmit(), I get a kernel crash.

    Backtrace:
    09:14:569>[0-553.5598] [<befaa194>] (ax88179_tx_fixup+0x0/0x16c [ax88179_178a]) from [<befef7a8>] (usbnet_start_xmit+0xa
    09:14:569>0/0x420 [usbnet])
    09:14:570>[0-553.5711]  r6:cb5ec280 r5:00000000 r4:cb5ebd40
    09:14:572>[0-553.5755] [<befef708>] (usbnet_start_xmit+0x0/0x420 [usbnet]) from [<c0400040>] (dev_hard_start_xmit+0x2ec/
    09:14:572>0x558)
    09:14:572>[0-553.5858] [<c03ffd54>] (dev_hard_start_xmit+0x0/0x558)
Quoted 2 lines

In case skb NULL check can not be added in usbnet_start_xmit() then NULL check is required in ax88179_tx_fixup() or asix_tx_fixup().

Yes.

Or you could add the check to usbnet_start_xmit() if you remove the ugly hack in the minidrivers calling usbnet_start_xmit with skb == NULL first. This is cdc_ncm and those depending on cdc_ncm.

But it would also be interesting to know why ax88179_tx_fixup() is called with a NULL skb. I believe this should not happen. Do you have any idea?

cdc_ncm, which is the driver depending on the NULL skb input, will explicitly call
usbnet_start_xmit(NULL, dev->net);

I don't know any other way this could happen.

Bjørn