linux/drivers/md
Mikulas Patocka 1fbeea217d dm raid: fix address sanitizer warning in raid_status
There is this warning when using a kernel with the address sanitizer
and running this testsuite:
https://gitlab.com/cki-project/kernel-tests/-/tree/main/storage/swraid/scsi_raid

==================================================================
BUG: KASAN: slab-out-of-bounds in raid_status+0x1747/0x2820 [dm_raid]
Read of size 4 at addr ffff888079d2c7e8 by task lvcreate/13319
CPU: 0 PID: 13319 Comm: lvcreate Not tainted 5.18.0-0.rc3.<snip> #1
Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
Call Trace:
 <TASK>
 dump_stack_lvl+0x6a/0x9c
 print_address_description.constprop.0+0x1f/0x1e0
 print_report.cold+0x55/0x244
 kasan_report+0xc9/0x100
 raid_status+0x1747/0x2820 [dm_raid]
 dm_ima_measure_on_table_load+0x4b8/0xca0 [dm_mod]
 table_load+0x35c/0x630 [dm_mod]
 ctl_ioctl+0x411/0x630 [dm_mod]
 dm_ctl_ioctl+0xa/0x10 [dm_mod]
 __x64_sys_ioctl+0x12a/0x1a0
 do_syscall_64+0x5b/0x80

The warning is caused by reading conf->max_nr_stripes in raid_status. The
code in raid_status reads mddev->private, casts it to struct r5conf and
reads the entry max_nr_stripes.

However, if we have different raid type than 4/5/6, mddev->private
doesn't point to struct r5conf; it may point to struct r0conf, struct
r1conf, struct r10conf or struct mpconf. If we cast a pointer to one
of these structs to struct r5conf, we will be reading invalid memory
and KASAN warns about it.

Fix this bug by reading struct r5conf only if raid type is 4, 5 or 6.

Cc: stable@vger.kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
2022-07-28 17:29:56 -04:00
..
bcache block: remove blk_cleanup_disk 2022-06-28 06:33:15 -06:00
persistent-data dm space map common: add bounds check to sm_ll_lookup_bitmap() 2022-01-04 13:58:19 -05:00
dm-audit.c
dm-audit.h
dm-bio-prison-v1.c
dm-bio-prison-v1.h
dm-bio-prison-v2.c
dm-bio-prison-v2.h
dm-bio-record.h
dm-bufio.c block: turn bio_kmalloc into a simple kmalloc wrapper 2022-04-17 19:30:41 -06:00
dm-builtin.c
dm-cache-background-tracker.c
dm-cache-background-tracker.h
dm-cache-block-types.h
dm-cache-metadata.c dm cache metadata: remove unnecessary variable in __dump_mapping 2022-05-09 15:40:10 -04:00
dm-cache-metadata.h dm cache: fix typo in 2 comment blocks 2022-07-07 11:49:37 -04:00
dm-cache-policy-internal.h
dm-cache-policy-smq.c dm cache policy smq: make static read-only array table const 2022-02-22 10:35:53 -05:00
dm-cache-policy.c
dm-cache-policy.h
dm-cache-target.c dm cache: fix typo in 2 comment blocks 2022-07-07 11:49:37 -04:00
dm-clone-metadata.c
dm-clone-metadata.h
dm-clone-target.c block: remove QUEUE_FLAG_DISCARD 2022-04-17 19:49:59 -06:00
dm-core.h dm table: audit all dm_table_get_target() callers 2022-07-07 11:49:34 -04:00
dm-crypt.c dm crypt: make printing of the key constant-time 2022-05-09 12:34:03 -04:00
dm-delay.c dm: simplify basic targets 2022-05-05 17:31:35 -04:00
dm-dust.c
dm-ebs-target.c scsi: dm: Remove WRITE_SAME support 2022-02-22 21:11:08 -05:00
dm-era-target.c dm era: commit metadata in postsuspend after worker stops 2022-06-21 13:35:01 -04:00
dm-exception-store.c
dm-exception-store.h
dm-flakey.c dm: simplify basic targets 2022-05-05 17:31:35 -04:00
dm-ima.c dm table: audit all dm_table_get_target() callers 2022-07-07 11:49:34 -04:00
dm-ima.h
dm-init.c
dm-integrity.c dm integrity: fix error code in dm_integrity_ctr() 2022-05-09 12:14:00 -04:00
dm-io-rewind.c dm: add two stage requeue mechanism 2022-07-07 11:49:32 -04:00
dm-io-tracker.h
dm-io.c block: add a bdev_max_discard_sectors helper 2022-04-17 19:49:59 -06:00
dm-ioctl.c dm table: remove dm_table_get_num_targets() wrapper 2022-07-07 11:49:33 -04:00
dm-kcopyd.c dm kcopyd: use __GFP_HIGHMEM when allocating pages 2022-07-14 15:52:31 -04:00
dm-linear.c libnvdimm for 5.19 2022-05-27 15:49:30 -07:00
dm-log-userspace-base.c
dm-log-userspace-transfer.c
dm-log-userspace-transfer.h
dm-log-writes.c libnvdimm for 5.19 2022-05-27 15:49:30 -07:00
dm-log.c dm mirror log: clear log bits up to BITS_PER_LONG boundary 2022-06-23 14:55:43 -04:00
dm-mpath.c dm mpath: provide high-resolution timer to HST for bio-based 2022-05-09 15:39:23 -04:00
dm-mpath.h
dm-path-selector.c
dm-path-selector.h dm mpath: provide high-resolution timer to HST for bio-based 2022-05-09 15:39:23 -04:00
dm-ps-historical-service-time.c dm mpath: provide high-resolution timer to HST for bio-based 2022-05-09 15:39:23 -04:00
dm-ps-io-affinity.c
dm-ps-queue-length.c
dm-ps-round-robin.c
dm-ps-service-time.c
dm-raid.c dm raid: fix address sanitizer warning in raid_status 2022-07-28 17:29:56 -04:00
dm-raid1.c
dm-region-hash.c
dm-rq.c dm: unexport dm_get_reserved_rq_based_ios 2022-06-29 12:46:05 -04:00
dm-rq.h
dm-snap-persistent.c
dm-snap-transient.c
dm-snap.c dm snapshot: fix typo in snapshot_map() comment 2022-07-07 11:49:39 -04:00
dm-stats.c dm stats: add cond_resched when looping over entries 2022-05-09 12:11:07 -04:00
dm-stats.h dm stats: fix too short end duration_ns when using precise_timestamps 2022-02-21 15:35:39 -05:00
dm-stripe.c dax: add .recovery_write dax_operation 2022-05-16 13:37:59 -07:00
dm-switch.c
dm-sysfs.c dm sysfs: use default_groups in kobj_type 2022-01-06 09:48:55 -05:00
dm-table.c dm table: rename dm_target variable in dm_table_add_target() 2022-07-07 11:49:35 -04:00
dm-target.c dax: introduce DAX_RECOVERY_WRITE dax access mode 2022-05-16 13:35:56 -07:00
dm-thin-metadata.c dm thin: fix use-after-free crash in dm_sm_register_threshold_callback 2022-07-15 18:09:14 -04:00
dm-thin-metadata.h dm thin metadata: remove unused dm_thin_remove_block and __remove 2022-02-22 13:55:50 -05:00
dm-thin.c dm thin: fix use-after-free crash in dm_sm_register_threshold_callback 2022-07-15 18:09:14 -04:00
dm-uevent.c
dm-uevent.h
dm-unstripe.c
dm-verity-fec.c
dm-verity-fec.h
dm-verity-target.c dm verity: fix checkpatch close brace error 2022-07-07 11:49:36 -04:00
dm-verity-verify-sig.c
dm-verity-verify-sig.h
dm-verity.h
dm-writecache.c dm writecache: count number of blocks discarded, not number of discard bios 2022-07-14 15:54:46 -04:00
dm-zero.c
dm-zone.c dm table: audit all dm_table_get_target() callers 2022-07-07 11:49:34 -04:00
dm-zoned-metadata.c dm-zoned: remove the ->name field in struct dmz_dev 2022-03-02 12:15:35 -05:00
dm-zoned-reclaim.c
dm-zoned-target.c dm-zoned: don't set the discard_alignment queue limit 2022-05-03 10:38:50 -06:00
dm-zoned.h dm-zoned: remove the ->name field in struct dmz_dev 2022-03-02 12:15:35 -05:00
dm.c dm: Start pr_preempt from the same starting path 2022-07-28 17:29:56 -04:00
dm.h dm table: audit all dm_table_get_target() callers 2022-07-07 11:49:34 -04:00
Kconfig blk-mq: make the blk-mq stacking code optional 2022-02-16 19:39:09 -07:00
Makefile dm: add dm_bio_rewind() API to DM core 2022-07-07 11:26:55 -04:00
md-autodetect.c
md-bitmap.c md: replace deprecated strlcpy & remove duplicated line 2022-04-25 14:00:36 -07:00
md-bitmap.h
md-cluster.c md: replace deprecated strlcpy & remove duplicated line 2022-04-25 14:00:36 -07:00
md-cluster.h
md-faulty.c block: pass a block_device to bio_clone_fast 2022-02-04 07:43:18 -07:00
md-linear.c md: remove most calls to bdevname 2022-05-22 23:07:21 -07:00
md-linear.h
md-multipath.c md: remove most calls to bdevname 2022-05-22 23:07:21 -07:00
md-multipath.h
md.c block: remove blk_cleanup_disk 2022-06-28 06:33:15 -06:00
md.h Revert "md: don't unregister sync_thread with reconfig_mutex held" 2022-06-15 10:30:14 -07:00
raid0.c md: Don't set mddev private to NULL in raid0 pers->free 2022-05-22 23:07:21 -07:00
raid0.h
raid1-10.c md: raid1/raid10: drop pending_cnt 2022-03-08 15:16:54 -08:00
raid1.c md: remove most calls to bdevname 2022-05-22 23:07:21 -07:00
raid1.h md: raid1/raid10: drop pending_cnt 2022-03-08 15:16:54 -08:00
raid5-cache.c md: remove most calls to bdevname 2022-05-22 23:07:21 -07:00
raid5-log.h
raid5-ppl.c md/raid5-ppl: Fix argument order in bio_alloc_bioset() 2022-06-15 10:32:48 -07:00
raid5.c md: remove most calls to bdevname 2022-05-22 23:07:21 -07:00
raid5.h md/raid5: Add __rcu annotation to struct disk_info 2022-04-25 14:00:36 -07:00
raid10.c md: remove most calls to bdevname 2022-05-22 23:07:21 -07:00
raid10.h md: raid1/raid10: drop pending_cnt 2022-03-08 15:16:54 -08:00