Re: KASAN: use-after-free Read in bpf_cgroup_storage_release

From: Daniel Borkmann
Date: Thu Aug 02 2018 - 15:23:10 EST


[ +Roman ]

On 08/02/2018 07:59 PM, syzbot wrote:
> Hello,
>
> syzbot found the following crash on:
>
> HEAD commit:ÂÂÂ fc2a3b5dd618 Merge branch 'bpf-cgroup-local-storage'
> git tree:ÂÂÂÂÂÂ bpf-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=17a6a1c8400000
> kernel config:Â https://syzkaller.appspot.com/x/.config?x=3bfcc1651962483
> dashboard link: https://syzkaller.appspot.com/bug?extid=25554ab865a12b51c66f
> compiler:ÂÂÂÂÂÂ gcc (GCC) 8.0.1 20180413 (experimental)
> syzkaller repro:https://syzkaller.appspot.com/x/repro.syz?x=12c4b9b4400000
> C reproducer:ÂÂ https://syzkaller.appspot.com/x/repro.c?x=13e9d6f0400000
>
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+25554ab865a12b51c66f@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> ==================================================================
> BUG: KASAN: use-after-free in debug_spin_lock_before kernel/locking/spinlock_debug.c:83 [inline]
> BUG: KASAN: use-after-free in do_raw_spin_lock+0x1c0/0x200 kernel/locking/spinlock_debug.c:112
> Read of size 4 at addr ffff8801c4723644 by task syz-executor865/9746
>
> CPU: 0 PID: 9746 Comm: syz-executor865 Not tainted 4.18.0-rc5+ #68
> 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+0x1c9/0x2b4 lib/dump_stack.c:113
> Âprint_address_description+0x6c/0x20b mm/kasan/report.c:256
> Âkasan_report_error mm/kasan/report.c:354 [inline]
> Âkasan_report.cold.7+0x242/0x2fe mm/kasan/report.c:412
> Â__asan_report_load4_noabort+0x14/0x20 mm/kasan/report.c:432
> Âdebug_spin_lock_before kernel/locking/spinlock_debug.c:83 [inline]
> Âdo_raw_spin_lock+0x1c0/0x200 kernel/locking/spinlock_debug.c:112
> Â__raw_spin_lock_bh include/linux/spinlock_api_smp.h:136 [inline]
> Â_raw_spin_lock_bh+0x39/0x40 kernel/locking/spinlock.c:168
> Âspin_lock_bh include/linux/spinlock.h:315 [inline]
> Âbpf_cgroup_storage_release+0x2c/0x110 kernel/bpf/local_storage.c:276
> Âfree_used_maps+0x81/0x200 kernel/bpf/syscall.c:961
> Âbpf_prog_load+0x17ba/0x1c90 kernel/bpf/syscall.c:1414
> Â__do_sys_bpf kernel/bpf/syscall.c:2338 [inline]
> Â__se_sys_bpf kernel/bpf/syscall.c:2300 [inline]
> Â__x64_sys_bpf+0x36c/0x510 kernel/bpf/syscall.c:2300
> Âdo_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
> Âentry_SYSCALL_64_after_hwframe+0x49/0xbe
> RIP: 0033:0x4490d9
> Code: e8 8c bb 02 00 48 83 c4 18 c3 0f 1f 80 00 00 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 0f 83 4b 00 fc ff c3 66 2e 0f 1f 84 00 00 00 00
> RSP: 002b:00007f6096d1ace8 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
> RAX: ffffffffffffffda RBX: 00000000006e5a08 RCX: 00000000004490d9
> RDX: 0000000000000048 RSI: 000000002001a840 RDI: 0000000000000005
> RBP: 00000000006e5a00 R08: 0000000000000000 R09: 0000000000000000
> R10: 0000000000000000 R11: 0000000000000246 R12: 00000000006e5a0c
> R13: 00007fffd579e24f R14: 00007f6096d1b9c0 R15: 0000000000000019
>
> Allocated by task 9746:
> Âsave_stack+0x43/0xd0 mm/kasan/kasan.c:448
> Âset_track mm/kasan/kasan.c:460 [inline]
> Âkasan_kmalloc+0xc4/0xe0 mm/kasan/kasan.c:553
> Âkmem_cache_alloc_node_trace+0x150/0x770 mm/slab.c:3663
> Âkmalloc_node include/linux/slab.h:551 [inline]
> Âcgroup_storage_map_alloc+0x26d/0x400 kernel/bpf/local_storage.c:209
> Âfind_and_alloc_map kernel/bpf/syscall.c:129 [inline]
> Âmap_create+0x37f/0xe20 kernel/bpf/syscall.c:481
> Â__do_sys_bpf kernel/bpf/syscall.c:2323 [inline]
> Â__se_sys_bpf kernel/bpf/syscall.c:2300 [inline]
> Â__x64_sys_bpf+0x303/0x510 kernel/bpf/syscall.c:2300
> Âdo_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
> Âentry_SYSCALL_64_after_hwframe+0x49/0xbe
>
> Freed by task 19:
> Âsave_stack+0x43/0xd0 mm/kasan/kasan.c:448
> Âset_track mm/kasan/kasan.c:460 [inline]
> Â__kasan_slab_free+0x11a/0x170 mm/kasan/kasan.c:521
> Âkasan_slab_free+0xe/0x10 mm/kasan/kasan.c:528
> Â__cache_free mm/slab.c:3498 [inline]
> Âkfree+0xd9/0x260 mm/slab.c:3813
> Âcgroup_storage_map_free+0x16e/0x210 kernel/bpf/local_storage.c:234
> Âbpf_map_free_deferred+0xba/0xf0 kernel/bpf/syscall.c:290
> Âprocess_one_work+0xc73/0x1ba0 kernel/workqueue.c:2153
> Âworker_thread+0x189/0x13c0 kernel/workqueue.c:2296
> Âkthread+0x345/0x410 kernel/kthread.c:246
> Âret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:412
>
> The buggy address belongs to the object at ffff8801c4723540
> Âwhich belongs to the cache kmalloc-512 of size 512
> The buggy address is located 260 bytes inside of
> Â512-byte region [ffff8801c4723540, ffff8801c4723740)
> The buggy address belongs to the page:
> page:ffffea000711c8c0 count:1 mapcount:0 mapping:ffff8801dac00940 index:0xffff8801c4723a40
> flags: 0x2fffc0000000100(slab)
> raw: 02fffc0000000100 ffffea0007299088 ffffea00072247c8 ffff8801dac00940
> raw: ffff8801c4723a40 ffff8801c4723040 0000000100000004 0000000000000000
> page dumped because: kasan: bad access detected
>
> Memory state around the buggy address:
> Âffff8801c4723500: fc fc fc fc fc fc fc fc fb fb fb fb fb fb fb fb
> Âffff8801c4723580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>> ffff8801c4723600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
> Âffff8801c4723680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> Âffff8801c4723700: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
> ==================================================================
>
>
> ---
> This bug is generated by a bot. It may contain errors.
> See https://goo.gl/tpsmEJ for more information about syzbot.
> syzbot engineers can be reached at syzkaller@xxxxxxxxxxxxxxxxx
>
> syzbot will keep track of this bug report. See:
> https://goo.gl/tpsmEJ#bug-status-tracking for how to communicate with syzbot.
> syzbot can test patches for this bug, for details see:
> https://goo.gl/tpsmEJ#testing-patches