[Devel] [PATCH RHEL9 COMMIT] dm-ploop: Fix off-by-one in init_be_iter()

Konstantin Khorenko khorenko at virtuozzo.com
Tue Dec 7 18:32:07 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.33
------>
commit 7f548d2eaa4709fa6133ec2d75e8aae41ad14d4f
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Tue Dec 7 17:43:04 2021 +0300

    dm-ploop: Fix off-by-one in init_be_iter()
    
    In case of last page completely filled with BAT entries,
    the reminder is 0, so @end becomes -1, while it must be 1024.
    
    https://jira.sw.ru/browse/PSBM-136783
    
    Fixes: 93f9012782e5 ("dm-ploop: Add ploop target driver")
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index fade3e394343..db787729332d 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -464,16 +464,20 @@ static inline bool md_page_cluster_is_in_top_delta(struct ploop *ploop,
 static inline void init_be_iter(u32 nr_be, u32 page_id,
 				u32 *start, u32 *end)
 {
-	u32 last_page = bat_clu_to_page_nr(nr_be - 1);
 	unsigned int count = PAGE_SIZE / sizeof(map_index_t);
+	u32 rem, last_page = bat_clu_to_page_nr(nr_be - 1);
 
 	*start = 0;
 	if (page_id == 0)
 		*start = PLOOP_MAP_OFFSET;
 
 	*end = count - 1;
-	if (page_id == last_page)
-		*end = ((nr_be + PLOOP_MAP_OFFSET) % count) - 1;
+	if (page_id == last_page) {
+		rem = (nr_be + PLOOP_MAP_OFFSET) % count;
+		/* Adjust *end only in case last page is not full. */
+		if (rem)
+			*end = rem - 1;
+	}
 }
 
 static inline void ploop_init_be_iter(struct ploop *ploop, u32 page_id,


More information about the Devel mailing list