[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 3/7] qemu-img: avoid overflow of min_sparse parameter
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 3/7] qemu-img: avoid overflow of min_sparse parameter |
Date: |
Mon, 23 Jul 2018 18:45:26 +0200 |
From: Peter Lieven <address@hidden>
the min_sparse convert parameter can overflow (e.g. -S 1024G)
in the conversion from int64_t to int resulting in a negative
min_sparse parameter. Avoid this by limiting the valid parameters
to sane values. In fact anything exceeding the convert buffer size
is also pointless. While at it also forbid values that are non
multiple of 512 to avoid undesired behaviour. For instance, values
between 1 and 511 were legal, but resulted in full allocation.
Cc: address@hidden
Signed-off-by: Peter Lieven <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-img.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 4a7ce43dc9..9b7506b8ae 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2005,6 +2005,8 @@ static int convert_do_copy(ImgConvertState *s)
return s->ret;
}
+#define MAX_BUF_SECTORS 32768
+
static int img_convert(int argc, char **argv)
{
int c, bs_i, flags, src_flags = 0;
@@ -2100,8 +2102,12 @@ static int img_convert(int argc, char **argv)
int64_t sval;
sval = cvtnum(optarg);
- if (sval < 0) {
- error_report("Invalid minimum zero buffer size for sparse
output specified");
+ if (sval < 0 || sval & (BDRV_SECTOR_SIZE - 1) ||
+ sval / BDRV_SECTOR_SIZE > MAX_BUF_SECTORS) {
+ error_report("Invalid buffer size for sparse output specified.
"
+ "Valid sizes are multiples of %llu up to %llu. Select "
+ "0 to disable sparse detection (fully allocates output).",
+ BDRV_SECTOR_SIZE, MAX_BUF_SECTORS * BDRV_SECTOR_SIZE);
goto fail_getopt;
}
@@ -2385,9 +2391,9 @@ static int img_convert(int argc, char **argv)
}
/* increase bufsectors from the default 4096 (2M) if opt_transfer
- * or discard_alignment of the out_bs is greater. Limit to 32768 (16MB)
- * as maximum. */
- s.buf_sectors = MIN(32768,
+ * or discard_alignment of the out_bs is greater. Limit to
+ * MAX_BUF_SECTORS as maximum which is currently 32768 (16MB). */
+ s.buf_sectors = MIN(MAX_BUF_SECTORS,
MAX(s.buf_sectors,
MAX(out_bs->bl.opt_transfer >> BDRV_SECTOR_BITS,
out_bs->bl.pdiscard_alignment >>
--
2.13.6
- [Qemu-devel] [PULL 0/7] Block layer patches, Kevin Wolf, 2018/07/23
- [Qemu-devel] [PULL 2/7] block: Fix typos in comments (found by codespell), Kevin Wolf, 2018/07/23
- [Qemu-devel] [PULL 3/7] qemu-img: avoid overflow of min_sparse parameter,
Kevin Wolf <=
- [Qemu-devel] [PULL 5/7] iotest: Fix filtering order in 226, Kevin Wolf, 2018/07/23
- [Qemu-devel] [PULL 4/7] iotests: remove LUKS support from test 226, Kevin Wolf, 2018/07/23
- [Qemu-devel] [PULL 7/7] block/vvfat: Disable debug message by default, Kevin Wolf, 2018/07/23
- [Qemu-devel] [PULL 6/7] iotests: Disallow compat=0.10 in 223, Kevin Wolf, 2018/07/23
- [Qemu-devel] [PULL 1/7] qemu-iotests: Use host_device instead of file in 149, Kevin Wolf, 2018/07/23
- Re: [Qemu-devel] [PULL 0/7] Block layer patches, Peter Maydell, 2018/07/23