linux/drivers/md
Guangshuo Li 13da856c86 dm cache policy smq: check allocation under invalidate lock
[ Upstream commit d3f0a606b9 ]

commit 2d1f7b65f5 ("dm cache policy smq: fix missing locks in
invalidating cache blocks") added mq->lock around the destructive part of
smq_invalidate_mapping(), but left the e->allocated check outside the
critical section.

That leaves a check-then-act race. Two concurrent invalidators can both
observe e->allocated as true before either of them takes mq->lock. The
first invalidator that acquires the lock removes the entry from the
queues and hash table and then calls free_entry(), which clears
e->allocated and puts the entry back on the free list. The second
invalidator can then acquire mq->lock and continue with the stale result
of the unlocked check.

This can corrupt the SMQ queues or hash table by deleting an entry that
is no longer on those structures. It can also hit the allocation check in
free_entry() when the same entry is freed again.

Move the allocation check under mq->lock so the predicate and the
destructive operations are serialized by the same lock.

Fixes: 2d1f7b65f5 ("dm cache policy smq: fix missing locks in invalidating cache blocks")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-06-19 13:33:33 +02:00
..
bcache bcache: fix uninitialized closure object 2026-06-01 17:35:26 +02:00
persistent-data dm-thin: fix metadata refcount underflow 2026-06-01 17:35:22 +02:00
dm-bio-prison-v1.c dm bio prison: replace spin_lock_irqsave with spin_lock_irq 2019-11-05 14:53:03 -05:00
dm-bio-prison-v1.h block: switch bios to blk_status_t 2017-06-09 09:27:32 -06:00
dm-bio-prison-v2.c dm bio prison v2: use true/false for bool variable 2020-01-07 12:07:08 -05:00
dm-bio-prison-v2.h dm bio prison v2: new interface for the bio prison 2017-03-07 11:30:16 -05:00
dm-bio-record.h block: store a block_device pointer in struct bio 2021-01-24 18:17:20 -07:00
dm-bufio.c dm bufio: subtract the number of initial sectors in dm_bufio_get_device_size 2021-03-04 14:53:54 -05:00
dm-builtin.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
dm-cache-background-tracker.c dm cache background tracker: fix sparse warning 2018-04-30 15:40:40 -04:00
dm-cache-background-tracker.h dm cache: significant rework to leverage dm-bio-prison-v2 2017-03-07 13:28:31 -05:00
dm-cache-block-types.h linux: drop __bitwise__ everywhere 2016-12-16 00:13:41 +02:00
dm-cache-metadata.c dm cache metadata: fix memory leak on metadata abort retry 2026-06-01 17:35:30 +02:00
dm-cache-metadata.h dm cache: fix dirty mapping checking in passthrough mode switching 2026-06-01 17:35:30 +02:00
dm-cache-policy-internal.h dm cache: significant rework to leverage dm-bio-prison-v2 2017-03-07 13:28:31 -05:00
dm-cache-policy-smq.c dm cache policy smq: check allocation under invalidate lock 2026-06-19 13:33:33 +02:00
dm-cache-policy.c dm cache: add policy name to status output 2014-01-16 13:44:11 -05:00
dm-cache-policy.h dm cache: significant rework to leverage dm-bio-prison-v2 2017-03-07 13:28:31 -05:00
dm-cache-target.c dm cache: fix dirty mapping checking in passthrough mode switching 2026-06-01 17:35:30 +02:00
dm-clone-metadata.c bitmap: introduce generic optimized bitmap_size() 2024-09-04 13:23:16 +02:00
dm-clone-metadata.h dm clone metadata: Fix return type of dm_clone_nr_of_hydrated_regions() 2020-03-27 14:42:51 -04:00
dm-clone-target.c dm clone: call kmem_cache_destroy() in dm_clone_init() error path 2023-05-11 23:00:40 +09:00
dm-core.h dm: limit the number of targets and parameter size area 2024-02-23 08:55:14 +01:00
dm-crypt.c dm-crypt: track tag_offset in convert_context 2025-03-13 12:50:28 +01:00
dm-delay.c dm-delay: fix a race between delay_presuspend and delay_bio 2023-12-03 07:31:25 +01:00
dm-dust.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-ebs-target.c dm-ebs: Mark full buffer dirty even on partial write 2026-01-19 13:10:01 +01:00
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 - Revert a dm-multipath change that caused a regression for unprivledged 2015-11-04 21:19:53 -08:00
dm-exception-store.h - Improve DM snapshot target's scalability by using finer grained 2019-05-16 15:55:48 -07:00
dm-flakey.c dm flakey: fix a crash with invalid table line 2023-05-11 23:00:40 +09:00
dm-ima.c integrity-v5.15 2021-09-02 12:51:41 -07:00
dm-ima.h dm ima: add version info to dm related events in ima log 2021-08-20 15:59:47 -04:00
dm-init.c dm init: ensure device probing has finished in dm-mod.waitfor= 2026-06-01 17:35:30 +02:00
dm-integrity.c dm-integrity: fix a typo in the code for write/discard race 2026-03-04 07:20:28 -05:00
dm-io-tracker.h dm writecache: make writeback pause configurable 2021-06-28 16:30:13 -04:00
dm-io.c block: Add bio_max_segs 2021-02-26 15:49:51 -07:00
dm-ioctl.c dm: fix a buffer overflow in ioctl processing 2026-06-01 17:35:23 +02:00
dm-kcopyd.c dm writecache: have ssd writeback wait if the kcopyd workqueue is busy 2021-06-15 15:42:03 -04:00
dm-linear.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-log-userspace-base.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-log-userspace-transfer.c dm log userspace transfer: match wait_for_completion_timeout return type 2015-04-15 12:10:20 -04:00
dm-log-userspace-transfer.h dm log: userspace add luid to distinguish between concurrent log instances 2009-09-04 20:40:34 +01:00
dm-log-writes.c dm log-writes: Add missing set_freezable() for freezable kthread 2026-01-19 13:09:39 +01:00
dm-log.c dm log: fix out-of-bounds write due to region_count overflow 2026-06-01 17:35:30 +02:00
dm-mpath.c dm mpath: make pg_init_delay_msecs settable 2026-03-04 07:20:32 -05:00
dm-mpath.h dm mpath: remove is_active from struct dm_path 2008-10-10 13:36:58 +01:00
dm-path-selector.c md: Add module.h to all files using it implicitly 2011-10-31 19:31:18 -04:00
dm-path-selector.h dm mpath: pass IO start time to path selector 2020-05-15 10:29:36 -04:00
dm-ps-historical-service-time.c dm-mpath: don't print the "loaded" message if registering fails 2025-08-28 16:24:24 +02:00
dm-ps-io-affinity.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-ps-queue-length.c dm-mpath: don't print the "loaded" message if registering fails 2025-08-28 16:24:24 +02:00
dm-ps-round-robin.c dm-mpath: don't print the "loaded" message if registering fails 2025-08-28 16:24:24 +02:00
dm-ps-service-time.c dm-mpath: don't print the "loaded" message if registering fails 2025-08-28 16:24:24 +02:00
dm-raid.c dm-raid: fix possible NULL dereference with undefined raid type 2026-01-19 13:09:39 +01:00
dm-raid1.c dm mirror: fix integer overflow in create_dirty_log() 2026-06-01 17:35:18 +02:00
dm-region-hash.c - Error path bug fix for overflow tests (Dan) 2018-06-12 18:28:00 -07:00
dm-rq.c dm: clear cloned request bio pointer when last clone bio completes 2026-03-04 07:20:29 -05:00
dm-rq.h dm: remove unused _rq_tio_cache and _rq_cache 2019-03-05 14:48:50 -05:00
dm-snap-persistent.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-snap-transient.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-snap.c dm snapshot: fix lockup in dm_exception_table_exit 2024-04-10 16:18:44 +02:00
dm-stats.c dm stats: check for and propagate alloc_percpu failure 2023-03-30 12:48:00 +02:00
dm-stats.h dm stats: check for and propagate alloc_percpu failure 2023-03-30 12:48:00 +02:00
dm-stripe.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-switch.c dm: update target status functions to support IMA measurement 2021-08-10 13:34:23 -04:00
dm-sysfs.c dm: remove legacy request-based IO path 2018-10-11 11:36:09 -04:00
dm-table.c dm: restrict dm device size to 2^63-512 bytes 2025-06-04 14:37:57 +02:00
dm-target.c dm mpath: fix missing call of path selector type->end_io 2019-04-25 15:38:52 -04:00
dm-thin-metadata.c dm thin metadata: check fail_io before using data_sm 2023-06-21 15:59:14 +02:00
dm-thin-metadata.h dm thin metadata: Add support for a pre-commit callback 2019-12-05 17:05:24 -05:00
dm-thin.c dm thin: make get_first_thin use rcu-safe list first function 2025-01-23 17:15:50 +01:00
dm-uevent.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
dm-uevent.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
dm-unstripe.c dm-unstripe: fix mapping bug when there are multiple targets in a table 2026-03-04 07:20:29 -05:00
dm-verity-fec.c dm-verity-fec: correctly reject too-small hash devices 2026-06-01 17:35:23 +02:00
dm-verity-fec.h dm-verity: disable recursive forward error correction 2026-06-01 17:35:09 +02:00
dm-verity-target.c dm verity: don't perform FEC for failed readahead IO 2023-12-08 08:48:01 +01:00
dm-verity-verify-sig.c dm verity: fix require_signatures module_param permissions 2021-05-25 16:14:05 -04:00
dm-verity-verify-sig.h dm verity: Fix compilation warning 2020-08-04 15:48:13 -04:00
dm-verity.h dm-verity, dm-crypt: align "struct bvec_iter" correctly 2024-03-26 18:21:13 -04:00
dm-writecache.c dm writecache: set a default MAX_WRITEBACK_JOBS 2022-08-17 14:24:23 +02:00
dm-zero.c dm: add support for REQ_NOWAIT to various targets 2020-12-04 18:04:35 -05:00
dm-zone.c dm zone: fix dm_revalidate_zones() memory allocation 2021-06-25 15:25:23 -04:00
dm-zoned-metadata.c dm zoned: check zone capacity 2021-06-04 12:07:28 -04:00
dm-zoned-reclaim.c dm kcopyd: avoid useless atomic operations 2021-06-04 12:07:24 -04:00
dm-zoned-target.c md: dm-zoned-target: Initialize return variable r to avoid uninitialized use 2025-08-28 16:24:24 +02:00
dm-zoned.h dm zoned: select reclaim zone based on device index 2020-06-05 14:59:53 -04:00
dm.c dm: fix NULL pointer dereference in __dm_suspend() 2025-10-19 16:21:51 +02:00
dm.h dm: send just one event on resize, not two 2023-03-10 09:40:05 +01:00
Kconfig md: select BLOCK_LEGACY_AUTOLOAD 2025-03-13 12:51:11 +01:00
Makefile dm ima: measure data on table load 2021-08-10 13:32:40 -04:00
md-autodetect.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
md-bitmap.c md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime 2026-06-01 17:35:11 +02:00
md-bitmap.h md: Avoid namespace collision with bitmap API 2018-08-01 15:49:39 -07:00
md-cluster.c for-5.11/drivers-2020-12-14 2020-12-16 13:09:32 -08:00
md-cluster.h md-cluster: introduce resync_info_get interface for sanity check 2018-10-18 09:36:35 -07:00
md-faulty.c md: mark some personalities as deprecated 2021-06-14 22:32:07 -07:00
md-linear.c md: add error_handlers for raid0 and linear 2023-09-19 12:22:39 +02:00
md-linear.h md/raid1: Replace zero-length array with flexible-array 2020-05-13 12:02:23 -07:00
md-multipath.c md: mark some personalities as deprecated 2021-06-14 22:32:07 -07:00
md-multipath.h md: convert to bioset_init()/mempool_init() 2018-05-30 15:33:32 -06:00
md.c md/md-bitmap: Synchronize bitmap_get_stats() with bitmap lifetime 2026-06-01 17:35:11 +02:00
md.h md: add error_handlers for raid0 and linear 2023-09-19 12:22:39 +02:00
raid0.c md: raid0: account for split bio in iostat accounting 2023-09-19 12:22:40 +02:00
raid0.h md/raid0: add discard support for the 'original' layout 2023-07-23 13:47:51 +02:00
raid1-10.c md: drop queue limitation for RAID1 and RAID10 2023-05-11 23:00:29 +09:00
raid1.c md/raid1: Fix stack memory use after return in raid1_reshape 2025-07-17 18:30:52 +02:00
raid1.h md/raid1: enable io accounting 2021-06-14 22:32:07 -07:00
raid5-cache.c md/raid5: validate payload size before accessing journal metadata 2026-06-01 17:35:17 +02:00
raid5-log.h raid5: set write hint for PPL 2019-03-12 10:15:18 -07:00
raid5-ppl.c block: rename BIO_MAX_PAGES to BIO_MAX_VECS 2021-03-11 07:47:48 -07:00
raid5.c md/raid5: fix soft lockup in retry_aligned_read() 2026-06-01 17:35:17 +02:00
raid5.h md/raid5: let multiple devices of stripe_head share page 2020-09-24 16:44:44 -07:00
raid10.c md/raid10: fix divide-by-zero in setup_geo() with zero far_copies 2026-06-01 17:35:23 +02:00
raid10.h md/raid10: enable io accounting 2021-06-14 22:32:07 -07:00