[tip:tools/kvm] kvm tools: check negative value of num_pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  d6f018c909b74b9630df522fb469616e112a8bd5
Gitweb:     http://git.kernel.org/tip/d6f018c909b74b9630df522fb469616e112a8bd5
Author:     Liming Wang <walimisdev@xxxxxxxxx>
AuthorDate: Thu, 11 Aug 2011 15:21:59 +0800
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Thu, 11 Aug 2011 16:37:05 +0300

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 <walimisdev@xxxxxxxxx>
[ penberg@xxxxxxxxxx: cleanups ]
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/virtio/balloon.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
index 854d04b..983a114 100644
--- a/tools/kvm/virtio/balloon.c
+++ b/tools/kvm/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;
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux