thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ae23c9
From f5eecfb16d182d3c37df06bf20e6843f126b33fe Mon Sep 17 00:00:00 2001
ae23c9
From: David Hildenbrand <david@redhat.com>
ae23c9
Date: Fri, 21 Sep 2018 10:18:00 +0100
ae23c9
Subject: [PATCH 3/4] exec: check that alignment is a power of two
ae23c9
ae23c9
RH-Author: David Hildenbrand <david@redhat.com>
ae23c9
Message-id: <20180921101800.27360-1-david@redhat.com>
ae23c9
Patchwork-id: 82229
ae23c9
O-Subject: [RHEL-8.0 qemu-kvm PATCH] exec: check that alignment is a power of two
ae23c9
Bugzilla: 1630746
ae23c9
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
ae23c9
RH-Acked-by: Pankaj Gupta <pagupta@redhat.com>
ae23c9
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
ae23c9
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
ae23c9
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1630746
ae23c9
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=18439951
ae23c9
Branch: rhel8/master-2.12.0
ae23c9
Upstream: 61362b71c105ccb151ca16897a7d56534423f390
ae23c9
ae23c9
Right now we can crash QEMU using e.g.
ae23c9
ae23c9
qemu-system-x86_64 -m 256M,maxmem=20G,slots=2 \
ae23c9
 -object memory-backend-file,id=mem0,size=12288,mem-path=/dev/zero,align=12288 \
ae23c9
 -device pc-dimm,id=dimm1,memdev=mem0
ae23c9
ae23c9
qemu-system-x86_64: util/mmap-alloc.c:115:
ae23c9
 qemu_ram_mmap: Assertion `is_power_of_2(align)' failed
ae23c9
ae23c9
Fix this by adding a proper check.
ae23c9
ae23c9
Signed-off-by: David Hildenbrand <david@redhat.com>
ae23c9
Message-Id: <20180607154705.6316-3-david@redhat.com>
ae23c9
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
ae23c9
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
ae23c9
(cherry picked from commit 61362b71c105ccb151ca16897a7d56534423f390)
ae23c9
Signed-off-by: David Hildenbrand <david@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 exec.c | 4 ++++
ae23c9
 1 file changed, 4 insertions(+)
ae23c9
ae23c9
diff --git a/exec.c b/exec.c
ae23c9
index 02b1efe..22cc7ef 100644
ae23c9
--- a/exec.c
ae23c9
+++ b/exec.c
ae23c9
@@ -1646,6 +1646,10 @@ static void *file_ram_alloc(RAMBlock *block,
ae23c9
                    " must be multiples of page size 0x%zx",
ae23c9
                    block->mr->align, block->page_size);
ae23c9
         return NULL;
ae23c9
+    } else if (block->mr->align && !is_power_of_2(block->mr->align)) {
ae23c9
+        error_setg(errp, "alignment 0x%" PRIx64
ae23c9
+                   " must be a power of two", block->mr->align);
ae23c9
+        return NULL;
ae23c9
     }
ae23c9
     block->mr->align = MAX(block->page_size, block->mr->align);
ae23c9
 #if defined(__s390x__)
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9