yeahuh / rpms / qemu-kvm

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