From: Bryam Vargas via B4 Relay <devnull+hexlabsecurity.proton.me@kernel.org>
To: Zheng Gu <cengku@gmail.com>, Dongsheng Yang <dongsheng.yang@linux.dev>
Cc: dm-devel@lists.linux.dev, Mikulas Patocka <mpatocka@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 08/11] dm-pcache: clamp the tail kset read to the segment data region
Date: Fri, 17 Jul 2026 06:27:01 -0500 [thread overview]
Message-ID: <20260717-b4-disp-4c0a0039-v2-8-19227d6e313c@proton.me> (raw)
In-Reply-To: <20260717-b4-disp-4c0a0039-v2-0-19227d6e313c@proton.me>
From: Bryam Vargas <hexlabsecurity@proton.me>
The tail-kset read in cache_replay(), the writeback worker and the GC
worker bounds its length by PCACHE_SEG_SIZE - seg_off, the raw segment
size rather than the data region. A tail near the segment end reads past
the segment data into the following control area.
Clamp the read to cache_seg_remain(), the data region.
Fixes: 1d57628ff95b ("dm-pcache: add persistent cache target in device-mapper")
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
drivers/md/dm-pcache/cache_gc.c | 2 +-
drivers/md/dm-pcache/cache_key.c | 2 +-
drivers/md/dm-pcache/cache_writeback.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/md/dm-pcache/cache_gc.c b/drivers/md/dm-pcache/cache_gc.c
index c483c7a3afaf..d551848912b4 100644
--- a/drivers/md/dm-pcache/cache_gc.c
+++ b/drivers/md/dm-pcache/cache_gc.c
@@ -37,7 +37,7 @@ static bool need_gc(struct pcache_cache *cache, struct pcache_cache_pos *dirty_t
kset_onmedia = (struct pcache_cache_kset_onmedia *)cache->gc_kset_onmedia_buf;
- to_copy = min(PCACHE_KSET_ONMEDIA_SIZE_MAX, PCACHE_SEG_SIZE - key_tail->seg_off);
+ to_copy = min(PCACHE_KSET_ONMEDIA_SIZE_MAX, cache_seg_remain(key_tail));
ret = copy_mc_to_kernel(kset_onmedia, key_addr, to_copy);
if (ret) {
pcache_dev_err(pcache, "error to read kset: %d", ret);
diff --git a/drivers/md/dm-pcache/cache_key.c b/drivers/md/dm-pcache/cache_key.c
index 86cc9565ffc7..f3ce319037be 100644
--- a/drivers/md/dm-pcache/cache_key.c
+++ b/drivers/md/dm-pcache/cache_key.c
@@ -794,7 +794,7 @@ int cache_replay(struct pcache_cache *cache)
__set_bit(pos->cache_seg->cache_seg_id, cache->seg_map);
while (true) {
- to_copy = min(PCACHE_KSET_ONMEDIA_SIZE_MAX, PCACHE_SEG_SIZE - pos->seg_off);
+ to_copy = min(PCACHE_KSET_ONMEDIA_SIZE_MAX, cache_seg_remain(pos));
ret = copy_mc_to_kernel(kset_onmedia, cache_pos_addr(pos), to_copy);
if (ret) {
ret = -EIO;
diff --git a/drivers/md/dm-pcache/cache_writeback.c b/drivers/md/dm-pcache/cache_writeback.c
index 7a85a9aed18e..c8a4c8110a58 100644
--- a/drivers/md/dm-pcache/cache_writeback.c
+++ b/drivers/md/dm-pcache/cache_writeback.c
@@ -48,7 +48,7 @@ static inline bool is_cache_clean(struct pcache_cache *cache, struct pcache_cach
addr = cache_pos_addr(dirty_tail);
kset_onmedia = (struct pcache_cache_kset_onmedia *)cache->wb_kset_onmedia_buf;
- to_copy = min(PCACHE_KSET_ONMEDIA_SIZE_MAX, PCACHE_SEG_SIZE - dirty_tail->seg_off);
+ to_copy = min(PCACHE_KSET_ONMEDIA_SIZE_MAX, cache_seg_remain(dirty_tail));
ret = copy_mc_to_kernel(kset_onmedia, addr, to_copy);
if (ret) {
pcache_dev_err(pcache, "error to read kset: %d", ret);
--
2.43.0
next prev parent reply other threads:[~2026-07-17 11:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 11:26 [PATCH v2 00/11] dm-pcache: validate on-media metadata against a forged cache image Bryam Vargas via B4 Relay
2026-07-17 11:26 ` [PATCH v2 01/11] dm-pcache: validate seg_id fields from persistent memory Bryam Vargas via B4 Relay
2026-07-17 11:26 ` [PATCH v2 02/11] dm-pcache: validate geometry fields from on-disk cache_info Bryam Vargas via B4 Relay
2026-07-17 11:26 ` [PATCH v2 03/11] dm-pcache: validate kset key_num and intra-segment bounds Bryam Vargas via B4 Relay
2026-07-17 11:26 ` [PATCH v2 04/11] dm-pcache: bound the persisted tail-position offset Bryam Vargas via B4 Relay
2026-07-17 11:26 ` [PATCH v2 05/11] dm-pcache: reject a kset that overruns its segment Bryam Vargas via B4 Relay
2026-07-17 11:26 ` [PATCH v2 06/11] dm-pcache: detect a cycle in the last-kset chain during replay Bryam Vargas via B4 Relay
2026-07-17 11:27 ` [PATCH v2 07/11] dm-pcache: bound the logical key offset from persistent memory Bryam Vargas via B4 Relay
2026-07-17 11:27 ` Bryam Vargas via B4 Relay [this message]
2026-07-17 11:27 ` [PATCH v2 09/11] dm-pcache: validate on-media seg_num against the cache device size Bryam Vargas via B4 Relay
2026-07-17 11:27 ` [PATCH v2 10/11] dm-pcache: validate the persisted dirty_tail chain at load Bryam Vargas via B4 Relay
2026-07-17 11:27 ` [PATCH v2 11/11] dm-pcache: only hand out initialized cache segments Bryam Vargas via B4 Relay
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=20260717-b4-disp-4c0a0039-v2-8-19227d6e313c@proton.me \
--to=devnull+hexlabsecurity.proton.me@kernel.org \
--cc=cengku@gmail.com \
--cc=dm-devel@lists.linux.dev \
--cc=dongsheng.yang@linux.dev \
--cc=hexlabsecurity@proton.me \
--cc=linux-kernel@vger.kernel.org \
--cc=mpatocka@redhat.com \
/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