All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usbnet: smsc95xx: Fix use-after-free after removal
@ 2020-06-21 10:43 Tuomas Tynkkynen
  2020-06-22 23:34 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Tuomas Tynkkynen @ 2020-06-21 10:43 UTC (permalink / raw)
  To: steve.glendinning
  Cc: UNGLinuxDriver, davem, kuba, netdev, linux-usb, linux-kernel,
	Tuomas Tynkkynen

Syzbot reports an use-after-free in workqueue context:

BUG: KASAN: use-after-free in mutex_unlock+0x19/0x40 kernel/locking/mutex.c:737
 mutex_unlock+0x19/0x40 kernel/locking/mutex.c:737
 __smsc95xx_mdio_read drivers/net/usb/smsc95xx.c:217 [inline]
 smsc95xx_mdio_read+0x583/0x870 drivers/net/usb/smsc95xx.c:278
 check_carrier+0xd1/0x2e0 drivers/net/usb/smsc95xx.c:644
 process_one_work+0x777/0xf90 kernel/workqueue.c:2274
 worker_thread+0xa8f/0x1430 kernel/workqueue.c:2420
 kthread+0x2df/0x300 kernel/kthread.c:255

It looks like that smsc95xx_unbind() is freeing the structures that are
still in use by the concurrently running workqueue callback. Thus switch
to using cancel_delayed_work_sync() to ensure the work callback really
is no longer active.

Reported-by: syzbot+29dc7d4ae19b703ff947@syzkaller.appspotmail.com
Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
---
Compile tested only.
---
 drivers/net/usb/smsc95xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 355be77f4241..3cf4dc3433f9 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1324,7 +1324,7 @@ static void smsc95xx_unbind(struct usbnet *dev, struct usb_interface *intf)
 	struct smsc95xx_priv *pdata = (struct smsc95xx_priv *)(dev->data[0]);
 
 	if (pdata) {
-		cancel_delayed_work(&pdata->carrier_check);
+		cancel_delayed_work_sync(&pdata->carrier_check);
 		netif_dbg(dev, ifdown, dev->net, "free pdata\n");
 		kfree(pdata);
 		pdata = NULL;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usbnet: smsc95xx: Fix use-after-free after removal
  2020-06-21 10:43 [PATCH] usbnet: smsc95xx: Fix use-after-free after removal Tuomas Tynkkynen
@ 2020-06-22 23:34 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-06-22 23:34 UTC (permalink / raw)
  To: tuomas.tynkkynen
  Cc: steve.glendinning, UNGLinuxDriver, kuba, netdev, linux-usb, linux-kernel

From: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
Date: Sun, 21 Jun 2020 13:43:26 +0300

> Syzbot reports an use-after-free in workqueue context:
> 
> BUG: KASAN: use-after-free in mutex_unlock+0x19/0x40 kernel/locking/mutex.c:737
>  mutex_unlock+0x19/0x40 kernel/locking/mutex.c:737
>  __smsc95xx_mdio_read drivers/net/usb/smsc95xx.c:217 [inline]
>  smsc95xx_mdio_read+0x583/0x870 drivers/net/usb/smsc95xx.c:278
>  check_carrier+0xd1/0x2e0 drivers/net/usb/smsc95xx.c:644
>  process_one_work+0x777/0xf90 kernel/workqueue.c:2274
>  worker_thread+0xa8f/0x1430 kernel/workqueue.c:2420
>  kthread+0x2df/0x300 kernel/kthread.c:255
> 
> It looks like that smsc95xx_unbind() is freeing the structures that are
> still in use by the concurrently running workqueue callback. Thus switch
> to using cancel_delayed_work_sync() to ensure the work callback really
> is no longer active.
> 
> Reported-by: syzbot+29dc7d4ae19b703ff947@syzkaller.appspotmail.com
> Signed-off-by: Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-22 23:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-21 10:43 [PATCH] usbnet: smsc95xx: Fix use-after-free after removal Tuomas Tynkkynen
2020-06-22 23:34 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.