syzbot


KASAN: use-after-free Write in hci_sock_release
Status: upstream: reported C repro on 2018/10/23 14:38
Reported-by: syzbot+b364ed862aa07c74bc62@syzkaller.appspotmail.com
First crash: 1311d, last: 769d

Cause bisection: introduced by (bisect log) :
commit c470abd4fde40ea6a0846a2beab642a578c0b8cd
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sun Feb 19 22:34:00 2017 +0000

  Linux 4.10


Fix bisection: fixed by (bisect log) :
commit f1e67e355c2aafeddf1eac31335709236996d2fe
Author: Thomas Gleixner <tglx@linutronix.de>
Date: Mon Nov 18 13:28:24 2019 +0000

  fs/buffer: Make BH_Uptodate_Lock bit_spin_lock a regular spinlock_t

Patch testing requests:
Created Duration User Patch Repo Result
2021/03/15 02:39 17m ducheng2@gmail.com upstream OK
2019/03/25 19:49 10m xiyou.wangcong@gmail.com upstream report log

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in atomic_dec include/asm-generic/atomic-instrumented.h:127 [inline]
BUG: KASAN: use-after-free in hci_sock_release+0x154/0x3c0 net/bluetooth/hci_sock.c:873
Write of size 4 at addr ffff888098651620 by task syz-executor472/8899

CPU: 1 PID: 8899 Comm: syz-executor472 Not tainted 4.20.0+ #8
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+0x1db/0x2d0 lib/dump_stack.c:113
 print_address_description.cold+0x7c/0x20d mm/kasan/report.c:187
 kasan_report.cold+0x1b/0x40 mm/kasan/report.c:317
 check_memory_region_inline mm/kasan/generic.c:185 [inline]
 check_memory_region+0x123/0x190 mm/kasan/generic.c:191
 kasan_check_write+0x14/0x20 mm/kasan/common.c:106
 atomic_dec include/asm-generic/atomic-instrumented.h:127 [inline]
 hci_sock_release+0x154/0x3c0 net/bluetooth/hci_sock.c:873
 __sock_release+0xd3/0x250 net/socket.c:579
 sock_close+0x1b/0x30 net/socket.c:1141
 __fput+0x3c5/0xb10 fs/file_table.c:278
 ____fput+0x16/0x20 fs/file_table.c:309
 task_work_run+0x1f4/0x2b0 kernel/task_work.c:113
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_usermode_loop+0x32a/0x3b0 arch/x86/entry/common.c:166
 prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
 do_syscall_64+0x696/0x800 arch/x86/entry/common.c:293
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x446419
Code: e8 0c e8 ff ff 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 7b 08 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ff91cfd4da8 EFLAGS: 00000246 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 00000000006dbc28 RCX: 0000000000446419
RDX: 0000000000446419 RSI: 0000000000446419 RDI: 0000000000000004
RBP: 00000000006dbc20 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000006dbc2c
R13: 6368762f7665642f R14: 00007ff91cfd59c0 R15: 00000000006dbd2c

Allocated by task 8889:
 save_stack+0x45/0xd0 mm/kasan/common.c:73
 set_track mm/kasan/common.c:85 [inline]
 kasan_kmalloc mm/kasan/common.c:482 [inline]
 kasan_kmalloc+0xcf/0xe0 mm/kasan/common.c:455
 kmem_cache_alloc_trace+0x151/0x760 mm/slab.c:3607
 kmalloc include/linux/slab.h:545 [inline]
 kzalloc include/linux/slab.h:740 [inline]
 hci_alloc_dev+0x148/0x21a0 net/bluetooth/hci_core.c:3116
 __vhci_create_device+0x101/0x5a0 drivers/bluetooth/hci_vhci.c:114
 vhci_create_device drivers/bluetooth/hci_vhci.c:163 [inline]
 vhci_get_user drivers/bluetooth/hci_vhci.c:219 [inline]
 vhci_write+0x2d0/0x470 drivers/bluetooth/hci_vhci.c:299
 call_write_iter include/linux/fs.h:1862 [inline]
 new_sync_write fs/read_write.c:474 [inline]
 __vfs_write+0x764/0xb40 fs/read_write.c:487
 vfs_write+0x20c/0x580 fs/read_write.c:549
 ksys_write+0x105/0x260 fs/read_write.c:598
 __do_sys_write fs/read_write.c:610 [inline]
 __se_sys_write fs/read_write.c:607 [inline]
 __x64_sys_write+0x73/0xb0 fs/read_write.c:607
 do_syscall_64+0x1a3/0x800 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

Freed by task 8888:
 save_stack+0x45/0xd0 mm/kasan/common.c:73
kobject: 'rfkill320' (00000000e0cb8fff): fill_kobj_path: path = '/devices/virtual/bluetooth/hci4/rfkill320'
 set_track mm/kasan/common.c:85 [inline]
 __kasan_slab_free+0x102/0x150 mm/kasan/common.c:444
 kasan_slab_free+0xe/0x10 mm/kasan/common.c:452
 __cache_free mm/slab.c:3485 [inline]
 kfree+0xcf/0x230 mm/slab.c:3804
 bt_host_release+0x19/0x30 net/bluetooth/hci_sysfs.c:86
 device_release+0x7d/0x210 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.cold+0x28f/0x2ec lib/kobject.c:708
 put_device+0x20/0x30 drivers/base/core.c:2060
 hci_free_dev+0x19/0x20 net/bluetooth/hci_core.c:3208
 vhci_release+0x7e/0xf0 drivers/bluetooth/hci_vhci.c:355
kobject: 'rfkill313' (00000000d3ffb8c5): kobject_uevent_env
 __fput+0x3c5/0xb10 fs/file_table.c:278
 ____fput+0x16/0x20 fs/file_table.c:309
 task_work_run+0x1f4/0x2b0 kernel/task_work.c:113
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_usermode_loop+0x32a/0x3b0 arch/x86/entry/common.c:166
kobject: 'rfkill313' (00000000d3ffb8c5): fill_kobj_path: path = '/devices/virtual/bluetooth/hci2/rfkill313'
 prepare_exit_to_usermode arch/x86/entry/common.c:197 [inline]
 syscall_return_slowpath arch/x86/entry/common.c:268 [inline]
 do_syscall_64+0x696/0x800 arch/x86/entry/common.c:293
 entry_SYSCALL_64_after_hwframe+0x49/0xbe

The buggy address belongs to the object at ffff8880986505c0
 which belongs to the cache kmalloc-8k of size 8192
The buggy address is located 4192 bytes inside of
 8192-byte region [ffff8880986505c0, ffff8880986525c0)
The buggy address belongs to the page:
kobject: 'rfkill313' (00000000d3ffb8c5): kobject_cleanup, parent           (null)
page:ffffea0002619400 count:1 mapcount:0 mapping:ffff88812c3f2080 index:0x0 compound_mapcount: 0
flags: 0x1fffc0000010200(slab|head)
raw: 01fffc0000010200 ffffea0002616508 ffffea0002302f08 ffff88812c3f2080
raw: 0000000000000000 ffff8880986505c0 0000000100000001 0000000000000000
kobject: 'rfkill313' (00000000d3ffb8c5): calling ktype release
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff888098651500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888098651580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
kobject: 'rfkill313': free name
>ffff888098651600: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                               ^
 ffff888098651680: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888098651700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (8):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-selinux-root 2019/01/04 09:26 upstream 645ff1e8e704 7da23925 .config log report syz C
ci-upstream-kasan-gce-selinux-root 2019/01/04 09:07 upstream 645ff1e8e704 7da23925 .config log report
ci-upstream-kasan-gce-smack-root 2019/01/04 00:18 upstream 645ff1e8e704 7da23925 .config log report
ci-upstream-kasan-gce-root 2018/12/19 06:09 upstream ddfbab46539f 4edaba93 .config log report
ci-upstream-kasan-gce-smack-root 2018/11/24 22:50 upstream 7c98a4261827 ecc7c870 .config log report
ci-upstream-kasan-gce-smack-root 2018/11/05 22:11 upstream 651022382c7f 8bd6bd63 .config log report
ci-upstream-kasan-gce-root 2018/11/03 00:58 upstream 8adcc59974b8 8bd6bd63 .config log report
ci-upstream-linux-next-kasan-gce-root 2018/10/23 06:41 linux-next 8c60c36d0b8c ecb386fe .config log report