[Devel] [PATCH rh7 03/38] ploop: check new size of block device on ioctl(GROW)

Andrey Smetanin asmetanin at virtuozzo.com
Fri May 15 09:48:04 PDT 2015


Return error if userspace attepmts to grow block device above limits
imposed by ploop1 formats.

https://jira.sw.ru/browse/PSBM-21027

Signed-off-by: Maxim Patlasov <MPatlasov at parallels.com>
---
 drivers/block/ploop/fmt_ploop1.c   |  4 ++++
 drivers/block/ploop/ploop1_image.h | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 624bdc1..fb12c30 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -458,6 +458,10 @@ ploop1_prepare_grow(struct ploop_delta * delta, u64 *new_size, int *reloc)
 	if (*new_size & ((1 << delta->cluster_log) - 1))
 		return -EINVAL;
 
+	if (*new_size > ploop1_max_size(1 << delta->plo->cluster_log,
+					delta->plo->fmt_version))
+		return -EFBIG;
+
 	vh = (struct ploop_pvd_header *)page_address(ph->dyn_page);
 	n_present  = le32_to_cpu(vh->m_FirstBlockOffset) >> log;
 	BUG_ON (!n_present);
diff --git a/drivers/block/ploop/ploop1_image.h b/drivers/block/ploop/ploop1_image.h
index 337c05b..c4efe87 100644
--- a/drivers/block/ploop/ploop1_image.h
+++ b/drivers/block/ploop/ploop1_image.h
@@ -247,6 +247,19 @@ ploop1_version(struct ploop_pvd_header *vh)
 	return -1;
 }
 
+static inline __u64
+ploop1_max_size(__u32 blocksize, int version)
+{
+	switch (version) {
+	case PLOOP_FMT_V1:
+		return (__u32)-1;
+	case PLOOP_FMT_V2:
+		return 0xffffffffUL * blocksize;
+	}
+
+	return 0;
+}
+
 #ifdef __KERNEL__
 static inline u64
 get_SizeInSectors_from_le(struct ploop_pvd_header *vh, int version)
-- 
1.9.3




More information about the Devel mailing list