syzbot


KASAN: use-after-free Read in disk_part_iter_next

Status: fixed on 2021/03/10 01:49
Reported-by: syzbot+825f0f9657d4e528046e@syzkaller.appspotmail.com
Fix commit: aebf5db91705 block: fix use-after-free in disk_part_iter_next
First crash: 729d, last: 637d

Cause bisection: introduced by (bisect log) [merge commit]:
commit 57cde551225bb09fa40ca3938e06d59fc529ff90
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Mon Nov 9 09:35:13 2020 +0000

  Merge 5.10-rc3 into usb-next

Crash: BUG: sleeping function called from invalid context in sta_info_move_state (log)
Repro: C syz .config
similar bugs (1):
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KASAN: use-after-free Read in disk_part_iter_next (2) C done 327 614d 632d 22/24 fixed on 2021/11/10 00:50

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in bdev_nr_sectors include/linux/genhd.h:264 [inline]
BUG: KASAN: use-after-free in disk_part_iter_next+0x4c7/0x560 block/genhd.c:204
Read of size 8 at addr ffff88814080b9a8 by task syz-executor825/9848

CPU: 1 PID: 9848 Comm: syz-executor825 Not tainted 5.10.0-rc6-next-20201207-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:79 [inline]
 dump_stack+0x107/0x163 lib/dump_stack.c:120
 print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:230
 __kasan_report mm/kasan/report.c:396 [inline]
 kasan_report.cold+0x79/0xd5 mm/kasan/report.c:413
 bdev_nr_sectors include/linux/genhd.h:264 [inline]
 disk_part_iter_next+0x4c7/0x560 block/genhd.c:204
 partition_overlaps+0x96/0x200 block/partitions/core.c:425
 bdev_add_partition+0x66/0x130 block/partitions/core.c:444
 blkpg_do_ioctl+0x2d0/0x340 block/ioctl.c:43
 blkpg_ioctl block/ioctl.c:60 [inline]
 blkdev_ioctl+0x577/0x6d0 block/ioctl.c:541
 block_ioctl+0xf9/0x140 fs/block_dev.c:1649
 vfs_ioctl fs/ioctl.c:48 [inline]
 __do_sys_ioctl fs/ioctl.c:753 [inline]
 __se_sys_ioctl fs/ioctl.c:739 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:739
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x447ff9
Code: dd ca 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 ab ca fb ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007fff3c27c398 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000447ff9
RDX: 0000000020000240 RSI: 0000000000001269 RDI: 0000000000000003
RBP: 00000000000148cc R08: 0000000200000000 R09: 0000000200000000
R10: 0000000000000004 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000404fc0 R14: 0000000000000000 R15: 0000000000000000

Allocated by task 9811:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:39
 kasan_set_track mm/kasan/common.c:47 [inline]
 set_alloc_info mm/kasan/common.c:405 [inline]
 ____kasan_kmalloc mm/kasan/common.c:436 [inline]
 ____kasan_kmalloc.constprop.0+0xa0/0xd0 mm/kasan/common.c:408
 kasan_slab_alloc include/linux/kasan.h:205 [inline]
 slab_post_alloc_hook mm/slab.h:518 [inline]
 slab_alloc_node mm/slub.c:2903 [inline]
 slab_alloc mm/slub.c:2911 [inline]
 kmem_cache_alloc+0x155/0x380 mm/slub.c:2916
 bdev_alloc_inode+0x18/0x40 fs/block_dev.c:777
 alloc_inode+0x61/0x230 fs/inode.c:233
 new_inode_pseudo fs/inode.c:927 [inline]
 new_inode+0x27/0x2f0 fs/inode.c:956
 bdev_alloc+0x20/0x340 fs/block_dev.c:864
 add_partition+0x1ad/0x8e0 block/partitions/core.c:345
 bdev_add_partition+0xb6/0x130 block/partitions/core.c:449
 blkpg_do_ioctl+0x2d0/0x340 block/ioctl.c:43
 blkpg_ioctl block/ioctl.c:60 [inline]
 blkdev_ioctl+0x577/0x6d0 block/ioctl.c:541
 block_ioctl+0xf9/0x140 fs/block_dev.c:1649
 vfs_ioctl fs/ioctl.c:48 [inline]
 __do_sys_ioctl fs/ioctl.c:753 [inline]
 __se_sys_ioctl fs/ioctl.c:739 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:739
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 17:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:39
 kasan_set_track+0x1c/0x30 mm/kasan/common.c:47
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:355
 ____kasan_slab_free.part.0+0xe1/0x110 mm/kasan/common.c:366
 kasan_slab_free include/linux/kasan.h:188 [inline]
 slab_free_hook mm/slub.c:1548 [inline]
 slab_free_freelist_hook+0x82/0x1d0 mm/slub.c:1586
 slab_free mm/slub.c:3157 [inline]
 kmem_cache_free+0x82/0x360 mm/slub.c:3173
 i_callback+0x3f/0x70 fs/inode.c:222
 rcu_do_batch kernel/rcu/tree.c:2502 [inline]
 rcu_core+0x735/0x1020 kernel/rcu/tree.c:2737
 __do_softirq+0x2b7/0xa76 kernel/softirq.c:343

Last potentially related work creation:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:39
 kasan_record_aux_stack+0xdc/0x100 mm/kasan/generic.c:343
 __call_rcu kernel/rcu/tree.c:2987 [inline]
 call_rcu+0xbb/0x810 kernel/rcu/tree.c:3062
 destroy_inode+0x129/0x1b0 fs/inode.c:288
 iput_final fs/inode.c:1651 [inline]
 iput.part.0+0x41e/0x840 fs/inode.c:1677
 iput+0x58/0x70 fs/inode.c:1667
 disk_part_iter_exit block/genhd.c:232 [inline]
 disk_part_iter_next+0x9a/0x560 block/genhd.c:200
 blk_drop_partitions+0x10a/0x180 block/partitions/core.c:541
 bdev_disk_changed+0x238/0x430 fs/block_dev.c:1228
 loop_reread_partitions+0x29/0x50 drivers/block/loop.c:655
 loop_set_status+0x735/0x1040 drivers/block/loop.c:1416
 loop_set_status64 drivers/block/loop.c:1536 [inline]
 lo_ioctl+0x900/0x1720 drivers/block/loop.c:1704
 blkdev_ioctl+0x2a1/0x6d0 block/ioctl.c:576
 block_ioctl+0xf9/0x140 fs/block_dev.c:1649
 vfs_ioctl fs/ioctl.c:48 [inline]
 __do_sys_ioctl fs/ioctl.c:753 [inline]
 __se_sys_ioctl fs/ioctl.c:739 [inline]
 __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:739
 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Second to last potentially related work creation:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:39
 kasan_record_aux_stack+0xdc/0x100 mm/kasan/generic.c:343
 __call_rcu kernel/rcu/tree.c:2987 [inline]
 call_rcu+0xbb/0x810 kernel/rcu/tree.c:3062
 destroy_inode+0x129/0x1b0 fs/inode.c:288
 iput_final fs/inode.c:1651 [inline]
 iput.part.0+0x41e/0x840 fs/inode.c:1677
 iput+0x58/0x70 fs/inode.c:1667
 disk_release+0x191/0x240 block/genhd.c:1212
 device_release+0x9f/0x240 drivers/base/core.c:1804
 kobject_cleanup lib/kobject.c:705 [inline]
 kobject_release lib/kobject.c:736 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1c8/0x540 lib/kobject.c:753
 put_device+0x1b/0x30 drivers/base/core.c:3033
 put_disk+0x44/0x60 block/genhd.c:1414
 do_floppy_init drivers/block/floppy.c:4826 [inline]
 floppy_async_init+0x2004/0x2033 drivers/block/floppy.c:4834
 async_run_entry_fn+0xf3/0x730 kernel/async.c:123
 process_one_work+0x98d/0x1630 kernel/workqueue.c:2275
 worker_thread+0x64c/0x1120 kernel/workqueue.c:2421
 kthread+0x3b1/0x4a0 kernel/kthread.c:292
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296

The buggy address belongs to the object at ffff88814080b980
 which belongs to the cache bdev_cache of size 2808
The buggy address is located 40 bytes inside of
 2808-byte region [ffff88814080b980, ffff88814080c478)
The buggy address belongs to the page:
page:0000000095b89171 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x140808
head:0000000095b89171 order:3 compound_mapcount:0 compound_pincount:0
flags: 0x57ff00000010200(slab|head)
raw: 057ff00000010200 0000000000000000 0000000100000001 ffff8880109c0b40
raw: 0000000000000000 00000000800b000b 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff88814080b880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fc
 ffff88814080b900: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88814080b980: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                  ^
 ffff88814080ba00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88814080ba80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (243):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-linux-next-kasan-gce-root 2020/12/08 11:18 linux-next 15ac8fdb7440 51a9082e .config log report syz C
ci-upstream-kasan-gce-root 2021/03/10 01:15 upstream 144c79ef3353 26967e35 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/10 00:13 upstream 144c79ef3353 26967e35 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/09 19:58 upstream 144c79ef3353 26967e35 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-qemu-upstream 2021/03/09 18:39 upstream 280d542f6ffa 26967e35 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-qemu-upstream 2021/03/09 17:33 upstream 280d542f6ffa 26967e35 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/09 02:56 upstream 144c79ef3353 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/09 01:33 upstream 144c79ef3353 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/09 00:27 upstream 144c79ef3353 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/08 23:15 upstream 144c79ef3353 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/08 22:13 upstream 144c79ef3353 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/08 18:56 upstream 144c79ef3353 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/08 16:40 upstream 144c79ef3353 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-qemu-upstream 2021/03/08 01:04 upstream 280d542f6ffa 09fbf400 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/07 22:40 upstream a38fd8748464 75506d9c .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/07 10:38 upstream a38fd8748464 e4b4d570 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/07 09:35 upstream a38fd8748464 e4b4d570 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/07 02:04 upstream a38fd8748464 e4b4d570 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/06 20:50 upstream a38fd8748464 e4b4d570 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/06 17:43 upstream a38fd8748464 e4b4d570 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-qemu-upstream 2021/03/06 15:18 upstream 280d542f6ffa e4b4d570 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/06 10:19 upstream 280d542f6ffa 56722561 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/06 06:55 upstream 280d542f6ffa 56722561 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/06 02:54 upstream 280d542f6ffa 56722561 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/06 00:40 upstream 280d542f6ffa 56722561 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/05 18:09 upstream 280d542f6ffa 9d751681 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/05 16:10 upstream 280d542f6ffa 9d751681 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/05 14:43 upstream 280d542f6ffa 9d751681 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/05 11:47 upstream 280d542f6ffa 9d751681 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/04 23:42 upstream cee407c5cc42 9d751681 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/04 21:59 upstream cee407c5cc42 9d751681 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/04 10:43 upstream f69d02e37a85 d7e4e604 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/04 10:21 upstream f69d02e37a85 d7e4e604 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/04 08:29 upstream f69d02e37a85 d7e4e604 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/03 20:01 upstream f69d02e37a85 06ed56cd .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/03 18:54 upstream f69d02e37a85 06ed56cd .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/03 16:22 upstream f69d02e37a85 06ed56cd .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/03 12:33 upstream f69d02e37a85 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/03 08:27 upstream 7a7fd0de4a98 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/03 06:42 upstream 7a7fd0de4a98 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/03 05:00 upstream 7a7fd0de4a98 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/03 01:42 upstream 7a7fd0de4a98 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/03 00:40 upstream 7a7fd0de4a98 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/02 23:33 upstream 7a7fd0de4a98 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/02 17:26 upstream 7a7fd0de4a98 92ead296 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/02 14:35 upstream 7a7fd0de4a98 92ead296 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/06 21:34 linux-next 4641b32307b3 e4b4d570 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/03 11:31 linux-next f6b975aabf15 e5b64d68 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/02 18:52 linux-next 92f791ebd25b 92ead296 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2020/12/08 09:34 linux-next 15ac8fdb7440 51a9082e .config log report info
ci-upstream-linux-next-kasan-gce-root 2020/12/07 20:59 linux-next 15ac8fdb7440 1190297f .config log report info
* Struck through repros no longer work on HEAD.