WSL2-Linux-Kernel/drivers/md
Mikulas Patocka 6ffce7a92e dm ioctl: fix misbehavior if list_versions races with module loading
commit 4fe1ec9954 upstream.

__list_versions will first estimate the required space using the
"dm_target_iterate(list_version_get_needed, &needed)" call and then will
fill the space using the "dm_target_iterate(list_version_get_info,
&iter_info)" call. Each of these calls locks the targets using the
"down_read(&_lock)" and "up_read(&_lock)" calls, however between the first
and second "dm_target_iterate" there is no lock held and the target
modules can be loaded at this point, so the second "dm_target_iterate"
call may need more space than what was the first "dm_target_iterate"
returned.

The code tries to handle this overflow (see the beginning of
list_version_get_info), however this handling is incorrect.

The code sets "param->data_size = param->data_start + needed" and
"iter_info.end = (char *)vers+len" - "needed" is the size returned by the
first dm_target_iterate call; "len" is the size of the buffer allocated by
userspace.

"len" may be greater than "needed"; in this case, the code will write up
to "len" bytes into the buffer, however param->data_size is set to
"needed", so it may write data past the param->data_size value. The ioctl
interface copies only up to param->data_size into userspace, thus part of
the result will be truncated.

Fix this bug by setting "iter_info.end = (char *)vers + needed;" - this
guarantees that the second "dm_target_iterate" call will write only up to
the "needed" buffer and it will exit with "DM_BUFFER_FULL_FLAG" if it
overflows the "needed" space - in this case, userspace will allocate a
larger buffer and retry.

Note that there is also a bug in list_version_get_needed - we need to add
"strlen(tt->name) + 1" to the needed size, not "strlen(tt->name)".

Cc: stable@vger.kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-11-26 09:24:46 +01:00
..
bcache bcache: fix set_at_max_writeback_rate() for multiple attached devices 2022-10-26 12:35:48 +02:00
persistent-data
Kconfig
Makefile
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
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.h
dm-cache-policy-internal.h
dm-cache-policy-smq.c
dm-cache-policy.c
dm-cache-policy.h
dm-cache-target.c
dm-clone-metadata.c
dm-clone-metadata.h
dm-clone-target.c
dm-core.h dm: interlock pending dm_io and dm_wait_for_bios_completion 2022-04-08 14:22:57 +02:00
dm-crypt.c dm crypt: make printing of the key constant-time 2022-06-06 08:43:40 +02:00
dm-delay.c
dm-dust.c
dm-ebs-target.c
dm-era-target.c dm era: commit metadata in postsuspend after worker stops 2022-06-29 09:03:20 +02:00
dm-exception-store.c
dm-exception-store.h
dm-flakey.c
dm-ima.c
dm-ima.h
dm-init.c
dm-integrity.c dm integrity: fix error code in dm_integrity_ctr() 2022-06-06 08:43:40 +02:00
dm-io-tracker.h
dm-io.c
dm-ioctl.c dm ioctl: fix misbehavior if list_versions races with module loading 2022-11-26 09:24:46 +01:00
dm-kcopyd.c
dm-linear.c
dm-log-userspace-base.c
dm-log-userspace-transfer.c
dm-log-userspace-transfer.h
dm-log-writes.c
dm-log.c dm mirror log: clear log bits up to BITS_PER_LONG boundary 2022-06-29 09:03:20 +02:00
dm-mpath.c
dm-mpath.h
dm-path-selector.c
dm-path-selector.h
dm-ps-historical-service-time.c dm mpath: only use ktime_get_ns() in historical selector 2022-04-20 09:34:13 +02: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_resume 2022-08-17 14:24:26 +02:00
dm-raid1.c
dm-region-hash.c
dm-rq.c dm: requeue IO if mapping table not yet available 2022-04-13 20:59:06 +02:00
dm-rq.h
dm-snap-persistent.c
dm-snap-transient.c
dm-snap.c
dm-stats.c dm stats: add cond_resched when looping over entries 2022-06-06 08:43:40 +02:00
dm-stats.h dm: fix double accounting of flush with data 2022-04-08 14:22:57 +02:00
dm-stripe.c
dm-switch.c
dm-sysfs.c
dm-table.c
dm-target.c
dm-thin-metadata.c dm thin: fix use-after-free crash in dm_sm_register_threshold_callback 2022-08-17 14:24:23 +02:00
dm-thin-metadata.h
dm-thin.c dm thin: fix use-after-free crash in dm_sm_register_threshold_callback 2022-08-17 14:24:23 +02:00
dm-uevent.c
dm-uevent.h
dm-unstripe.c
dm-verity-fec.c
dm-verity-fec.h
dm-verity-target.c dm verity: set DM_TARGET_IMMUTABLE feature flag 2022-06-06 08:43:40 +02:00
dm-verity-verify-sig.c
dm-verity-verify-sig.h
dm-verity.h
dm-writecache.c dm writecache: set a default MAX_WRITEBACK_JOBS 2022-08-17 14:24:23 +02:00
dm-zero.c
dm-zone.c
dm-zoned-metadata.c
dm-zoned-reclaim.c
dm-zoned-target.c
dm-zoned.h
dm.c dm: remove unnecessary assignment statement in alloc_dev() 2022-10-29 10:12:56 +02:00
dm.h
md-autodetect.c
md-bitmap.c md/bitmap: don't set sb values if can't pass sanity check 2022-06-09 10:22:33 +02:00
md-bitmap.h
md-cluster.c
md-cluster.h
md-faulty.c
md-linear.c
md-linear.h
md-multipath.c
md-multipath.h
md.c md: Flush workqueue md_rdev_misc_wq in md_alloc() 2022-09-15 11:30:01 +02:00
md.h md: Move alloc/free acct bioset in to personality 2022-01-27 11:05:08 +01:00
raid0.c md: Replace snprintf with scnprintf 2022-10-26 12:35:12 +02:00
raid0.h
raid1-10.c
raid1.c
raid1.h
raid5-cache.c
raid5-log.h
raid5-ppl.c
raid5.c md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d 2022-10-26 12:35:49 +02:00
raid5.h
raid10.c md-raid10: fix KASAN warning 2022-08-17 14:22:57 +02:00
raid10.h