9ae3a8
From 62ba92f33f1d727cff17f5d1b38fabfe0901f7ee Mon Sep 17 00:00:00 2001
9ae3a8
From: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
Date: Tue, 30 Sep 2014 01:08:31 +0200
9ae3a8
Subject: [PATCH 3/3] virtio-balloon: fix integer overflow in memory stats
9ae3a8
 feature
9ae3a8
9ae3a8
Message-id: <20140929210831.1cc65ebe@redhat.com>
9ae3a8
Patchwork-id: 61504
9ae3a8
O-Subject: [RHEL7.1 qemu-kvm PATCH] virtio-balloon: fix integer overflow in memory stats feature
9ae3a8
Bugzilla: 1142290
9ae3a8
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
9ae3a8
RH-Acked-by: Juan Quintela <quintela@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
When a QMP client changes the polling interval time by setting
9ae3a8
the guest-stats-polling-interval property, the interval value
9ae3a8
is stored and manipulated as an int64_t variable.
9ae3a8
9ae3a8
However, the balloon_stats_change_timer() function, which is
9ae3a8
used to set the actual timer with the interval value, takes
9ae3a8
an int instead, causing an overflow for big interval values.
9ae3a8
9ae3a8
This commit fix this bug by changing balloon_stats_change_timer()
9ae3a8
to take an int64_t and also it limits the polling interval value
9ae3a8
to UINT_MAX to avoid other kinds of overflow.
9ae3a8
9ae3a8
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
Reviewed-by: Eric Blake <eblake@redhat.com>
9ae3a8
Reviewed-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
(cherry picked from commit 1f9296b51a26650916a2c4191268bb64057bdc5f)
9ae3a8
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/virtio/virtio-balloon.c | 7 ++++++-
9ae3a8
 1 file changed, 6 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
9ae3a8
index 76c607f..016dc60 100644
9ae3a8
--- a/hw/virtio/virtio-balloon.c
9ae3a8
+++ b/hw/virtio/virtio-balloon.c
9ae3a8
@@ -85,7 +85,7 @@ static void balloon_stats_destroy_timer(VirtIOBalloon *s)
9ae3a8
     }
9ae3a8
 }
9ae3a8
 
9ae3a8
-static void balloon_stats_change_timer(VirtIOBalloon *s, int secs)
9ae3a8
+static void balloon_stats_change_timer(VirtIOBalloon *s, int64_t secs)
9ae3a8
 {
9ae3a8
     qemu_mod_timer(s->stats_timer, qemu_get_clock_ms(vm_clock) + secs * 1000);
9ae3a8
 }
9ae3a8
@@ -154,6 +154,11 @@ static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
9ae3a8
         return;
9ae3a8
     }
9ae3a8
 
9ae3a8
+    if (value > UINT_MAX) {
9ae3a8
+        error_setg(errp, "timer value is too big");
9ae3a8
+        return;
9ae3a8
+    }
9ae3a8
+
9ae3a8
     if (value == s->stats_poll_interval) {
9ae3a8
         return;
9ae3a8
     }
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8