Skip to contentSkip to conversation

net: usb: asix: Fix crash on skb alloc failure

PATCH Dean Jenkins 1 participant 1 message Oct 1, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 30 lines

If asix_rx_fixup_internal() fails to allocate rx->ax_skb, it will return but not clear rx->size. rx points to driver private data. A later call assumes that nonzero size means ax_skb was allocated and passes a null ax_skb to skb_put. Changed allocation failure return to clear size first.

Found testing board with AX88772B devices.

---
  drivers/net/usb/asix_common.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/usb/asix_common.c +3 -1
index 75d6f26..079069a 100644
@@ -91,8 +91,10 @@ int asix_rx_fixup_internal(struct usbnet *dev, struct sk_buff *skb,
  			}
  			rx->ax_skb = netdev_alloc_skb_ip_align(dev->net,
  							       rx->size);
-			if (!rx->ax_skb)
+			if (!rx->ax_skb) {
+				rx->size = 0;
  				return 0;
+			}
  		}
 
  		if (rx->size > dev->net->mtu + ETH_HLEN + VLAN_HLEN) {
Signature · 1 line
1.9.1

Hi David,

I copied your patch from http://www.spinics.net/lists/netdev/msg345724.html and resubscribed to [email protected] so I am unable to directly reply to your original post. But I should now see any subsequent reply on the mailing list.

We are preparing to release some fixes in this area of the asix driver which fixes your observation. Unfortunately, your simple proposal has a flaw because state variables exist outside of the scope of asix_rx_fixup_internal() which handles Ethernet frames spanning multiple URBs (depends on the variant of the USB ASIX chipset). Therefore, subsequent URBs with the remainder of the Ethernet frame need to be handled when no netdev socket buffer exists.

We intend to release the patches within the next few days so please watch out for them.

Regards,
Dean

Signature · 5 lines
Dean Jenkins
Embedded Software Engineer
Linux Transportation Solutions
Mentor Embedded Software Division
Mentor Graphics (UK) Ltd.