From: Mikulas Patocka <mpatocka@redhat.com>
To: Wentao Liang <vulab@iscas.ac.cn>
Cc: cengku@gmail.com, dm-devel@lists.linux.dev,
dongsheng.yang@linux.dev, linux-kernel@vger.kernel.org,
Jianyun Gao <jianyungao89@gmail.com>
Subject: Re: [PATCH] dm-pcache: Fix use-after-free in kset_replay()
Date: Mon, 21 Sep 2026 14:34:34 +0200 (CEST) [thread overview]
Message-ID: <ab890e71-8075-76f8-a91b-0beb78a0d3b7@redhat.com> (raw)
In-Reply-To: <20260917094133.2145340-1-vulab@iscas.ac.cn>
Hi
This patch conflicts with the patch
c2e894eac398b258f12fdec73ed6ba081047f7b3 (which also fixes the
use-after-free condition).
Please, download the current kernel 7.3-rc4 and test if the bug is still
present there. If it is, send a patch against 7.3-rc4.
Mikulas
On Thu, 17 Sep 2026, Wentao Liang wrote:
> 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
>
prev parent reply other threads:[~2026-09-21 12:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 9:41 Wentao Liang
2026-09-21 12:34 ` Mikulas Patocka [this message]
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=ab890e71-8075-76f8-a91b-0beb78a0d3b7@redhat.com \
--to=mpatocka@redhat.com \
--cc=cengku@gmail.com \
--cc=dm-devel@lists.linux.dev \
--cc=dongsheng.yang@linux.dev \
--cc=jianyungao89@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=vulab@iscas.ac.cn \
/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®