Skip to contentSkip to conversation

virtio-balloon: fix integer overflow in memory stats feature

PATCH In review Luiz Capitulino 4 participants 5 messages Sep 16, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 virtio-balloon: fix integer overflow in memory stats feature

When a QMP client changes the polling interval time by setting the guest-stats-polling-interval property, the interval value is stored and manipulated as an int64_t variable.

However, the balloon_stats_change_timer() function, which is used to set the actual timer with the interval value, takes an int instead, causing an overflow for big interval values.

This commit fix this bug by changing balloon_stats_change_timer() to take an int64_t and also it limits the polling interval value to UINT_MAX to avoid other kinds of overflow.

---
 hw/virtio/virtio-balloon.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +6 -1
index 2c30b3d..b5cf7ca 100644
@@ -87,7 +87,7 @@ static void balloon_stats_destroy_timer(VirtIOBalloon *s)
     }
 }
 
-static void balloon_stats_change_timer(VirtIOBalloon *s, int secs)
+static void balloon_stats_change_timer(VirtIOBalloon *s, int64_t secs)
 {
     timer_mod(s->stats_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + secs * 1000);
 }
@@ -170,6 +170,11 @@ static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
         return;
     }
 
+    if (value > UINT_MAX) {
+        error_setg(errp, "timer value is too big");
+        return;
+    }
+
     if (value == s->stats_poll_interval) {
         return;
     }
Signature · 1 line
1.9.3
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Luiz Capitulino

When a QMP client changes the polling interval time by setting the guest-stats-polling-interval property, the interval value is stored and manipulated as an int64_t variable.

However, the balloon_stats_change_timer() function, which is used to set the actual timer with the interval value, takes an int instead, causing an overflow for big interval values.

Quoted 8 lines

This commit fix this bug by changing balloon_stats_change_timer() to take an int64_t and also it limits the polling interval value to UINT_MAX to avoid other kinds of overflow.

---
 hw/virtio/virtio-balloon.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
In reply to Luiz Capitulino
Quoted 8 lines · Luiz Capitulino

When a QMP client changes the polling interval time by setting the guest-stats-polling-interval property, the interval value is stored and manipulated as an int64_t variable.

However, the balloon_stats_change_timer() function, which is used to set the actual timer with the interval value, takes an int instead, causing an overflow for big interval values.

Quoted 5 lines

This commit fix this bug by changing balloon_stats_change_timer() to take an int64_t and also it limits the polling interval value to UINT_MAX to avoid other kinds of overflow.

OK but pls remember to Cc qemu-stable on bugfixes.

Quoted 33 lines

---

 hw/virtio/virtio-balloon.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +6 -1
index 2c30b3d..b5cf7ca 100644
@@ -87,7 +87,7 @@ static void balloon_stats_destroy_timer(VirtIOBalloon *s)
     }
 }
 
-static void balloon_stats_change_timer(VirtIOBalloon *s, int secs)
+static void balloon_stats_change_timer(VirtIOBalloon *s, int64_t secs)
 {
     timer_mod(s->stats_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + secs * 1000);
 }
@@ -170,6 +170,11 @@ static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
         return;
     }
 
+    if (value > UINT_MAX) {
+        error_setg(errp, "timer value is too big");
+        return;
+    }
+
     if (value == s->stats_poll_interval) {
         return;
     }
Signature · 1 line
1.9.3
#3 lore raw
Quoted 9 lines · On Tue, 16 Sep 2014 18:02:54 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 8 lines · Luiz Capitulino

When a QMP client changes the polling interval time by setting the guest-stats-polling-interval property, the interval value is stored and manipulated as an int64_t variable.

However, the balloon_stats_change_timer() function, which is used to set the actual timer with the interval value, takes an int instead, causing an overflow for big interval values.

Quoted 7 lines
Quoted 5 lines

This commit fix this bug by changing balloon_stats_change_timer() to take an int64_t and also it limits the polling interval value to UINT_MAX to avoid other kinds of overflow.

OK but pls remember to Cc qemu-stable on bugfixes.

I did.

Quoted 35 lines
Quoted 34 lines

---

 hw/virtio/virtio-balloon.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +6 -1
index 2c30b3d..b5cf7ca 100644
@@ -87,7 +87,7 @@ static void balloon_stats_destroy_timer(VirtIOBalloon *s)
     }
 }
 
-static void balloon_stats_change_timer(VirtIOBalloon *s, int secs)
+static void balloon_stats_change_timer(VirtIOBalloon *s, int64_t secs)
 {
     timer_mod(s->stats_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + secs * 1000);
 }
@@ -170,6 +170,11 @@ static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
         return;
     }
 
+    if (value > UINT_MAX) {
+        error_setg(errp, "timer value is too big");
+        return;
+    }
+
     if (value == s->stats_poll_interval) {
         return;
     }
Signature · 1 line
1.9.3
Reviewed-by on v2 1/1
#4 lore raw
In reply to Luiz Capitulino
Quoted 8 lines · Luiz Capitulino

When a QMP client changes the polling interval time by setting the guest-stats-polling-interval property, the interval value is stored and manipulated as an int64_t variable.

However, the balloon_stats_change_timer() function, which is used to set the actual timer with the interval value, takes an int instead, causing an overflow for big interval values.

Quoted 5 lines

This commit fix this bug by changing balloon_stats_change_timer() to take an int64_t and also it limits the polling interval value to UINT_MAX to avoid other kinds of overflow.