Eric Dumazet
8aaeed81fc
bpf: Fix error path in htab_map_alloc()
syzbot was able to trigger a use-after-free in htab_map_alloc() [1]
htab_map_alloc() lacks a call to lockdep_unregister_key() in its error path.
lockdep_register_key() and lockdep_unregister_key() can not fail,
it seems better to use them right after htab allocation and before
htab freeing, avoiding more goto/labels in htab_map_alloc()
[1]
BUG: KASAN: use-after-free in lockdep_register_key+0x356/0x3e0 kernel/locking/lockdep.c:1182
Read of size 8 at addr ffff88805fa67ad8 by task syz-executor.3/2356
CPU: 1 PID: 2356 Comm: syz-executor.3 Not tainted 5.9.0-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x107/0x163 lib/dump_stack.c:118
print_address_description.constprop.0.cold+0xae/0x4c8 mm/kasan/report.c:385
__kasan_report mm/kasan/report.c:545 [inline]
kasan_report.cold+0x1f/0x37 mm/kasan/report.c:562
lockdep_register_key+0x356/0x3e0 kernel/locking/lockdep.c:1182
htab_init_buckets kernel/bpf/hashtab.c:144 [inline]
htab_map_alloc+0x6c5/0x14a0 kernel/bpf/hashtab.c:521
find_and_alloc_map kernel/bpf/syscall.c:122 [inline]
map_create kernel/bpf/syscall.c:825 [inline]
__do_sys_bpf+0xa80/0x5180 kernel/bpf/syscall.c:4381
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45deb9
Code: 0d b4 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 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 0f 83 db b3 fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f0eafee1c78 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 0000000000001a00 RCX: 000000000045deb9
RDX: 0000000000000040 RSI: 0000000020000040 RDI: 405a020000000000
RBP: 000000000118bf60 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000118bf2c
R13: 00007ffd3cf9eabf R14: 00007f0eafee29c0 R15: 000000000118bf2c
Allocated by task 2053:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_set_track mm/kasan/common.c:56 [inline]
__kasan_kmalloc.constprop.0+0xc2/0xd0 mm/kasan/common.c:461
kmalloc include/linux/slab.h:554 [inline]
kzalloc include/linux/slab.h:666 [inline]
htab_map_alloc+0xdf/0x14a0 kernel/bpf/hashtab.c:454
find_and_alloc_map kernel/bpf/syscall.c:122 [inline]
map_create kernel/bpf/syscall.c:825 [inline]
__do_sys_bpf+0xa80/0x5180 kernel/bpf/syscall.c:4381
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
Freed by task 2053:
kasan_save_stack+0x1b/0x40 mm/kasan/common.c:48
kasan_set_track+0x1c/0x30 mm/kasan/common.c:56
kasan_set_free_info+0x1b/0x30 mm/kasan/generic.c:355
__kasan_slab_free+0x102/0x140 mm/kasan/common.c:422
slab_free_hook mm/slub.c:1544 [inline]
slab_free_freelist_hook+0x5d/0x150 mm/slub.c:1577
slab_free mm/slub.c:3142 [inline]
kfree+0xdb/0x360 mm/slub.c:4124
htab_map_alloc+0x3f9/0x14a0 kernel/bpf/hashtab.c:549
find_and_alloc_map kernel/bpf/syscall.c:122 [inline]
map_create kernel/bpf/syscall.c:825 [inline]
__do_sys_bpf+0xa80/0x5180 kernel/bpf/syscall.c:4381
do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
entry_SYSCALL_64_after_hwframe+0x44/0xa9
The buggy address belongs to the object at ffff88805fa67800
which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 728 bytes inside of
1024-byte region [ffff88805fa67800, ffff88805fa67c00)
The buggy address belongs to the page:
page:000000003c5582c4 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x5fa60
head:000000003c5582c4 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head)
raw: 00fff00000010200 ffffea0000bc1200 0000000200000002 ffff888010041140
raw: 0000000000000000 0000000000100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88805fa67980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805fa67a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88805fa67b00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88805fa67b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
Fixes: c50eb518e2 ("bpf: Use separate lockdep class for each hashtab")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20201102114100.3103180-1-eric.dumazet@gmail.com
2020-11-02 17:20:21 +01:00
..
2020-11-02 17:20:21 +01:00
2020-10-16 11:11:19 -07:00
2020-04-07 10:43:42 -07:00
2020-10-01 14:44:08 +01:00
2020-10-16 11:11:19 -07:00
2020-10-23 10:06:38 -07:00
2020-10-17 15:05:30 -06:00
2020-09-11 09:33:54 -07:00
2020-10-17 15:05:30 -06:00
2020-10-16 11:11:19 -07:00
2020-10-16 11:11:19 -07:00
2020-10-18 14:34:50 -07:00
2020-10-16 11:11:19 -07:00
2020-10-16 12:52:37 -07:00
2020-10-18 14:34:50 -07:00
2020-10-17 15:05:30 -06:00
2020-10-18 14:34:50 -07:00
2020-10-16 14:56:52 -07:00
2020-03-25 11:50:48 +01:00
2020-10-16 11:11:19 -07:00
2020-07-16 12:35:15 -07:00
2020-07-27 23:25:50 +02:00
2020-08-06 19:29:51 -07:00
2020-07-27 23:25:50 +02:00
2020-08-26 09:10:39 -04:00
2020-08-17 20:26:58 -04:00
2020-08-23 17:36:59 -05:00
2020-08-04 14:20:26 -07:00
2020-07-30 11:15:58 -07:00
2020-08-23 17:36:59 -05:00
2020-08-23 17:36:59 -05:00
2020-06-11 15:14:36 +02:00
2020-09-01 09:58:03 +02:00
2020-06-03 13:06:42 -07:00
2020-08-12 10:58:01 -07:00
2020-04-15 11:21:54 +02:00
2020-05-20 14:44:21 -05:00
2020-10-18 09:27:10 -07:00
2020-04-07 10:43:42 -07:00
2020-10-16 11:11:19 -07:00
2020-10-16 11:11:19 -07:00
2020-06-06 23:42:01 +09:00
2020-06-02 10:59:11 -07:00
2020-06-08 11:05:56 -07:00
2020-05-28 10:54:15 +02:00
2020-10-16 11:11:19 -07:00
2020-08-23 17:36:59 -05:00
2020-03-25 10:04:01 -05:00
2020-08-12 10:58:02 -07:00
2020-10-16 11:11:19 -07:00
2020-10-16 11:11:18 -07:00
2020-10-05 13:37:03 +02:00
2020-08-12 10:58:01 -07:00
2020-10-15 15:51:28 -07:00
2020-10-16 11:11:19 -07:00
2020-04-27 02:07:40 -04:00
2020-10-22 13:13:57 -07:00
2020-10-22 13:08:57 -07:00
2020-09-01 09:58:03 +02:00
2020-07-08 11:14:22 +02:00
2020-09-04 17:51:55 +10:00
2020-10-16 11:11:22 -07:00
2020-07-28 13:44:53 +02:00
2020-10-16 11:11:19 -07:00
2020-10-18 09:27:10 -07:00
2020-10-16 11:11:19 -07:00
2020-07-01 12:09:13 +03:00
2020-07-27 14:31:12 -04:00
2020-10-16 11:11:22 -07:00
2020-10-16 11:11:18 -07:00
2020-08-24 18:38:38 -07:00
2020-08-07 11:33:25 -07:00
2020-10-08 13:17:47 -07:00
2020-08-23 17:36:59 -05:00
2020-10-18 14:34:50 -07:00
2020-09-16 15:18:56 +02:00
2020-09-19 13:13:39 -07:00
2020-09-18 14:24:16 +01:00
2020-10-02 21:18:25 +02:00
2020-10-18 09:27:10 -07:00
2020-10-16 11:11:19 -07:00
2020-09-17 10:26:41 -07:00
2020-10-17 15:05:30 -06:00
2020-10-02 19:11:12 -07:00
2020-06-29 12:01:45 -07:00
2020-10-02 21:18:25 +02:00
2020-04-07 21:51:27 +02:00
2020-10-06 10:31:52 -07:00
2020-10-16 11:11:19 -07:00
2020-06-04 19:06:24 -07:00
2020-07-07 11:58:59 -05:00
2020-04-27 02:07:40 -04:00
2020-05-09 13:57:12 +02:00
2020-08-17 09:39:18 -07:00
2020-06-08 11:05:56 -07:00
2020-10-16 07:28:20 +02:00