From: Dongsheng Yang <dongsheng.yang@linux.dev>
To: Li Chen <me@linux.beauty>, Kees Cook <kees@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nicolas.schier@linux.dev>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
linux-kbuild@vger.kernel.org, Zheng Gu <cengku@gmail.com>,
dm-devel@lists.linux.dev
Subject: Re: [PATCH 3/3] dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest()
Date: Mon, 10 Nov 2025 19:18:38 +0800 [thread overview]
Message-ID: <bd04f307-7f83-41f5-a1ad-afcd8d2a9237@linux.dev> (raw)
In-Reply-To: <20251105084733.3598704-4-me@linux.beauty>
Hi Li,
It seems you sent the same patch again, shoud it be V2 instead?
Thanx
在 11/5/2025 4:46 PM, Li Chen 写道:
> From: Li Chen <chenl311@chinatelecom.cn>
>
> Before this change pcache_meta_find_latest() was copying each
> slot directly into meta_ret while scanning. If no valid slot
> was found and the function returned NULL, meta_ret still held
> whatever was last copied (possibly CRC-bad). Later users
> (e.g. cache_segs_init) could mistakenly trust that data.
>
> Allocate a temporary buffer instead and only populate meta_ret after a
> valid/latest header is found. If no valid header exists we return NULL
> without touching meta_ret.
>
> Also add __free(kvfree) so the temporary buffer is always freed, and
> include the needed headers.
>
> Signed-off-by: Li Chen <chenl311@chinatelecom.cn>
> ---
> drivers/md/dm-pcache/pcache_internal.h | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/md/dm-pcache/pcache_internal.h b/drivers/md/dm-pcache/pcache_internal.h
> index b7a3319d2bd3e..ac28f9dd2986f 100644
> --- a/drivers/md/dm-pcache/pcache_internal.h
> +++ b/drivers/md/dm-pcache/pcache_internal.h
> @@ -4,6 +4,8 @@
>
> #include <linux/delay.h>
> #include <linux/crc32c.h>
> +#include <linux/slab.h>
> +#include <linux/cleanup.h>
>
> #define pcache_err(fmt, ...) \
> pr_err("dm-pcache: %s:%u " fmt, __func__, __LINE__, ##__VA_ARGS__)
> @@ -79,14 +81,17 @@ static inline void __must_check *pcache_meta_find_latest(struct pcache_meta_head
> u32 meta_size, u32 meta_max_size,
> void *meta_ret)
> {
> - struct pcache_meta_header *meta, *latest = NULL;
> + struct pcache_meta_header *latest = NULL;
> + struct pcache_meta_header *meta __free(kvfree);
> u32 i, seq_latest = 0;
> - void *meta_addr;
>
> - meta = meta_ret;
> + meta = kvzalloc(meta_size, GFP_KERNEL);
> + if (!meta)
> + return ERR_PTR(-ENOMEM);
>
> for (i = 0; i < PCACHE_META_INDEX_MAX; i++) {
> - meta_addr = (void *)header + (i * meta_max_size);
> + void *meta_addr = (void *)header + (i * meta_max_size);
> +
> if (copy_mc_to_kernel(meta, meta_addr, meta_size)) {
> pcache_err("hardware memory error when copy meta");
> return ERR_PTR(-EIO);
next prev parent reply other threads:[~2025-11-10 11:19 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 8:46 [PATCH 0/3] dm-pcache: built-in support and metadata hardening Li Chen
2025-11-05 8:46 ` [PATCH 1/3] dm-pcache: allow built-in build and rename flush helper Li Chen
2025-11-05 8:46 ` [PATCH 2/3] dm-pcache: reuse meta_addr in pcache_meta_find_latest Li Chen
2025-11-05 8:46 ` [PATCH 3/3] dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest() Li Chen
2025-11-10 11:18 ` Dongsheng Yang [this message]
2025-11-10 12:32 ` Li Chen
2025-11-05 8:46 ` [RFC PATCH 0/2] Add cleanup_plugin for detecting problematic cleanup patterns Li Chen
2025-11-05 9:04 ` Li Chen
2025-11-05 9:49 ` Peter Zijlstra
2025-11-05 14:52 ` Li Chen
2025-11-05 8:46 ` [RFC PATCH 1/2] gcc-plugins: add cleanup_plugin for uninitialized cleanup detection Li Chen
2025-11-07 7:39 ` kernel test robot
2025-11-05 8:46 ` [RFC PATCH 2/2] gcc-plugins: cleanup_plugin: detect NULL init Li Chen
2025-11-05 12:41 ` [PATCH 0/3] dm-pcache: built-in support and metadata hardening Li Chen
-- strict thread matches above, loose matches on Subject: below --
2025-10-30 12:33 Li Chen
2025-10-30 12:33 ` [PATCH 3/3] dm-pcache: avoid leaking invalid metadata in pcache_meta_find_latest() Li Chen
[not found] ` <CADSj-VoQerDc2UUfBOknRMGetSddMEqRKaC3VDniD+xCq0pH1g@mail.gmail.com>
2025-11-01 13:10 ` Li Chen
2025-11-04 6:46 ` Dongsheng Yang
2025-11-04 13:36 ` Li Chen
2025-11-05 1:16 ` Dongsheng Yang
2025-11-03 11:38 ` Jonathan Cameron
2025-11-04 12:19 ` Li Chen
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=bd04f307-7f83-41f5-a1ad-afcd8d2a9237@linux.dev \
--to=dongsheng.yang@linux.dev \
--cc=cengku@gmail.com \
--cc=dm-devel@lists.linux.dev \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@linux.beauty \
--cc=nathan@kernel.org \
--cc=nicolas.schier@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.