From: Wentao Liang <vulab@iscas.ac.cn>
To: cengku@gmail.com
Cc: dm-devel@lists.linux.dev, dongsheng.yang@linux.dev,
linux-kernel@vger.kernel.org, mpatocka@redhat.com,
Wentao Liang <vulab@iscas.ac.cn>,
stable@vger.kernel.org
Subject: [PATCH] dm-pcache: Fix use-after-free in kset_replay()
Date: Thu, 17 Sep 2026 09:41:33 +0000 [thread overview]
Message-ID: <20260917094133.2145340-1-vulab@iscas.ac.cn> (raw)
When the generation of the segment referenced by a replayed key is
stale, kset_replay() releases the key with cache_key_put(). The caller
holds the only reference, so the key is freed, yet the function then
dereferences key->cache_pos to pin the segment.
Pin the segment before the key can be released.
Fixes: 1d57628ff95b ("dm-pcache: add persistent cache target in device-mapper")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/md/dm-pcache/cache_key.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-pcache/cache_key.c b/drivers/md/dm-pcache/cache_key.c
index e068e878231b..668c16a2e111 100644
--- a/drivers/md/dm-pcache/cache_key.c
+++ b/drivers/md/dm-pcache/cache_key.c
@@ -730,6 +730,12 @@ static int kset_replay(struct pcache_cache *cache, struct pcache_cache_kset_onme
__set_bit(key->cache_pos.cache_seg->cache_seg_id, cache->seg_map);
+ /*
+ * Pin the segment while the key is still alive: the stale key
+ * below is released and freed by cache_key_put().
+ */
+ cache_seg_get(key->cache_pos.cache_seg);
+
/* Check if the segment generation is valid for insertion. */
if (key->seg_gen < key->cache_pos.cache_seg->gen) {
cache_key_put(key);
@@ -739,8 +745,6 @@ static int kset_replay(struct pcache_cache *cache, struct pcache_cache_kset_onme
cache_key_insert(&cache->req_key_tree, key, true);
spin_unlock(&cache_subtree->tree_lock);
}
-
- cache_seg_get(key->cache_pos.cache_seg);
}
return 0;
--
2.34.1
next reply other threads:[~2026-09-17 9:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 9:41 Wentao Liang [this message]
2026-09-21 12:34 ` Mikulas Patocka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260917094133.2145340-1-vulab@iscas.ac.cn \
--to=vulab@iscas.ac.cn \
--cc=cengku@gmail.com \
--cc=dm-devel@lists.linux.dev \
--cc=dongsheng.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®