Skip to content

Commit 56b786d

Browse files
mudongliangdavem330
authored andcommitted
net: usb: fix possible use-after-free in smsc75xx_bind
The commit 46a8b29 ("net: usb: fix memory leak in smsc75xx_bind") fails to clean up the work scheduled in smsc75xx_reset-> smsc75xx_set_multicast, which leads to use-after-free if the work is scheduled to start after the deallocation. In addition, this patch also removes a dangling pointer - dev->data[0]. This patch calls cancel_work_sync to cancel the scheduled work and set the dangling pointer to NULL. Fixes: 46a8b29 ("net: usb: fix memory leak in smsc75xx_bind") Signed-off-by: Dongliang Mu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8f26910 commit 56b786d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/net/usb/smsc75xx.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
14831483
ret = smsc75xx_wait_ready(dev, 0);
14841484
if (ret < 0) {
14851485
netdev_warn(dev->net, "device not ready in smsc75xx_bind\n");
1486-
goto err;
1486+
goto free_pdata;
14871487
}
14881488

14891489
smsc75xx_init_mac_address(dev);
@@ -1492,7 +1492,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
14921492
ret = smsc75xx_reset(dev);
14931493
if (ret < 0) {
14941494
netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret);
1495-
goto err;
1495+
goto cancel_work;
14961496
}
14971497

14981498
dev->net->netdev_ops = &smsc75xx_netdev_ops;
@@ -1503,8 +1503,11 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf)
15031503
dev->net->max_mtu = MAX_SINGLE_PACKET_SIZE;
15041504
return 0;
15051505

1506-
err:
1506+
cancel_work:
1507+
cancel_work_sync(&pdata->set_multicast);
1508+
free_pdata:
15071509
kfree(pdata);
1510+
dev->data[0] = 0;
15081511
return ret;
15091512
}
15101513

@@ -1515,7 +1518,6 @@ static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf)
15151518
cancel_work_sync(&pdata->set_multicast);
15161519
netif_dbg(dev, ifdown, dev->net, "free pdata\n");
15171520
kfree(pdata);
1518-
pdata = NULL;
15191521
dev->data[0] = 0;
15201522
}
15211523
}

0 commit comments

Comments
 (0)