Message ID | 9e768a837391af216cf1d2c8ac08af41f28cb147.1509654127.git.andreyknvl@google.com |
---|---|
State | Accepted, archived |
Delegated to: | David Miller |
Headers | show |
Series | net: usb: asix: fill null-ptr-deref in asix_suspend | expand |
From: Andrey Konovalov <andreyknvl@google.com> Date: Thu, 2 Nov 2017 21:26:59 +0100 > When asix_suspend() is called dev->driver_priv might not have been > assigned a value, so we need to check that it's not NULL. > > Found by syzkaller. ... > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> Applied, thank you.
Am Donnerstag, den 02.11.2017, 21:26 +0100 schrieb Andrey Konovalov: > When asix_suspend() is called dev->driver_priv might not have been > assigned a value, so we need to check that it's not NULL. > > Found by syzkaller. Hi, 1. if that happens on suspend, it will also happen on resume 2. Will a device work after that? The appropriate fix may be to wait until the device is properly initialized. Regards Oliver
On Mon, Nov 6, 2017 at 10:49 AM, Oliver Neukum <oneukum@suse.com> wrote: > Am Donnerstag, den 02.11.2017, 21:26 +0100 schrieb Andrey Konovalov: >> When asix_suspend() is called dev->driver_priv might not have been >> assigned a value, so we need to check that it's not NULL. >> >> Found by syzkaller. > > Hi, Hi Oliver, > > 1. if that happens on suspend, it will also happen on resume Indeed, got crashes in asix_resume() tonight as well. Mailed v2. > 2. Will a device work after that? The appropriate fix may be to wait > until the device is properly initialized. This shouldn't affect real devices as far as I understand. The crash can be caused by a crafted malicious device. Go ahead if you see a better way to fix this, my patch is more of a hot fix trying to prevent the crashes. Thanks! > > Regards > Oliver >
Am Montag, den 06.11.2017, 13:30 +0100 schrieb Andrey Konovalov: > On Mon, Nov 6, 2017 at 10:49 AM, Oliver Neukum <oneukum@suse.com> wrote: > > > > > > 2. Will a device work after that? The appropriate fix may be to wait > > until the device is properly initialized. > > This shouldn't affect real devices as far as I understand. The crash > can be caused by a crafted malicious device. Hi! Hm. That seems strange as driver_priv is kmalloced. Do you still have a descriptor that causes this? Shouldn't we rather reject such a broken device? Regards Oliver
On Mon, Nov 6, 2017 at 4:20 PM, Oliver Neukum <oneukum@suse.com> wrote: > Am Montag, den 06.11.2017, 13:30 +0100 schrieb Andrey Konovalov: >> On Mon, Nov 6, 2017 at 10:49 AM, Oliver Neukum <oneukum@suse.com> wrote: >> > >> > >> > 2. Will a device work after that? The appropriate fix may be to wait >> > until the device is properly initialized. >> >> This shouldn't affect real devices as far as I understand. The crash >> can be caused by a crafted malicious device. > > Hi! > > Hm. That seems strange as driver_priv is kmalloced. Do you > still have a descriptor that causes this? > Shouldn't we rather reject such a broken device? I do have a way to reproduce this. As far as I understand, for this particular device ax88172_bind() is called, which doesn't assign anything to dev->driver_priv, so that's why it is NULL in suspend() and resume(). > > Regards > Oliver >
Am Montag, den 06.11.2017, 17:05 +0100 schrieb Andrey Konovalov: > On Mon, Nov 6, 2017 at 4:20 PM, Oliver Neukum <oneukum@suse.com> wrote: > > > I do have a way to reproduce this. > > As far as I understand, for this particular device ax88172_bind() is > called, which doesn't assign anything to dev->driver_priv, so that's > why it is NULL in suspend() and resume(). Thanks and ouch. That means it never worked for those devices. That makes this a rather serious bug and your fix is right. Regards Oliver
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c index b2ff88e69a81..743416be84f3 100644 --- a/drivers/net/usb/asix_devices.c +++ b/drivers/net/usb/asix_devices.c @@ -626,7 +626,7 @@ static int asix_suspend(struct usb_interface *intf, pm_message_t message) struct usbnet *dev = usb_get_intfdata(intf); struct asix_common_private *priv = dev->driver_priv; - if (priv->suspend) + if (priv && priv->suspend) priv->suspend(dev); return usbnet_suspend(intf, message);
When asix_suspend() is called dev->driver_priv might not have been assigned a value, so we need to check that it's not NULL. Found by syzkaller. kasan: CONFIG_KASAN_INLINE enabled kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] PREEMPT SMP KASAN Modules linked in: CPU: 0 PID: 24 Comm: kworker/0:1 Not tainted 4.14.0-rc4-43422-geccacdd69a8c #400 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Workqueue: usb_hub_wq hub_event task: ffff88006bb36300 task.stack: ffff88006bba8000 RIP: 0010:asix_suspend+0x76/0xc0 drivers/net/usb/asix_devices.c:629 RSP: 0018:ffff88006bbae718 EFLAGS: 00010202 RAX: dffffc0000000000 RBX: ffff880061ba3b80 RCX: 1ffff1000c34d644 RDX: 0000000000000001 RSI: 0000000000000402 RDI: 0000000000000008 RBP: ffff88006bbae738 R08: 1ffff1000d775cad R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: ffff8800630a8b40 R13: 0000000000000000 R14: 0000000000000402 R15: ffff880061ba3b80 FS: 0000000000000000(0000) GS:ffff88006c600000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007ff33cf89000 CR3: 0000000061c0a000 CR4: 00000000000006f0 Call Trace: usb_suspend_interface drivers/usb/core/driver.c:1209 usb_suspend_both+0x27f/0x7e0 drivers/usb/core/driver.c:1314 usb_runtime_suspend+0x41/0x120 drivers/usb/core/driver.c:1852 __rpm_callback+0x339/0xb60 drivers/base/power/runtime.c:334 rpm_callback+0x106/0x220 drivers/base/power/runtime.c:461 rpm_suspend+0x465/0x1980 drivers/base/power/runtime.c:596 __pm_runtime_suspend+0x11e/0x230 drivers/base/power/runtime.c:1009 pm_runtime_put_sync_autosuspend ./include/linux/pm_runtime.h:251 usb_new_device+0xa37/0x1020 drivers/usb/core/hub.c:2487 hub_port_connect drivers/usb/core/hub.c:4903 hub_port_connect_change drivers/usb/core/hub.c:5009 port_event drivers/usb/core/hub.c:5115 hub_event+0x194d/0x3740 drivers/usb/core/hub.c:5195 process_one_work+0xc7f/0x1db0 kernel/workqueue.c:2119 worker_thread+0x221/0x1850 kernel/workqueue.c:2253 kthread+0x3a1/0x470 kernel/kthread.c:231 ret_from_fork+0x2a/0x40 arch/x86/entry/entry_64.S:431 Code: 8d 7c 24 20 48 89 fa 48 c1 ea 03 80 3c 02 00 75 5b 48 b8 00 00 00 00 00 fc ff df 4d 8b 6c 24 20 49 8d 7d 08 48 89 fa 48 c1 ea 03 <80> 3c 02 00 75 34 4d 8b 6d 08 4d 85 ed 74 0b e8 26 2b 51 fd 4c RIP: asix_suspend+0x76/0xc0 RSP: ffff88006bbae718 ---[ end trace dfc4f5649284342c ]--- Signed-off-by: Andrey Konovalov <andreyknvl@google.com> --- drivers/net/usb/asix_devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)