In the Linux kernel, the following vulnerability has been resolved:
block: fix uaf for flush rq while iterating tags
blk_mq_clear_flush_rq_mapping() is not called during scsi probe, by
checking blk_queue_init_done(). However, QUEUE_FLAG_INIT_DONE is cleared
in del_gendisk by commit aec89dc5d421 ("block: keep q_usage_counter in
atomic mode after del_gendisk"), hence for disk like scsi, following
blk_mq_destroy_queue() will not clear flush rq from tags->rqs[] as well,
cause following uaf that is found by our syzkaller for v6.6:
==================================================================BUG: KASAN: slab-use-after-free in blk_mq_find_and_get_req+0x16e/0x1a0block/blk-mq-tag.c:261Read of size 4 at addr ffff88811c969c20 by task kworker/1:2H/224909
CPU: 1 PID: 224909 Comm: kworker/1:2H Not tainted 6.6.0-ga836a5060850 #32
Workqueue: kblockd blk_mq_timeout_work
Call Trace:__dump_stacklib/dump_stack.c:88[inline]dump_stack_lvl+0x91/0xf0lib/dump_stack.c:106print_address_description.constprop.0+0x66/0x300mm/kasan/report.c:364print_report+0x3e/0x70mm/kasan/report.c:475kasan_report+0xb8/0xf0mm/kasan/report.c:588blk_mq_find_and_get_req+0x16e/0x1a0block/blk-mq-tag.c:261bt_iterblock/blk-mq-tag.c:288[inline]__sbitmap_for_each_setinclude/linux/sbitmap.h:295[inline]sbitmap_for_each_setinclude/linux/sbitmap.h:316[inline]bt_for_each+0x455/0x790block/blk-mq-tag.c:325blk_mq_queue_tag_busy_iter+0x320/0x740block/blk-mq-tag.c:534blk_mq_timeout_work+0x1a3/0x7b0block/blk-mq.c:1673process_one_work+0x7c4/0x1450kernel/workqueue.c:2631process_scheduled_workskernel/workqueue.c:2704[inline]worker_thread+0x804/0xe40kernel/workqueue.c:2785kthread+0x346/0x450kernel/kthread.c:388ret_from_fork+0x4d/0x80arch/x86/kernel/process.c:147ret_from_fork_asm+0x1b/0x30arch/x86/entry/entry_64.S:293Allocated by task 942:kasan_save_stack+0x22/0x50mm/kasan/common.c:45kasan_set_track+0x25/0x30mm/kasan/common.c:52____kasan_kmallocmm/kasan/common.c:374[inline]__kasan_kmallocmm/kasan/common.c:383[inline]__kasan_kmalloc+0xaa/0xb0mm/kasan/common.c:380kasan_kmallocinclude/linux/kasan.h:198[inline]__do_kmalloc_nodemm/slab_common.c:1007[inline]__kmalloc_node+0x69/0x170mm/slab_common.c:1014kmalloc_nodeinclude/linux/slab.h:620[inline]kzalloc_nodeinclude/linux/slab.h:732[inline]blk_alloc_flush_queue+0x144/0x2f0block/blk-flush.c:499blk_mq_alloc_hctx+0x601/0x940block/blk-mq.c:3788blk_mq_alloc_and_init_hctx+0x27f/0x330block/blk-mq.c:4261blk_mq_realloc_hw_ctxs+0x488/0x5e0block/blk-mq.c:4294blk_mq_init_allocated_queue+0x188/0x860block/blk-mq.c:4350blk_mq_init_queue_datablock/blk-mq.c:4166[inline]blk_mq_init_queue+0x8d/0x100block/blk-mq.c:4176scsi_alloc_sdev+0x843/0xd50drivers/scsi/scsi_scan.c:335scsi_probe_and_add_lun+0x77c/0xde0drivers/scsi/scsi_scan.c:1189__scsi_scan_target+0x1fc/0x5a0drivers/scsi/scsi_scan.c:1727scsi_scan_channeldrivers/scsi/scsi_scan.c:1815[inline]scsi_scan_channel+0x14b/0x1e0drivers/scsi/scsi_scan.c:1791scsi_scan_host_selected+0x2fe/0x400drivers/scsi/scsi_scan.c:1844scsi_scan+0x3a0/0x3f0drivers/scsi/scsi_sysfs.c:151store_scan+0x2a/0x60drivers/scsi/scsi_sysfs.c:191dev_attr_store+0x5c/0x90drivers/base/core.c:2388sysfs_kf_write+0x11c/0x170fs/sysfs/file.c:136kernfs_fop_write_iter+0x3fc/0x610fs/kernfs/file.c:338call_write_iterinclude/linux/fs.h:2083[inline]new_sync_write+0x1b4/0x2d0fs/read_write.c:493vfs_write+0x76c/0xb00fs/read_write.c:586ksys_write+0x127/0x250fs/read_write.c:639do_syscall_x64arch/x86/entry/common.c:51[inline]do_syscall_64+0x70/0x120arch/x86/entry/common.c:81entry_SYSCALL_64_after_hwframe+0x78/0xe2Freed by task 244687:kasan_save_stack+0x22/0x50mm/kasan/common.c:45kasan_set_track+0x25/0x30mm/kasan/common.c:52kasan_save_free_info+0x2b/0x50mm/kasan/generic.c:522____kasan_slab_freemm/kasan/common.c:236[inline]__kasan_slab_free+0x12a/0x1b0mm/kasan/common.c:244kasan_slab_freeinclude/linux/kasan.h:164 [in