]> xenbits.xensource.com Git - qemu-upstream-4.5-testing.git/commitdiff
exec: Stop using memory after free
authorDon Slutz <don.slutz@gmail.com>
Mon, 30 Nov 2015 22:11:04 +0000 (17:11 -0500)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Thu, 18 Feb 2016 17:30:28 +0000 (17:30 +0000)
memory_region_unref(mr) can free memory.

For example I got:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f43280d4700 (LWP 4462)]
0x00007f43323283c0 in phys_section_destroy (mr=0x7f43259468b0)
    at /home/don/xen/tools/qemu-xen-dir/exec.c:1023
1023        if (mr->subpage) {
(gdb) bt
    at /home/don/xen/tools/qemu-xen-dir/exec.c:1023
    at /home/don/xen/tools/qemu-xen-dir/exec.c:1034
    at /home/don/xen/tools/qemu-xen-dir/exec.c:2205
(gdb) p mr
$1 = (MemoryRegion *) 0x7f43259468b0

And this change prevents this.

upstream-commit-id: 55b4e80b047300e1512df02887b7448ba3786b62

Signed-off-by: Don Slutz <Don.Slutz@Gmail.com>
Message-Id: <1448921464-21845-1-git-send-email-Don.Slutz@Gmail.com>
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
exec.c

diff --git a/exec.c b/exec.c
index cf120496f7e4467351e9ea425882432ace3866e0..b517a32164b03c0d8ee243e80978ae73d79e395b 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -875,9 +875,11 @@ static uint16_t phys_section_add(PhysPageMap *map,
 
 static void phys_section_destroy(MemoryRegion *mr)
 {
+    bool have_sub_page = mr->subpage;
+
     memory_region_unref(mr);
 
-    if (mr->subpage) {
+    if (have_sub_page) {
         subpage_t *subpage = container_of(mr, subpage_t, iomem);
         memory_region_destroy(&subpage->iomem);
         g_free(subpage);