[Devel] [PATCH RHEL7 COMMIT] ploop: check new size of block device on ioctl(GROW)

Konstantin Khorenko khorenko at odin.com
Mon May 18 21:26:56 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.1
------>
commit 0385f754e9f680c7d5095ae981fe29c1b6e7323a
Author: Andrey Smetanin <asmetanin at virtuozzo.com>
Date:   Tue May 19 08:26:55 2015 +0400

    ploop: check new size of block device on ioctl(GROW)
    
    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)



More information about the Devel mailing list