]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
dm cache policy smq: check allocation under invalidate lock
authorGuangshuo Li <lgs201920130244@gmail.com>
Fri, 29 May 2026 15:57:45 +0000 (23:57 +0800)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 1 Jun 2026 15:30:24 +0000 (17:30 +0200)
commitd3f0a606b9f278ece8a0df626ded9c4044071235
treec1ddf64c392f2655f9a5d39d266edf044d64518a
parentfb7415f2ab0e3c818254cbf5fb0afda71bef4333
dm cache policy smq: check allocation under invalidate lock

commit 2d1f7b65f5de ("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: 2d1f7b65f5de ("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>
drivers/md/dm-cache-policy-smq.c