Skip to contentSkip to conversation

virtio-balloon: fix buffer overflow in memory stats feature

PATCH Superseded Luiz Capitulino 3 participants 7 messages Sep 15, 2014 – Sep 16, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-balloon: fix buffer 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 manipuled 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.

Fix it.

---
 hw/virtio/virtio-balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +1 -1
index 2c30b3d..9629264 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);
 }
Signature · 1 line
1.9.3
#1 lore raw
Quoted 4 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 manipuled as an int64_t variable.

s/manipuled/manipulated/

Quoted 16 lines

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.

Fix it.

---
 hw/virtio/virtio-balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +0 -0
index 2c30b3d..9629264 100644

hw/virtio/virtio-balloon.c static void balloon_stats_destroy_timer(VirtIOBalloon *s) · line 92

Quoted 7 lines
hw/virtio/virtio-balloon.c +1 -1
@@ -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);

secs * 1000 can still overflow for (really large) values, do we care about that?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 27 lines · On Mon, 15 Sep 2014 13:16:01 -0600 Eric Blake <[email protected]> wrote:
Quoted 4 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 manipuled as an int64_t variable.

s/manipuled/manipulated/

Quoted 19 lines

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.

Fix it.

---
 hw/virtio/virtio-balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +0 -0
index 2c30b3d..9629264 100644
@@ -87,7 +87,7 @@ static void balloon_stats_destroy_timer(VirtIOBalloon *s)
     }
 }
 
Quoted 7 lines

hw/virtio/virtio-balloon.c static void balloon_stats_destroy_timer(VirtIOBalloon *s) · line 92

Quoted 4 lines
hw/virtio/virtio-balloon.c +1 -1
-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);

secs * 1000 can still overflow for (really large) values, do we care about that?

Hmm, good point. I think I could keep the s/int/int64_t change but limit secs to UINT_MAX for simplicity. I guess we don't expect anyone to set this to billions of seconds in the future :)

#3 lore raw
In reply to Luiz Capitulino
Quoted 11 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 manipuled 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.

Fix it.

Subject claims buffer overflow, but description suggests integer overflow. Which one is it?

[...]

#4 lore raw
Quoted 10 lines · On Tue, 16 Sep 2014 09:25:02 +0200 Markus Armbruster <[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 manipuled 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 6 lines
Quoted 3 lines

Fix it.

Subject claims buffer overflow, but description suggests integer overflow. Which one is it?

Integer.

#5 lore raw
Quoted 13 lines · Luiz Capitulino
Quoted 10 lines · On Tue, 16 Sep 2014 09:25:02 +0200 Markus Armbruster <[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 manipuled 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
Quoted 6 lines
Quoted 3 lines

Fix it.

Subject claims buffer overflow, but description suggests integer overflow. Which one is it?

Integer.

Thanks. If you fix the subject, you can add my R-by.

#6 lore raw
Quoted 17 lines · On Tue, 16 Sep 2014 15:43:14 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 15 lines · Luiz Capitulino
Quoted 12 lines · On Tue, 16 Sep 2014 09:25:02 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 10 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 manipuled 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.

Fix it.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Subject claims buffer overflow, but description suggests integer overflow. Which one is it?

Integer.

Thanks. If you fix the subject, you can add my R-by.

I've fixed the subject, but I've also added a new hunk to the patch.