syzbot


KASAN: use-after-free Read in disk_part_iter_next (2)

Status: fixed on 2021/11/10 00:50
Reported-by: syzbot+8fede7e30c7cee0de139@syzkaller.appspotmail.com
Fix commit: e82fc7855749 block: don't create too many partitions
First crash: 563d, last: 541d

Cause bisection: introduced by (bisect log) :
commit a33df75c6328bf40078b35f2040d8e54d574c357
Author: Christoph Hellwig <hch@lst.de>
Date: Sun Jan 24 10:02:41 2021 +0000

  block: use an xarray for disk->part_tbl

Crash: KASAN: use-after-free Read in disk_part_iter_next (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 C unreliable 243 563d 651d 21/24 fixed on 2021/03/10 01:49
Patch testing requests:
Created Duration User Patch Repo Result
2021/03/26 08:35 18m tom.leiming@gmail.com https://github.com/ming1/linux.git v5.12-block-test report log
2021/03/24 13:05 12m hch@lst.de git://git.infradead.org/users/hch/block.git 079274f2cf123f9a85972db1043d689c74c0787f report log
2021/03/24 09:49 10m hch@lst.de git://git.infradead.org/users/hch/block.git part-iter-fix report log
2021/03/22 08:51 17m tom.leiming@gmail.com https://github.com/ming1/linux.git v5.12-block-test report log
2021/03/22 07:49 10m dvyukov@google.com patch upstream report log
2021/03/21 21:26 12m bvanassche@acm.org https://github.com/bvanassche/linux a5f35387ebdc report log

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in bdev_nr_sectors include/linux/genhd.h:266 [inline]
BUG: KASAN: use-after-free in disk_part_iter_next+0x49d/0x530 block/genhd.c:206
Read of size 8 at addr ffff88803268d0a8 by task syz-executor193/10255

CPU: 0 PID: 10255 Comm: syz-executor193 Not tainted 5.12.0-rc3-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+0x141/0x1d7 lib/dump_stack.c:120
 print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:232
 __kasan_report mm/kasan/report.c:399 [inline]
 kasan_report.cold+0x7c/0xd8 mm/kasan/report.c:416
 bdev_nr_sectors include/linux/genhd.h:266 [inline]
 disk_part_iter_next+0x49d/0x530 block/genhd.c:206
 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:548
 block_ioctl+0xf9/0x140 fs/block_dev.c:1667
 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/0xae
RIP: 0033:0x445739
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 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 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffca5947308 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000445739
RDX: 0000000020000240 RSI: 0000000000001269 RDI: 0000000000000003
RBP: 00007ffca5947380 R08: 000000000000ece4 R09: 000000000000ece4
R10: 0023706f6f6c2f76 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffca5947370 R14: 00007ffca5947360 R15: 00007ffca594732c

Allocated by task 10192:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:427 [inline]
 __kasan_slab_alloc+0x75/0x90 mm/kasan/common.c:460
 kasan_slab_alloc include/linux/kasan.h:223 [inline]
 slab_post_alloc_hook mm/slab.h:516 [inline]
 slab_alloc_node mm/slub.c:2907 [inline]
 slab_alloc mm/slub.c:2915 [inline]
 kmem_cache_alloc+0x155/0x370 mm/slub.c:2920
 bdev_alloc_inode+0x18/0x80 fs/block_dev.c:795
 alloc_inode+0x61/0x230 fs/inode.c:234
 new_inode_pseudo fs/inode.c:928 [inline]
 new_inode+0x27/0x2f0 fs/inode.c:957
 bdev_alloc+0x20/0x2f0 fs/block_dev.c:885
 add_partition+0x1ab/0x880 block/partitions/core.c:346
 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:548
 block_ioctl+0xf9/0x140 fs/block_dev.c:1667
 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/0xae

Freed by task 0:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_set_track+0x1c/0x30 mm/kasan/common.c:46
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:357
 ____kasan_slab_free mm/kasan/common.c:360 [inline]
 ____kasan_slab_free mm/kasan/common.c:325 [inline]
 __kasan_slab_free+0xf5/0x130 mm/kasan/common.c:367
 kasan_slab_free include/linux/kasan.h:199 [inline]
 slab_free_hook mm/slub.c:1562 [inline]
 slab_free_freelist_hook+0x92/0x210 mm/slub.c:1600
 slab_free mm/slub.c:3161 [inline]
 kmem_cache_free+0x8a/0x740 mm/slub.c:3177
 i_callback+0x3f/0x70 fs/inode.c:223
 rcu_do_batch kernel/rcu/tree.c:2559 [inline]
 rcu_core+0x74a/0x12f0 kernel/rcu/tree.c:2794
 __do_softirq+0x29b/0x9f6 kernel/softirq.c:345

Last potentially related work creation:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_record_aux_stack+0xe5/0x110 mm/kasan/generic.c:345
 __call_rcu kernel/rcu/tree.c:3039 [inline]
 call_rcu+0xb1/0x740 kernel/rcu/tree.c:3114
 destroy_inode+0x129/0x1b0 fs/inode.c:289
 iput_final fs/inode.c:1654 [inline]
 iput.part.0+0x57e/0x810 fs/inode.c:1680
 iput+0x58/0x70 fs/inode.c:1670
 disk_part_iter_exit block/genhd.c:235 [inline]
 disk_part_iter_next+0x9a/0x530 block/genhd.c:202
 blk_drop_partitions+0x10a/0x180 block/partitions/core.c:541
 bdev_disk_changed+0x238/0x430 fs/block_dev.c:1246
 __loop_clr_fd+0x7c7/0xff0 drivers/block/loop.c:1271
 lo_release+0x1ac/0x1f0 drivers/block/loop.c:1923
 __blkdev_put+0x54e/0x800 fs/block_dev.c:1588
 blkdev_put+0x92/0x580 fs/block_dev.c:1641
 blkdev_close+0x8c/0xb0 fs/block_dev.c:1649
 __fput+0x288/0x920 fs/file_table.c:280
 task_work_run+0xdd/0x1a0 kernel/task_work.c:140
 tracehook_notify_resume include/linux/tracehook.h:189 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:174 [inline]
 exit_to_user_mode_prepare+0x249/0x250 kernel/entry/common.c:208
 __syscall_exit_to_user_mode_work kernel/entry/common.c:290 [inline]
 syscall_exit_to_user_mode+0x19/0x60 kernel/entry/common.c:301
 entry_SYSCALL_64_after_hwframe+0x44/0xae

Second to last potentially related work creation:
 kasan_save_stack+0x1b/0x40 mm/kasan/common.c:38
 kasan_record_aux_stack+0xe5/0x110 mm/kasan/generic.c:345
 __call_rcu kernel/rcu/tree.c:3039 [inline]
 call_rcu+0xb1/0x740 kernel/rcu/tree.c:3114
 destroy_inode+0x129/0x1b0 fs/inode.c:289
 iput_final fs/inode.c:1654 [inline]
 iput.part.0+0x57e/0x810 fs/inode.c:1680
 iput+0x58/0x70 fs/inode.c:1670
 disk_part_iter_exit block/genhd.c:235 [inline]
 disk_part_iter_next+0x9a/0x530 block/genhd.c:202
 blk_drop_partitions+0x10a/0x180 block/partitions/core.c:541
 bdev_disk_changed+0x238/0x430 fs/block_dev.c:1246
 __blkdev_get+0x86c/0xa30 fs/block_dev.c:1350
 blkdev_get_by_dev fs/block_dev.c:1454 [inline]
 blkdev_get_by_dev+0x26c/0x600 fs/block_dev.c:1422
 blkdev_reread_part block/ioctl.c:100 [inline]
 blkdev_common_ioctl+0x137e/0x17e0 block/ioctl.c:508
 blkdev_ioctl+0x1ef/0x6d0 block/ioctl.c:577
 block_ioctl+0xf9/0x140 fs/block_dev.c:1667
 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/0xae

The buggy address belongs to the object at ffff88803268d080
 which belongs to the cache bdev_cache of size 2792
The buggy address is located 40 bytes inside of
 2792-byte region [ffff88803268d080, ffff88803268db68)
The buggy address belongs to the page:
page:ffffea0000c9a200 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x32688
head:ffffea0000c9a200 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head)
raw: 00fff00000010200 ffffea0005110a00 0000000200000002 ffff8880109bdb40
raw: 0000000000000000 00000000800b000b 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected

Memory state around the buggy address:
 ffff88803268cf80: fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc fc
 ffff88803268d000: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88803268d080: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                  ^
 ffff88803268d100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff88803268d180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (327):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-root 2021/03/20 20:52 upstream 1c273e10bc0c 17810eae .config log report syz C KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/28 17:11 upstream 0f4498cef9f5 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/28 12:43 upstream 0f4498cef9f5 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/28 01:58 upstream 0f4498cef9f5 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/27 16:13 upstream 0f4498cef9f5 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/27 10:49 upstream 0f4498cef9f5 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/27 09:40 upstream 0f4498cef9f5 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/27 08:06 upstream 0f4498cef9f5 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/27 06:52 upstream db24726bfefa a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/27 03:31 upstream db24726bfefa a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/27 01:37 upstream db24726bfefa a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/26 21:38 upstream db24726bfefa a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/26 18:36 upstream db24726bfefa a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/26 17:29 upstream db24726bfefa a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/26 16:26 upstream db24726bfefa a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/26 13:53 upstream db24726bfefa 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/26 10:57 upstream db24726bfefa 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/26 09:32 upstream db24726bfefa 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-qemu-upstream 2021/03/26 05:40 upstream 002322402daf 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-qemu-upstream 2021/03/26 01:24 upstream 002322402daf 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/25 20:06 upstream e138138003eb 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/25 17:56 upstream e138138003eb 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/25 16:06 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/25 09:59 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/25 09:57 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/25 04:49 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/25 03:36 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/25 00:49 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/24 23:37 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/24 22:04 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-selinux-root 2021/03/24 21:01 upstream 4ee998b0ef8b 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/24 19:05 upstream 7acac4b3196c 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-smack-root 2021/03/24 17:54 upstream 7acac4b3196c 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/24 17:08 upstream 7acac4b3196c 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/24 16:02 upstream 7acac4b3196c 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-qemu-upstream 2021/03/14 05:44 upstream 280d542f6ffa 4a003785 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/04/01 12:22 linux-next 931294922e65 6a81331a .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/31 22:51 linux-next 931294922e65 6a81331a .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/30 03:45 linux-next 931294922e65 6a81331a .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/29 20:13 linux-next 931294922e65 6a81331a .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/29 18:09 linux-next 931294922e65 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/29 17:59 linux-next 931294922e65 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/29 10:57 linux-next 931294922e65 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/29 09:49 linux-next 931294922e65 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/28 19:38 linux-next 931294922e65 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/27 08:39 linux-next 931294922e65 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/26 19:43 linux-next 931294922e65 a8529b82 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/26 12:58 linux-next b4f20b70784a 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/25 23:35 linux-next b4f20b70784a 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/25 21:18 linux-next b4f20b70784a 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/25 19:21 linux-next b4f20b70784a 6a383ecf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/25 02:18 linux-next 20f1b5f9c07c 607e3baf .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-linux-next-kasan-gce-root 2021/03/10 10:57 linux-next 3aa6f5082286 26967e35 .config log report info KASAN: use-after-free Read in disk_part_iter_next
ci-upstream-kasan-gce-root 2021/03/23 18:52 upstream 7acac4b3196c e613994b .config log report info KFENCE: use-after-free in disk_part_iter_next
* Struck through repros no longer work on HEAD.