From 42bcd3eea136301664d02108639a49e3dfce6873 Mon Sep 17 00:00:00 2001 From: Liming Wang Date: Thu, 11 Aug 2011 15:21:59 +0800 Subject: [PATCH] kvm tools: check negative value of num_pages If num_pages is negative, balloon will make kernel crash with "out of memory". So we check this value to avoid it to be negative. Signed-off-by: Liming Wang [ penberg@kernel.org: cleanups ] Signed-off-by: Pekka Enberg --- virtio/balloon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/virtio/balloon.c b/virtio/balloon.c index 854d04b..983a114 100644 --- a/virtio/balloon.c +++ b/virtio/balloon.c @@ -220,10 +220,14 @@ static struct ioport_operations virtio_bln_io_ops = { static void handle_sigmem(int sig) { - if (sig == SIGKVMADDMEM) + if (sig == SIGKVMADDMEM) { bdev.config.num_pages += 256; - else + } else { + if (bdev.config.num_pages < 256) + return; + bdev.config.num_pages -= 256; + } /* Notify that the configuration space has changed */ bdev.isr = VIRTIO_PCI_ISR_CONFIG;