Skip to contentSkip to conversation

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

PATCH Applied David B. Robins 2 participants 3 messages Sep 30, 2015 – Oct 5, 2015

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

PATCH 1/1 net: usb: asix: Fix crash on skb alloc failure

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
maintainer Applied
#1 lore raw

From: "David B. Robins" <[email protected]>
Date: Wed, 30 Sep 2015 16:20:04 -0400

Quoted 8 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.

Applied, thanks.

#2 lore raw
Quoted 8 lines · David Miller

From: "David B. Robins" <[email protected]>
Date: Wed, 30 Sep 2015 16:20:04 -0400

Quoted 5 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.

Quoted 5 lines
Quoted 3 lines

Found testing board with AX88772B devices.

Applied, thanks.

While I am happy for the patch I submitted to be applied, and it is consistent with existing error handling and does fix the specific issue, I believe a later series of 5 patches by Dean Jenkins that more comprehensively address the issue (grouped under subject "Improve ASIX RX memory allocation error handling") should be preferred.