FAILED: patch "[PATCH] dm-pcache: validate seg_id fields from persistent memory" failed to apply to 6.18-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 90c990a68460d7b5720e5634cf650eccdf0f4098
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090437-wok-unstable-1b2e@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 90c990a68460d7b5720e5634cf650eccdf0f4098 Mon Sep 17 00:00:00 2001
From: Bryam Vargas <[email protected]>
Date: Fri, 17 Jul 2026 06:26:54 -0500
Subject: [PATCH] dm-pcache: validate seg_id fields from persistent memory
cache_pos_decode(), cache_key_decode() and the last-kset branches of cache_replay(), the writeback worker and the GC worker take a cache segment id from the cache device metadata and index cache->segments[] with it without checking it against cache->n_segs. That metadata is only CRC-protected with a fixed public seed, so whoever supplies the cache device on a table load (CAP_SYS_ADMIN) controls the id; an out-of-range value forms a wild pcache_cache_segment pointer that is dereferenced and written through -- an out-of-bounds read and write driven by on-disk data.
Add cache_seg_id_valid() and reject an out-of-range id at each decode site, failing the operation with -EIO instead of indexing past the array. Bound the id against the initialized-segment count (cache_info.n_segs) rather than the physical device total. A forged cache_info.n_segs below seg_num otherwise leaves segments[cache_info.n_segs..seg_num) as zeroed structs whose data pointer is NULL, so a forged id in that window would still be dereferenced. A later patch guarantees cache_info.n_segs <= seg_num, and a driver-created cache sets the two equal, so valid images are unaffected.
drivers/md/dm-pcache/cache.c +4 -0
@@ -118,6 +118,9 @@ int cache_pos_decode(struct pcache_cache *cache,if (!latest_addr)return -EIO ; +if (!cache_seg_id_valid (cache, latest.cache_seg_id)) +return -EIO ; + pos->cache_seg = &cache->segments[latest.cache_seg_id]; pos->seg_off = latest.seg_off; *seq = latest.header.seq;
@@ -155,6 +158,7 @@ static int cache_init(struct dm_pcache *pcache) cache->cache_dev = &pcache->cache_dev; cache->n_segs = cache_dev->seg_num;atomic_set (&cache->gc_errors,0 ); +atomic_set (&cache->writeback_errors,0 );spin_lock_init (&cache->seg_map_lock);spin_lock_init (&cache->key_head_lock);
drivers/md/dm-pcache/cache.h +15 -0
@@ -180,6 +180,7 @@ struct pcache_cache {u32 advance;int ret; } writeback_ctx; +atomic_t writeback_errors;char gc_kset_onmedia_buf[PCACHE_KSET_ONMEDIA_SIZE_MAX ];struct delayed_work gc_work;
@@ -420,6 +421,20 @@ static inline bool cache_seg_is_ctrl_seg(u32 cache_seg_id)return (cache_seg_id ==0 ); } +/** +* cache_seg_id_valid - Validate a cache segment id read from the cache device. +* @cache: Pointer to the pcache_cache structure. +* @cache_seg_id: Segment id decoded from on-media metadata. +* +* On-media segment ids are only protected by a CRC, which an attacker who can +* format the cache device computes over their chosen value. Reject any id that +* would index cache->segments[] out of bounds before it is dereferenced. +*/ +static inline bool cache_seg_id_valid (struct pcache_cache *cache,u32 cache_seg_id) +{ +return cache_seg_id < cache->cache_info.n_segs; +} +/** * cache_key_cutfront - Cuts a specified length from the front of a cache key. * @key: Pointer to pcache_cache_key structure.
drivers/md/dm-pcache/cache_gc.c +14 -2
@@ -74,11 +74,17 @@ static bool need_gc(struct pcache_cache *cache, struct pcache_cache_pos *dirty_t* @cache: Pointer to the pcache_cache structure. * @kset_onmedia: Pointer to the kset_onmedia structure for the last kset. */ -static void last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) +static int last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *cur_seg, *next_seg; +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in gc (n_segs %u)\n" , + kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } + cur_seg = cache->key_tail.cache_seg; next_seg = &cache->segments[kset_onmedia->next_cache_seg_id];
@@ -94,6 +100,8 @@ static void last_kset_gc(struct pcache_cache *cache, struct pcache_cache_kset_onspin_lock (&cache->seg_map_lock);__clear_bit (cur_seg->cache_seg_id, cache->seg_map);spin_unlock (&cache->seg_map_lock); + +return 0 ; }void pcache_cache_gc_fn (struct work_struct *work)
@@ -130,7 +138,11 @@ void pcache_cache_gc_fn(struct work_struct *work)if (dirty_tail.cache_seg == key_tail.cache_seg)break ; -last_kset_gc (cache, kset_onmedia); + ret =last_kset_gc (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->gc_errors); +return ; + }continue ; }
drivers/md/dm-pcache/cache_key.c +11 -0
@@ -94,6 +94,12 @@ int cache_key_decode(struct pcache_cache *cache, key->off = key_onmedia->off; key->len = key_onmedia->len; +if (!cache_seg_id_valid (cache, key_onmedia->cache_seg_id)) { +pcache_dev_err (pcache,"invalid cache_seg_id %u in cache key (n_segs %u)\n" , + key_onmedia->cache_seg_id, cache->n_segs); +return -EIO ; + } + key->cache_pos.cache_seg = &cache->segments[key_onmedia->cache_seg_id]; key->cache_pos.seg_off = key_onmedia->cache_seg_off;
@@ -789,6 +795,11 @@ int cache_replay(struct pcache_cache *cache)pcache_dev_debug (pcache,"last kset replay, next: %u\n" , kset_onmedia->next_cache_seg_id); +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { + ret = -EIO ; + goto out; + } + next_seg = &cache->segments[kset_onmedia->next_cache_seg_id]; pos->cache_seg = next_seg;
drivers/md/dm-pcache/cache_writeback.c +19 -4
@@ -196,12 +196,18 @@ static int cache_kset_insert_tree(struct pcache_cache *cache, struct pcache_cachreturn ret; } -static void last_kset_writeback (struct pcache_cache *cache, +static int last_kset_writeback (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *last_kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *next_seg; +if (!cache_seg_id_valid (cache, last_kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in writeback (n_segs %u)\n" , + last_kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } +pcache_dev_debug (pcache,"last kset, next: %u\n" , last_kset_onmedia->next_cache_seg_id); next_seg = &cache->segments[last_kset_onmedia->next_cache_seg_id];
@@ -211,6 +217,8 @@ static void last_kset_writeback(struct pcache_cache *cache, cache->dirty_tail.seg_off =0 ;cache_encode_dirty_tail (cache);mutex_unlock (&cache->dirty_tail_lock); + +return 0 ; }void cache_writeback_fn (struct work_struct *work)
@@ -229,6 +237,9 @@ void cache_writeback_fn(struct work_struct *work)if (pcache_is_stopping (pcache)) goto unlock; +if (atomic_read (&cache->writeback_errors)) + goto unlock; + kset_onmedia = (struct pcache_cache_kset_onmedia *)cache->wb_kset_onmedia_buf;mutex_lock (&cache->dirty_tail_lock);
@@ -241,15 +252,19 @@ void cache_writeback_fn(struct work_struct *work) }if (kset_onmedia->flags &PCACHE_KSET_FLAGS_LAST ) { -last_kset_writeback (cache, kset_onmedia); + ret =last_kset_writeback (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->writeback_errors); + goto unlock; + } delay =0 ; goto queue_work; } ret =cache_kset_insert_tree (cache, kset_onmedia);if (ret) { - delay =PCACHE_CACHE_WRITEBACK_INTERVAL ; - goto queue_work; +atomic_inc (&cache->writeback_errors); + goto unlock; }cache_wb_tree_writeback (cache,get_kset_onmedia_size (kset_onmedia));
Sasha Levin
maintainerPATCH 1/1 dm-pcache: validate seg_id fields from persistent memory
From: Bryam Vargas <[email protected]>
[ Upstream commit 90c990a68460d7b5720e5634cf650eccdf0f4098 ]
cache_pos_decode(), cache_key_decode() and the last-kset branches of cache_replay(), the writeback worker and the GC worker take a cache segment id from the cache device metadata and index cache->segments[] with it without checking it against cache->n_segs. That metadata is only CRC-protected with a fixed public seed, so whoever supplies the cache device on a table load (CAP_SYS_ADMIN) controls the id; an out-of-range value forms a wild pcache_cache_segment pointer that is dereferenced and written through -- an out-of-bounds read and write driven by on-disk data.
Add cache_seg_id_valid() and reject an out-of-range id at each decode site, failing the operation with -EIO instead of indexing past the array. Bound the id against the initialized-segment count (cache_info.n_segs) rather than the physical device total. A forged cache_info.n_segs below seg_num otherwise leaves segments[cache_info.n_segs..seg_num) as zeroed structs whose data pointer is NULL, so a forged id in that window would still be dereferenced. A later patch guarantees cache_info.n_segs <= seg_num, and a driver-created cache sets the two equal, so valid images are unaffected.
--- drivers/md/dm-pcache/cache.c | 4 ++++ drivers/md/dm-pcache/cache.h | 15 +++++++++++++++ drivers/md/dm-pcache/cache_gc.c | 16 ++++++++++++++-- drivers/md/dm-pcache/cache_key.c | 11 +++++++++++ drivers/md/dm-pcache/cache_writeback.c | 23 +++++++++++++++++++---- 5 files changed, 63 insertions(+), 6 deletions(-)
drivers/md/dm-pcache/cache.c +4 -0
@@ -118,6 +118,9 @@ int cache_pos_decode(struct pcache_cache *cache,if (!latest_addr)return -EIO ; +if (!cache_seg_id_valid (cache, latest.cache_seg_id)) +return -EIO ; + pos->cache_seg = &cache->segments[latest.cache_seg_id];if (latest.seg_off >= pos->cache_seg->segment.data_size)
@@ -158,6 +161,7 @@ static int cache_init(struct dm_pcache *pcache) cache->cache_dev = &pcache->cache_dev; cache->n_segs = cache_dev->seg_num;atomic_set (&cache->gc_errors,0 ); +atomic_set (&cache->writeback_errors,0 );spin_lock_init (&cache->seg_map_lock);spin_lock_init (&cache->key_head_lock);
drivers/md/dm-pcache/cache.h +15 -0
@@ -180,6 +180,7 @@ struct pcache_cache {u32 advance;int ret; } writeback_ctx; +atomic_t writeback_errors;char gc_kset_onmedia_buf[PCACHE_KSET_ONMEDIA_SIZE_MAX ];struct delayed_work gc_work;
@@ -420,6 +421,20 @@ static inline bool cache_seg_is_ctrl_seg(u32 cache_seg_id)return (cache_seg_id ==0 ); } +/** +* cache_seg_id_valid - Validate a cache segment id read from the cache device. +* @cache: Pointer to the pcache_cache structure. +* @cache_seg_id: Segment id decoded from on-media metadata. +* +* On-media segment ids are only protected by a CRC, which an attacker who can +* format the cache device computes over their chosen value. Reject any id that +* would index cache->segments[] out of bounds before it is dereferenced. +*/ +static inline bool cache_seg_id_valid (struct pcache_cache *cache,u32 cache_seg_id) +{ +return cache_seg_id < cache->cache_info.n_segs; +} +/** * cache_key_cutfront - Cuts a specified length from the front of a cache key. * @key: Pointer to pcache_cache_key structure.
drivers/md/dm-pcache/cache_gc.c +14 -2
@@ -74,11 +74,17 @@ static bool need_gc(struct pcache_cache *cache, struct pcache_cache_pos *dirty_t* @cache: Pointer to the pcache_cache structure. * @kset_onmedia: Pointer to the kset_onmedia structure for the last kset. */ -static void last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) +static int last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *cur_seg, *next_seg; +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in gc (n_segs %u)\n" , + kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } + cur_seg = cache->key_tail.cache_seg; next_seg = &cache->segments[kset_onmedia->next_cache_seg_id];
@@ -94,6 +100,8 @@ static void last_kset_gc(struct pcache_cache *cache, struct pcache_cache_kset_onspin_lock (&cache->seg_map_lock);__clear_bit (cur_seg->cache_seg_id, cache->seg_map);spin_unlock (&cache->seg_map_lock); + +return 0 ; }void pcache_cache_gc_fn (struct work_struct *work)
@@ -130,7 +138,11 @@ void pcache_cache_gc_fn(struct work_struct *work)if (dirty_tail.cache_seg == key_tail.cache_seg)break ; -last_kset_gc (cache, kset_onmedia); + ret =last_kset_gc (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->gc_errors); +return ; + }continue ; }
drivers/md/dm-pcache/cache_key.c +11 -0
@@ -94,6 +94,12 @@ int cache_key_decode(struct pcache_cache *cache, key->off = key_onmedia->off; key->len = key_onmedia->len; +if (!cache_seg_id_valid (cache, key_onmedia->cache_seg_id)) { +pcache_dev_err (pcache,"invalid cache_seg_id %u in cache key (n_segs %u)\n" , + key_onmedia->cache_seg_id, cache->n_segs); +return -EIO ; + } + key->cache_pos.cache_seg = &cache->segments[key_onmedia->cache_seg_id]; key->cache_pos.seg_off = key_onmedia->cache_seg_off;
@@ -801,6 +807,11 @@ int cache_replay(struct pcache_cache *cache) goto out; } +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { + ret = -EIO ; + goto out; + } + next_seg = &cache->segments[kset_onmedia->next_cache_seg_id]; pos->cache_seg = next_seg;
drivers/md/dm-pcache/cache_writeback.c +19 -4
@@ -196,12 +196,18 @@ static int cache_kset_insert_tree(struct pcache_cache *cache, struct pcache_cachreturn ret; } -static void last_kset_writeback (struct pcache_cache *cache, +static int last_kset_writeback (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *last_kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *next_seg; +if (!cache_seg_id_valid (cache, last_kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in writeback (n_segs %u)\n" , + last_kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } +pcache_dev_debug (pcache,"last kset, next: %u\n" , last_kset_onmedia->next_cache_seg_id); next_seg = &cache->segments[last_kset_onmedia->next_cache_seg_id];
@@ -211,6 +217,8 @@ static void last_kset_writeback(struct pcache_cache *cache, cache->dirty_tail.seg_off =0 ;cache_encode_dirty_tail (cache);mutex_unlock (&cache->dirty_tail_lock); + +return 0 ; }void cache_writeback_fn (struct work_struct *work)
@@ -229,6 +237,9 @@ void cache_writeback_fn(struct work_struct *work)if (pcache_is_stopping (pcache)) goto unlock; +if (atomic_read (&cache->writeback_errors)) + goto unlock; + kset_onmedia = (struct pcache_cache_kset_onmedia *)cache->wb_kset_onmedia_buf;mutex_lock (&cache->dirty_tail_lock);
@@ -241,15 +252,19 @@ void cache_writeback_fn(struct work_struct *work) }if (kset_onmedia->flags &PCACHE_KSET_FLAGS_LAST ) { -last_kset_writeback (cache, kset_onmedia); + ret =last_kset_writeback (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->writeback_errors); + goto unlock; + } delay =0 ; goto queue_work; } ret =cache_kset_insert_tree (cache, kset_onmedia);if (ret) { - delay =PCACHE_CACHE_WRITEBACK_INTERVAL ; - goto queue_work; +atomic_inc (&cache->writeback_errors); + goto unlock; }cache_wb_tree_writeback (cache,get_kset_onmedia_size (kset_onmedia));
Signature · 1 line
2.53.0
Re: [PATCH 6.18.y] dm-pcache: validate seg_id fields from persistent memory
Quoted 236 lines · Sasha Levin
From: Bryam Vargas <[email protected]>
[ Upstream commit
90c990a68460d7b5720e5634cf650eccdf0f4098]
cache_pos_decode(),cache_key_decode()and the last-kset branches ofcache_replay(), the writeback worker and the GC worker take a cache segment id from the cache device metadata and index cache->segments[] with it without checking it againstcache->n_segs. That metadata is only CRC-protected with a fixed public seed, so whoever supplies the cache device on a table load (CAP_SYS_ADMIN) controls the id; an out-of-range value forms a wildpcache_cache_segmentpointer that is dereferenced and written through -- an out-of-bounds read and write driven by on-disk data.Add
cache_seg_id_valid()and reject an out-of-range id at each decode site, failing the operation with-EIOinstead of indexing past the array. Bound the id against the initialized-segment count (cache_info.n_segs) rather than the physical device total. A forged cache_info.n_segs belowseg_numotherwise leaves segments[cache_info.n_segs..seg_num) as zeroed structs whose data pointer is NULL, so a forged id in that window would still be dereferenced. A later patch guarantees cache_info.n_segs <=seg_num, and a driver-created cache sets the two equal, so valid images are unaffected.Fixes 1d57628ff95b ("dm-pcache: add persistent cache target in device-mapper")Signed-off-by Bryam Vargas <[email protected]>Signed-off-by Mikulas Patocka <[email protected]>[ adjusted cache_replay() context to preserve the existing hop-limit check before segment-ID validation ]Signed-off-by Sasha Levin <[email protected]>--- drivers/md/dm-pcache/cache.c | 4 ++++ drivers/md/dm-pcache/cache.h | 15 +++++++++++++++ drivers/md/dm-pcache/cache_gc.c | 16 ++++++++++++++-- drivers/md/dm-pcache/cache_key.c | 11 +++++++++++ drivers/md/dm-pcache/cache_writeback.c | 23 +++++++++++++++++++---- 5 files changed, 63 insertions(+), 6 deletions(-)drivers/md/dm-pcache/cache.c +4
-0@@ -118,6 +118,9 @@ int cache_pos_decode(struct pcache_cache *cache,if (!latest_addr)return -EIO ; +if (!cache_seg_id_valid (cache, latest.cache_seg_id)) +return -EIO ; + pos->cache_seg = &cache->segments[latest.cache_seg_id];if (latest.seg_off >= pos->cache_seg->segment.data_size)@@ -158,6 +161,7 @@ static int cache_init(struct dm_pcache *pcache) cache->cache_dev = &pcache->cache_dev; cache->n_segs = cache_dev->seg_num;atomic_set (&cache->gc_errors,0 ); +atomic_set (&cache->writeback_errors,0 );spin_lock_init (&cache->seg_map_lock);spin_lock_init (&cache->key_head_lock);drivers/md/dm-pcache/cache.h +15
-0@@ -180,6 +180,7 @@ struct pcache_cache {u32 advance;int ret; } writeback_ctx; +atomic_t writeback_errors;char gc_kset_onmedia_buf[PCACHE_KSET_ONMEDIA_SIZE_MAX ];struct delayed_work gc_work;@@ -420,6 +421,20 @@ static inline bool cache_seg_is_ctrl_seg(u32 cache_seg_id)return (cache_seg_id ==0 ); } +/** +* cache_seg_id_valid - Validate a cache segment id read from the cache device. +* @cache: Pointer to the pcache_cache structure. +* @cache_seg_id: Segment id decoded from on-media metadata. +* +* On-media segment ids are only protected by a CRC, which an attacker who can +* format the cache device computes over their chosen value. Reject any id that +* would index cache->segments[] out of bounds before it is dereferenced. +*/ +static inline bool cache_seg_id_valid (struct pcache_cache *cache,u32 cache_seg_id) +{ +return cache_seg_id < cache->cache_info.n_segs; +} +/** * cache_key_cutfront - Cuts a specified length from the front of a cache key. * @key: Pointer to pcache_cache_key structure. drivers/md/dm-pcache/cache_gc.c +14
-2@@ -74,11 +74,17 @@ static bool need_gc(struct pcache_cache *cache, struct pcache_cache_pos *dirty_t* @cache: Pointer to the pcache_cache structure. * @kset_onmedia: Pointer to the kset_onmedia structure for the last kset. */ -static void last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) +static int last_kset_gc (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *cur_seg, *next_seg; +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in gc (n_segs %u)\n" , + kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } + cur_seg = cache->key_tail.cache_seg; next_seg = &cache->segments[kset_onmedia->next_cache_seg_id];@@ -94,6 +100,8 @@ static void last_kset_gc(struct pcache_cache *cache, struct pcache_cache_kset_onspin_lock (&cache->seg_map_lock);__clear_bit (cur_seg->cache_seg_id, cache->seg_map);spin_unlock (&cache->seg_map_lock); + +return 0 ; }void pcache_cache_gc_fn (struct work_struct *work)@@ -130,7 +138,11 @@ void pcache_cache_gc_fn(struct work_struct *work)if (dirty_tail.cache_seg == key_tail.cache_seg)break ; -last_kset_gc (cache, kset_onmedia); + ret =last_kset_gc (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->gc_errors); +return ; + }continue ; }drivers/md/dm-pcache/cache_key.c +11
-0@@ -94,6 +94,12 @@ int cache_key_decode(struct pcache_cache *cache, key->off = key_onmedia->off; key->len = key_onmedia->len; +if (!cache_seg_id_valid (cache, key_onmedia->cache_seg_id)) { +pcache_dev_err (pcache,"invalid cache_seg_id %u in cache key (n_segs %u)\n" , + key_onmedia->cache_seg_id, cache->n_segs); +return -EIO ; + } + key->cache_pos.cache_seg = &cache->segments[key_onmedia->cache_seg_id]; key->cache_pos.seg_off = key_onmedia->cache_seg_off;@@ -801,6 +807,11 @@ int cache_replay(struct pcache_cache *cache) goto out; } +if (!cache_seg_id_valid (cache, kset_onmedia->next_cache_seg_id)) { + ret = -EIO ; + goto out; + } + next_seg = &cache->segments[kset_onmedia->next_cache_seg_id]; pos->cache_seg = next_seg;drivers/md/dm-pcache/cache_writeback.c +19
-4@@ -196,12 +196,18 @@ static int cache_kset_insert_tree(struct pcache_cache *cache, struct pcache_cachreturn ret; } -static void last_kset_writeback (struct pcache_cache *cache, +static int last_kset_writeback (struct pcache_cache *cache,struct pcache_cache_kset_onmedia *last_kset_onmedia) {struct dm_pcache *pcache =CACHE_TO_PCACHE (cache);struct pcache_cache_segment *next_seg; +if (!cache_seg_id_valid (cache, last_kset_onmedia->next_cache_seg_id)) { +pcache_dev_err (pcache,"invalid next_cache_seg_id %u in writeback (n_segs %u)\n" , + last_kset_onmedia->next_cache_seg_id, cache->n_segs); +return -EIO ; + } +pcache_dev_debug (pcache,"last kset, next: %u\n" , last_kset_onmedia->next_cache_seg_id); next_seg = &cache->segments[last_kset_onmedia->next_cache_seg_id];@@ -211,6 +217,8 @@ static void last_kset_writeback(struct pcache_cache *cache, cache->dirty_tail.seg_off =0 ;cache_encode_dirty_tail (cache);mutex_unlock (&cache->dirty_tail_lock); + +return 0 ; }void cache_writeback_fn (struct work_struct *work)@@ -229,6 +237,9 @@ void cache_writeback_fn(struct work_struct *work)if (pcache_is_stopping (pcache)) goto unlock; +if (atomic_read (&cache->writeback_errors)) + goto unlock; + kset_onmedia = (struct pcache_cache_kset_onmedia *)cache->wb_kset_onmedia_buf;mutex_lock (&cache->dirty_tail_lock);@@ -241,15 +252,19 @@ void cache_writeback_fn(struct work_struct *work) }if (kset_onmedia->flags &PCACHE_KSET_FLAGS_LAST ) { -last_kset_writeback (cache, kset_onmedia); + ret =last_kset_writeback (cache, kset_onmedia); +if (ret) { +atomic_inc (&cache->writeback_errors); + goto unlock; + } delay =0 ; goto queue_work; } ret =cache_kset_insert_tree (cache, kset_onmedia);if (ret) { - delay =PCACHE_CACHE_WRITEBACK_INTERVAL ; - goto queue_work; +atomic_inc (&cache->writeback_errors); + goto unlock; }cache_wb_tree_writeback (cache,get_kset_onmedia_size (kset_onmedia));Signature · 1 line
2.53.0
Did not apply :(