syzbot


KASAN: slab-use-after-free Write in sco_chan_del

Status: upstream: reported on 2023/05/15 12:47
Labels: bluetooth (incorrect?)
Reported-by: syzbot+cf54c1da6574b6c1b049@syzkaller.appspotmail.com
First crash: 24d, last: 11d
Discussions (2)
Title Replies (including bot) Last reply
[syzbot] Monthly bluetooth report (May 2023) 0 (1) 2023/05/30 20:52
[syzbot] [bluetooth?] KASAN: slab-use-after-free Write in sco_chan_del 1 (2) 2023/05/15 16:01

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in instrument_atomic_read_write include/linux/instrumented.h:96 [inline]
BUG: KASAN: slab-use-after-free in atomic_dec_and_test include/linux/atomic/atomic-instrumented.h:575 [inline]
BUG: KASAN: slab-use-after-free in hci_conn_drop include/net/bluetooth/hci_core.h:1418 [inline]
BUG: KASAN: slab-use-after-free in sco_chan_del+0x102/0x4f0 net/bluetooth/sco.c:169
Write of size 4 at addr ffff88806c786010 by task syz-executor.0/17873

CPU: 2 PID: 17873 Comm: syz-executor.0 Not tainted 6.4.0-rc3-syzkaller #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-2 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
 print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:351
 print_report mm/kasan/report.c:462 [inline]
 kasan_report+0x11c/0x130 mm/kasan/report.c:572
 check_region_inline mm/kasan/generic.c:181 [inline]
 kasan_check_range+0x141/0x190 mm/kasan/generic.c:187
 instrument_atomic_read_write include/linux/instrumented.h:96 [inline]
 atomic_dec_and_test include/linux/atomic/atomic-instrumented.h:575 [inline]
 hci_conn_drop include/net/bluetooth/hci_core.h:1418 [inline]
 sco_chan_del+0x102/0x4f0 net/bluetooth/sco.c:169
 __sco_sock_close+0x178/0x740 net/bluetooth/sco.c:454
 sco_sock_close net/bluetooth/sco.c:469 [inline]
 sco_sock_release+0x81/0x360 net/bluetooth/sco.c:1267
 __sock_release+0xcd/0x290 net/socket.c:653
 sock_close+0x1c/0x20 net/socket.c:1397
 __fput+0x27c/0xa90 fs/file_table.c:321
 task_work_run+0x16f/0x270 kernel/task_work.c:179
 get_signal+0x1c7/0x25b0 kernel/signal.c:2650
 arch_do_signal_or_restart+0x79/0x5c0 arch/x86/kernel/signal.c:306
 exit_to_user_mode_loop kernel/entry/common.c:168 [inline]
 exit_to_user_mode_prepare+0x11f/0x240 kernel/entry/common.c:204
 __syscall_exit_to_user_mode_work kernel/entry/common.c:286 [inline]
 syscall_exit_to_user_mode+0x1d/0x50 kernel/entry/common.c:297
 do_syscall_64+0x46/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f98c808c169
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 f1 19 00 00 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 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f98c8e03168 EFLAGS: 00000246 ORIG_RAX: 000000000000002a
RAX: fffffffffffffffc RBX: 00007f98c81abf80 RCX: 00007f98c808c169
RDX: 0000000000000008 RSI: 0000000020000040 RDI: 0000000000000004
RBP: 00007f98c80e7ca1 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffc4a3c322f R14: 00007f98c8e03300 R15: 0000000000022000
 </TASK>

Allocated by task 17873:
 kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 ____kasan_kmalloc mm/kasan/common.c:374 [inline]
 ____kasan_kmalloc mm/kasan/common.c:333 [inline]
 __kasan_kmalloc+0xa3/0xb0 mm/kasan/common.c:383
 kmalloc include/linux/slab.h:559 [inline]
 kzalloc include/linux/slab.h:680 [inline]
 hci_conn_add+0xb8/0x16b0 net/bluetooth/hci_conn.c:986
 hci_connect_sco+0x3c7/0x1050 net/bluetooth/hci_conn.c:1663
 sco_connect net/bluetooth/sco.c:264 [inline]
 sco_sock_connect+0x2d7/0xae0 net/bluetooth/sco.c:610
 __sys_connect_file+0x153/0x1a0 net/socket.c:2003
 __sys_connect+0x165/0x1a0 net/socket.c:2020
 __do_sys_connect net/socket.c:2030 [inline]
 __se_sys_connect net/socket.c:2027 [inline]
 __x64_sys_connect+0x73/0xb0 net/socket.c:2027
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 17869:
 kasan_save_stack+0x22/0x40 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:521
 ____kasan_slab_free mm/kasan/common.c:236 [inline]
 ____kasan_slab_free+0x13b/0x1a0 mm/kasan/common.c:200
 kasan_slab_free include/linux/kasan.h:162 [inline]
 __cache_free mm/slab.c:3389 [inline]
 __do_kmem_cache_free mm/slab.c:3576 [inline]
 __kmem_cache_free+0xcd/0x2c0 mm/slab.c:3583
 device_release+0xa3/0x240 drivers/base/core.c:2484
 kobject_cleanup lib/kobject.c:683 [inline]
 kobject_release lib/kobject.c:714 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1c2/0x4d0 lib/kobject.c:731
 put_device+0x1f/0x30 drivers/base/core.c:3733
 hci_conn_del+0x1e5/0x950 net/bluetooth/hci_conn.c:1162
 hci_conn_unlink+0x2ce/0x460 net/bluetooth/hci_conn.c:1109
 hci_conn_unlink+0x362/0x460 net/bluetooth/hci_conn.c:1087
 hci_conn_hash_flush+0x19b/0x270 net/bluetooth/hci_conn.c:2479
 hci_dev_close_sync+0x5fb/0x1200 net/bluetooth/hci_sync.c:4941
 hci_dev_do_close+0x31/0x70 net/bluetooth/hci_core.c:554
 hci_rfkill_set_block+0x161/0x1d0 net/bluetooth/hci_core.c:956
 rfkill_set_block+0x1f9/0x540 net/rfkill/core.c:345
 rfkill_fop_write+0x2c7/0x570 net/rfkill/core.c:1286
 vfs_write+0x2ae/0xd50 fs/read_write.c:582
 ksys_write+0x1ec/0x250 fs/read_write.c:637
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff88806c786000
 which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 16 bytes inside of
 freed 4096-byte region [ffff88806c786000, ffff88806c787000)

The buggy address belongs to the physical page:
page:ffffea0001b1e180 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x6c786
head:ffffea0001b1e180 order:1 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x4fff00000010200(slab|head|node=1|zone=1|lastcpupid=0x7ff)
page_type: 0x1()
raw: 04fff00000010200 ffff888012440900 ffffea000169f190 ffffea0001a64710
raw: 0000000000000000 ffff88806c786000 0000000100000001 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 1, migratetype Unmovable, gfp_mask 0x140cc0(GFP_USER|__GFP_COMP), pid 17873, tgid 17872 (syz-executor.0), ts 504049811151, free_ts 503705670839
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x2db/0x350 mm/page_alloc.c:1731
 prep_new_page mm/page_alloc.c:1738 [inline]
 get_page_from_freelist+0xf41/0x2c00 mm/page_alloc.c:3502
 __alloc_pages+0x1cb/0x4a0 mm/page_alloc.c:4768
 __alloc_pages_node include/linux/gfp.h:237 [inline]
 kmem_getpages mm/slab.c:1360 [inline]
 cache_grow_begin+0x9b/0x3b0 mm/slab.c:2569
 fallback_alloc+0x1e2/0x2d0 mm/slab.c:3112
 __do_cache_alloc mm/slab.c:3216 [inline]
 slab_alloc_node mm/slab.c:3249 [inline]
 __kmem_cache_alloc_node+0x105/0x3f0 mm/slab.c:3540
 kmalloc_trace+0x26/0xe0 mm/slab_common.c:1057
 kmalloc include/linux/slab.h:559 [inline]
 kzalloc include/linux/slab.h:680 [inline]
 hci_conn_add+0xb8/0x16b0 net/bluetooth/hci_conn.c:986
 hci_connect_sco+0x3c7/0x1050 net/bluetooth/hci_conn.c:1663
 sco_connect net/bluetooth/sco.c:264 [inline]
 sco_sock_connect+0x2d7/0xae0 net/bluetooth/sco.c:610
 __sys_connect_file+0x153/0x1a0 net/socket.c:2003
 __sys_connect+0x165/0x1a0 net/socket.c:2020
 __do_sys_connect net/socket.c:2030 [inline]
 __se_sys_connect net/socket.c:2027 [inline]
 __x64_sys_connect+0x73/0xb0 net/socket.c:2027
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1302 [inline]
 free_unref_page_prepare+0x62e/0xcb0 mm/page_alloc.c:2564
 free_unref_page+0x33/0x370 mm/page_alloc.c:2659
 slab_destroy mm/slab.c:1612 [inline]
 slabs_destroy+0x85/0xc0 mm/slab.c:1632
 __cache_free_alien mm/slab.c:773 [inline]
 cache_free_alien mm/slab.c:789 [inline]
 ___cache_free+0x204/0x3d0 mm/slab.c:3416
 qlink_free mm/kasan/quarantine.c:166 [inline]
 qlist_free_all+0x4f/0x1a0 mm/kasan/quarantine.c:185
 kasan_quarantine_reduce+0x195/0x220 mm/kasan/quarantine.c:292
 __kasan_slab_alloc+0x63/0x90 mm/kasan/common.c:305
 kasan_slab_alloc include/linux/kasan.h:186 [inline]
 slab_post_alloc_hook mm/slab.h:711 [inline]
 slab_alloc_node mm/slab.c:3256 [inline]
 slab_alloc mm/slab.c:3265 [inline]
 __kmem_cache_alloc_lru mm/slab.c:3442 [inline]
 kmem_cache_alloc+0x1bd/0x3f0 mm/slab.c:3451
 kmem_cache_zalloc include/linux/slab.h:670 [inline]
 jbd2_alloc_handle include/linux/jbd2.h:1602 [inline]
 new_handle fs/jbd2/transaction.c:476 [inline]
 jbd2__journal_start+0x190/0x850 fs/jbd2/transaction.c:503
 __ext4_journal_start_sb+0x411/0x5d0 fs/ext4/ext4_jbd2.c:111
 __ext4_journal_start fs/ext4/ext4_jbd2.h:326 [inline]
 ext4_dirty_inode+0xa5/0x130 fs/ext4/inode.c:5921
 __mark_inode_dirty+0x1e0/0xd60 fs/fs-writeback.c:2424
 mark_inode_dirty include/linux/fs.h:2144 [inline]
 generic_write_end+0x354/0x440 fs/buffer.c:2257
 ext4_da_write_end+0x19b/0xad0 fs/ext4/inode.c:3012
 generic_perform_write+0x316/0x570 mm/filemap.c:3934
 ext4_buffered_write_iter+0x15b/0x460 fs/ext4/file.c:289

Memory state around the buggy address:
 ffff88806c785f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff88806c785f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88806c786000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                         ^
 ffff88806c786080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88806c786100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets Manager Title
2023/05/22 09:45 upstream 44c026a73be8 4bce1a3e .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream KASAN: slab-use-after-free Write in sco_chan_del
2023/05/09 01:31 net-next ed23734c23d2 f4168103 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-net-kasan-gce KASAN: slab-use-after-free Write in sco_chan_del
* Struck through repros no longer work on HEAD.