All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 16/17] blockdev: Error out on negative throttling option values
Date: Wed, 20 Jan 2016 17:25:05 +0100	[thread overview]
Message-ID: <1453307106-28330-17-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1453307106-28330-1-git-send-email-kwolf@redhat.com>

From: Fam Zheng <famz@redhat.com>

extract_common_blockdev_options() uses qemu_opt_get_number() to parse
the bps/iops numbers to uint64_t, then converts to double and stores in
ThrottleConfig.  The actual parsing is done by strtoull() in
parse_option_number().  Negative numbers are wrapped to large positive
ones, and stored.

We used to reject negative numbers since 7d81c1413c9, but this regressed
when the option parsing code was changed later. Now fix this again.

This time, define an arbitrary large upper limit (1e15),  and check the
values so both negative and impractically big numbers are caught and
reported.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 blockdev.c              |  3 ++-
 include/qemu/throttle.h |  2 ++
 util/throttle.c         | 16 ++++++----------
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 1392fff..07cfe25 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -348,7 +348,8 @@ static bool check_throttle_config(ThrottleConfig *cfg, Error **errp)
     }
 
     if (!throttle_is_valid(cfg)) {
-        error_setg(errp, "bps/iops/maxs values must be 0 or greater");
+        error_setg(errp, "bps/iops/max values must be within [0, %lld]",
+                   THROTTLE_VALUE_MAX);
         return false;
     }
 
diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h
index 12faaad..d0c98ed 100644
--- a/include/qemu/throttle.h
+++ b/include/qemu/throttle.h
@@ -29,6 +29,8 @@
 #include "qemu-common.h"
 #include "qemu/timer.h"
 
+#define THROTTLE_VALUE_MAX 1000000000000000LL
+
 typedef enum {
     THROTTLE_BPS_TOTAL,
     THROTTLE_BPS_READ,
diff --git a/util/throttle.c b/util/throttle.c
index 1113671..af4bc95 100644
--- a/util/throttle.c
+++ b/util/throttle.c
@@ -282,22 +282,18 @@ bool throttle_conflicting(ThrottleConfig *cfg)
  */
 bool throttle_is_valid(ThrottleConfig *cfg)
 {
-    bool invalid = false;
     int i;
 
     for (i = 0; i < BUCKETS_COUNT; i++) {
-        if (cfg->buckets[i].avg < 0) {
-            invalid = true;
+        if (cfg->buckets[i].avg < 0 ||
+            cfg->buckets[i].max < 0 ||
+            cfg->buckets[i].avg > THROTTLE_VALUE_MAX ||
+            cfg->buckets[i].max > THROTTLE_VALUE_MAX) {
+            return false;
         }
     }
 
-    for (i = 0; i < BUCKETS_COUNT; i++) {
-        if (cfg->buckets[i].max < 0) {
-            invalid = true;
-        }
-    }
-
-    return !invalid;
+    return true;
 }
 
 /* check if bps_max/iops_max is used without bps/iops
-- 
1.8.3.1

  parent reply	other threads:[~2016-01-20 16:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-20 16:24 [Qemu-devel] [PULL 00/17] Block patches Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 01/17] block: Fix .bdrv_open flags Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 02/17] block/raw-posix: avoid bogus fixup for cylinders on DASD disks Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 03/17] qemu-img: Speed up comparing empty/zero images Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 04/17] qemu-iotests: Reduce racy output in 028 Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 05/17] block: Clean up includes Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 06/17] qcow2: Write feature table only for v3 images Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 07/17] qcow2: Write full header on image creation Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 08/17] block: Assert no write requests under BDRV_O_INCOMING Kevin Wolf
2016-02-18 16:03   ` Laurent Vivier
2016-02-19  9:17     ` Kevin Wolf
2016-02-19 10:37       ` Laurent Vivier
2016-02-19 13:47         ` Kevin Wolf
2016-02-19 14:11           ` Paolo Bonzini
2016-02-19 14:17             ` Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 09/17] block: Fix error path in bdrv_invalidate_cache() Kevin Wolf
2016-01-20 16:24 ` [Qemu-devel] [PULL 10/17] block: Rename BDRV_O_INCOMING to BDRV_O_INACTIVE Kevin Wolf
2016-01-20 16:25 ` [Qemu-devel] [PULL 11/17] block: Inactivate BDS when migration completes Kevin Wolf
2016-01-20 16:25 ` [Qemu-devel] [PULL 12/17] qcow2: Implement .bdrv_inactivate Kevin Wolf
2016-01-22 11:24   ` Paolo Bonzini
2016-01-20 16:25 ` [Qemu-devel] [PULL 13/17] qcow2: Fix BDRV_O_INACTIVE handling in qcow2_invalidate_cache() Kevin Wolf
2016-01-20 16:25 ` [Qemu-devel] [PULL 14/17] qcow2: Make image inaccessible after failed qcow2_invalidate_cache() Kevin Wolf
2016-01-20 16:25 ` [Qemu-devel] [PULL 15/17] vmdk: Create streamOptimized as version 3 Kevin Wolf
2016-01-20 16:25 ` Kevin Wolf [this message]
2016-01-20 16:25 ` [Qemu-devel] [PULL 17/17] iotests: Test that throttle values ranges Kevin Wolf
2016-01-21 13:42 ` [Qemu-devel] [PULL 00/17] Block patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453307106-28330-17-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.