cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-vmdk-Handle-failure-for-potentially-large-allocation.patch

958e1b
From 2db24b5a4b5a760a0cf014e7285b0f07f0a63762 Mon Sep 17 00:00:00 2001
958e1b
Message-Id: <2db24b5a4b5a760a0cf014e7285b0f07f0a63762.1418766606.git.jen@redhat.com>
958e1b
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
958e1b
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
958e1b
From: Fam Zheng <famz@redhat.com>
958e1b
Date: Thu, 4 Dec 2014 00:05:20 -0600
958e1b
Subject: [CHANGE 26/31] vmdk: Handle failure for potentially large allocations
958e1b
To: rhvirt-patches@redhat.com,
958e1b
    jen@redhat.com
958e1b
958e1b
RH-Author: Fam Zheng <famz@redhat.com>
958e1b
Message-id: <1417651524-18041-27-git-send-email-famz@redhat.com>
958e1b
Patchwork-id: 62699
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH v5 26/30] vmdk: Handle failure for potentially large allocations
958e1b
Bugzilla: 1002493
958e1b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
958e1b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
958e1b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
958e1b
958e1b
From: Kevin Wolf <kwolf@redhat.com>
958e1b
958e1b
Some code in the block layer makes potentially huge allocations. Failure
958e1b
is not completely unexpected there, so avoid aborting qemu and handle
958e1b
out-of-memory situations gracefully.
958e1b
958e1b
This patch addresses the allocations in the vmdk block driver.
958e1b
958e1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
958e1b
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
Reviewed-by: Benoit Canet <benoit@irqsave.net>
958e1b
(cherry picked from commit d6e5993197990ff55c660714526681fa7028299e)
958e1b
Signed-off-by: Fam Zheng <famz@redhat.com>
958e1b
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
958e1b
---
958e1b
 block/vmdk.c | 12 ++++++++++--
958e1b
 1 file changed, 10 insertions(+), 2 deletions(-)
958e1b
958e1b
diff --git a/block/vmdk.c b/block/vmdk.c
958e1b
index 70b616a..560dd43 100644
958e1b
--- a/block/vmdk.c
958e1b
+++ b/block/vmdk.c
958e1b
@@ -456,7 +456,11 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,
958e1b
 
958e1b
     /* read the L1 table */
958e1b
     l1_size = extent->l1_size * sizeof(uint32_t);
958e1b
-    extent->l1_table = g_malloc(l1_size);
958e1b
+    extent->l1_table = g_try_malloc(l1_size);
958e1b
+    if (l1_size && extent->l1_table == NULL) {
958e1b
+        return -ENOMEM;
958e1b
+    }
958e1b
+
958e1b
     ret = bdrv_pread(extent->file,
958e1b
                      extent->l1_table_offset,
958e1b
                      extent->l1_table,
958e1b
@@ -472,7 +476,11 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,
958e1b
     }
958e1b
 
958e1b
     if (extent->l1_backup_table_offset) {
958e1b
-        extent->l1_backup_table = g_malloc(l1_size);
958e1b
+        extent->l1_backup_table = g_try_malloc(l1_size);
958e1b
+        if (l1_size && extent->l1_backup_table == NULL) {
958e1b
+            ret = -ENOMEM;
958e1b
+            goto fail_l1;
958e1b
+        }
958e1b
         ret = bdrv_pread(extent->file,
958e1b
                          extent->l1_backup_table_offset,
958e1b
                          extent->l1_backup_table,
958e1b
-- 
958e1b
2.1.0
958e1b