YueHaibing
6ff7b06053
mdio_bus: Fix use-after-free on device_register fails
KASAN has found use-after-free in fixed_mdio_bus_init,
commit 0c692d0784 ("drivers/net/phy/mdio_bus.c: call
put_device on device_register() failure") call put_device()
while device_register() fails,give up the last reference
to the device and allow mdiobus_release to be executed
,kfreeing the bus. However in most drives, mdiobus_free
be called to free the bus while mdiobus_register fails.
use-after-free occurs when access bus again, this patch
revert it to let mdiobus_free free the bus.
KASAN report details as below:
BUG: KASAN: use-after-free in mdiobus_free+0x85/0x90 drivers/net/phy/mdio_bus.c:482
Read of size 4 at addr ffff8881dc824d78 by task syz-executor.0/3524
CPU: 1 PID: 3524 Comm: syz-executor.0 Not tainted 5.0.0-rc7+ #45
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0xfa/0x1ce lib/dump_stack.c:113
print_address_description+0x65/0x270 mm/kasan/report.c:187
kasan_report+0x149/0x18d mm/kasan/report.c:317
mdiobus_free+0x85/0x90 drivers/net/phy/mdio_bus.c:482
fixed_mdio_bus_init+0x283/0x1000 [fixed_phy]
? 0xffffffffc0e40000
? 0xffffffffc0e40000
? 0xffffffffc0e40000
do_one_initcall+0xfa/0x5ca init/main.c:887
do_init_module+0x204/0x5f6 kernel/module.c:3460
load_module+0x66b2/0x8570 kernel/module.c:3808
__do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x462e99
Code: f7 d8 64 89 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f6215c19c58 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
RAX: ffffffffffffffda RBX: 000000000073bf00 RCX: 0000000000462e99
RDX: 0000000000000000 RSI: 0000000020000080 RDI: 0000000000000003
RBP: 00007f6215c19c70 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f6215c1a6bc
R13: 00000000004bcefb R14: 00000000006f7030 R15: 0000000000000004
Allocated by task 3524:
set_track mm/kasan/common.c:85 [inline]
__kasan_kmalloc.constprop.3+0xa0/0xd0 mm/kasan/common.c:496
kmalloc include/linux/slab.h:545 [inline]
kzalloc include/linux/slab.h:740 [inline]
mdiobus_alloc_size+0x54/0x1b0 drivers/net/phy/mdio_bus.c:143
fixed_mdio_bus_init+0x163/0x1000 [fixed_phy]
do_one_initcall+0xfa/0x5ca init/main.c:887
do_init_module+0x204/0x5f6 kernel/module.c:3460
load_module+0x66b2/0x8570 kernel/module.c:3808
__do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Freed by task 3524:
set_track mm/kasan/common.c:85 [inline]
__kasan_slab_free+0x130/0x180 mm/kasan/common.c:458
slab_free_hook mm/slub.c:1409 [inline]
slab_free_freelist_hook mm/slub.c:1436 [inline]
slab_free mm/slub.c:2986 [inline]
kfree+0xe1/0x270 mm/slub.c:3938
device_release+0x78/0x200 drivers/base/core.c:919
kobject_cleanup lib/kobject.c:662 [inline]
kobject_release lib/kobject.c:691 [inline]
kref_put include/linux/kref.h:67 [inline]
kobject_put+0x146/0x240 lib/kobject.c:708
put_device+0x1c/0x30 drivers/base/core.c:2060
__mdiobus_register+0x483/0x560 drivers/net/phy/mdio_bus.c:382
fixed_mdio_bus_init+0x26b/0x1000 [fixed_phy]
do_one_initcall+0xfa/0x5ca init/main.c:887
do_init_module+0x204/0x5f6 kernel/module.c:3460
load_module+0x66b2/0x8570 kernel/module.c:3808
__do_sys_finit_module+0x238/0x2a0 kernel/module.c:3902
do_syscall_64+0x147/0x600 arch/x86/entry/common.c:290
entry_SYSCALL_64_after_hwframe+0x49/0xbe
The buggy address belongs to the object at ffff8881dc824c80
which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 248 bytes inside of
2048-byte region [ffff8881dc824c80, ffff8881dc825480)
The buggy address belongs to the page:
page:ffffea0007720800 count:1 mapcount:0 mapping:ffff8881f6c02800 index:0x0 compound_mapcount: 0
flags: 0x2fffc0000010200(slab|head)
raw: 02fffc0000010200 0000000000000000 0000000500000001 ffff8881f6c02800
raw: 0000000000000000 00000000800f000f 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8881dc824c00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8881dc824c80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff8881dc824d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8881dc824d80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881dc824e00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
Fixes: 0c692d0784 ("drivers/net/phy/mdio_bus.c: call put_device on device_register() failure")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-02-22 15:34:07 -08:00
..
2019-02-07 12:24:28 +01:00
2019-02-01 15:50:26 +01:00
2019-02-06 12:47:09 -07:00
2019-01-17 11:27:00 -08:00
2019-02-15 19:48:39 +01:00
2019-02-08 10:53:44 -08:00
2019-02-12 09:13:18 -07:00
2018-12-19 13:43:42 +01:00
2019-01-29 07:53:47 -08:00
2018-12-29 08:20:44 -07:00
2019-01-25 13:03:34 -10:00
2019-01-24 11:41:48 -08:00
2019-01-29 07:53:47 -08:00
2019-01-11 10:09:51 +01:00
2019-01-30 22:57:42 +01:00
2019-02-15 08:11:43 -08:00
2018-12-28 12:11:47 -08:00
2018-12-11 11:40:13 +09:00
2019-02-10 10:39:37 -08:00
2019-01-04 13:13:46 -08:00
2019-01-24 17:13:59 +01:00
2019-01-22 20:40:59 -05:00
2019-02-17 09:22:01 -08:00
2019-01-31 16:19:48 +01:00
2018-12-10 10:17:45 +01:00
2019-01-28 15:28:43 +01:00
2019-02-15 13:08:08 +10:00
2019-01-29 12:09:11 +01:00
2019-01-09 19:20:31 -05:00
2019-01-27 18:55:49 -08:00
2019-01-03 11:42:10 -08:00
2018-12-19 20:21:06 +01:00
2019-02-15 09:45:05 +01:00
2019-01-26 11:14:25 +01:00
2019-01-31 08:25:09 -07:00
2019-02-03 13:10:41 +01:00
2019-01-29 13:57:22 -07:00
2019-02-17 08:30:35 -08:00
2019-02-08 15:34:10 -08:00
2019-02-10 09:54:19 -08:00
2019-02-05 16:39:29 -08:00
2019-01-17 22:27:39 +01:00
2018-12-22 14:45:35 -07:00
2019-01-03 18:57:57 -08:00
2019-02-18 10:40:58 -06:00
2019-02-15 09:12:28 -08:00
2019-01-16 11:13:25 -05:00
2019-01-05 11:30:37 -08:00
2018-12-28 16:52:18 -08:00
2018-12-18 23:13:12 -05:00
2019-01-29 10:55:34 +01:00
2019-02-01 15:53:54 +01:00
2019-02-13 08:41:15 +01:00
2019-02-06 09:39:22 +01:00
2019-02-22 15:34:07 -08:00
2019-01-08 07:58:37 -05:00
2019-01-21 09:57:43 -08:00
2019-02-12 09:29:07 +01:00
2019-01-16 12:49:53 -06:00
2019-01-04 12:19:40 +01:00
2018-12-29 13:40:29 -08:00
2019-02-08 15:32:10 -08:00
2019-01-05 11:23:17 -08:00
2019-01-04 10:13:27 +00:00
2019-01-25 12:57:09 -10:00
2019-01-22 10:52:39 +01:00
2019-01-29 10:59:07 +01:00
2019-01-03 18:57:57 -08:00
2018-12-28 20:22:45 -08:00
2018-12-29 13:03:29 -08:00
2019-01-08 16:22:56 -05:00
2018-12-24 12:06:56 +01:00
2019-01-08 07:58:37 -05:00
2018-12-22 00:25:54 +09:00
2018-12-21 13:43:35 +00:00
2019-01-14 20:15:19 -05:00
2019-01-07 16:38:51 +01:00
2019-01-01 13:24:31 -08:00
2019-02-11 10:28:48 -08:00
2018-12-26 10:32:18 -08:00
2019-02-15 13:36:43 -08:00
2019-01-30 11:14:04 +01:00
2019-01-08 07:58:37 -05:00
2019-02-08 10:51:59 -08:00
2019-02-04 21:40:32 -05:00
2018-12-31 13:06:30 -08:00
2019-02-05 15:50:13 -08:00
2019-02-08 10:49:55 -08:00
2018-12-28 20:54:57 -08:00
2019-01-31 09:14:00 +01:00
2019-01-23 08:20:43 -07:00
2019-02-19 13:14:45 -08:00
2019-01-25 12:58:40 -10:00
2019-02-05 15:29:48 -05:00
2018-12-22 00:25:54 +09:00
2019-01-07 10:10:35 +01:00
2019-01-23 22:14:56 +01:00
2018-12-29 13:40:29 -08:00