[Devel] [PATCH RH8 09/10] ploop: Add sanity check of passed BAT from disk
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Jun 30 19:46:57 MSK 2021
Check, nobody refer to BAT-related clusters.
In scope of: https://jira.sw.ru/browse/PSBM-131202
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
drivers/md/dm-ploop-bat.c | 13 +++++++++----
drivers/md/dm-ploop.h | 2 +-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 1ae863043f50..b07dc87cf3e9 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -339,15 +339,20 @@ static int ploop_delta_check_header(struct ploop *ploop,
return ret;
}
-int convert_bat_entries(u32 *bat_entries, u32 count)
+int convert_bat_entries(struct ploop *ploop, u32 *bat_entries, u32 nr_be)
{
- int i;
+ u32 i, bytes, bat_clusters;
- for (i = 0; i < count; i++) {
+ bytes = (PLOOP_MAP_OFFSET + nr_be) * sizeof(map_index_t);
+ bat_clusters = DIV_ROUND_UP(bytes, CLU_SIZE(ploop));
+
+ for (i = 0; i < nr_be; i++) {
if (bat_entries[i] == BAT_ENTRY_NONE)
return -EPROTO;
if (!bat_entries[i])
bat_entries[i] = BAT_ENTRY_NONE;
+ if (bat_entries[i] < bat_clusters)
+ return -EXDEV;
}
return 0;
@@ -387,7 +392,7 @@ int ploop_read_delta_metadata(struct ploop *ploop, struct file *file,
goto out_vfree;
delta_bat_entries = *d_hdr + PLOOP_MAP_OFFSET * sizeof(map_index_t);
- ret = convert_bat_entries(delta_bat_entries, delta_nr_be);
+ ret = convert_bat_entries(ploop, delta_bat_entries, delta_nr_be);
*delta_nr_be_ret = delta_nr_be;
out_vfree:
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index d26f269e475c..5bc3cb7c78b6 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -529,7 +529,7 @@ extern void ploop_free_md_page(struct md_page *md);
extern void free_md_pages_tree(struct rb_root *root);
extern bool try_update_bat_entry(struct ploop *ploop, u32 clu,
u8 level, u32 dst_clu);
-extern int convert_bat_entries(u32 *bat_entries, u32 count);
+extern int convert_bat_entries(struct ploop *ploop, u32 *bat_entries, u32 count);
extern int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_raw);
extern void dispatch_pios(struct ploop *ploop, struct pio *pio, struct list_head *pio_list);
More information about the Devel
mailing list