Skip to contentSkip to conversation

memory: fix segv on qemu_ram_free(block=0x0)

PATCH In review [email protected] 2 participants 2 messages Mar 29, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memory: fix segv on qemu_ram_free(block=0x0)

From: Marc-André Lureau <[email protected]>

Since f1060c55bf1377b4, the pointer is directly passed to qemu_ram_free(). However, on initialization failure, it may be called with a NULL pointer. Return immediately in this case.

This fixes a SEGV when memory initialization failed, for example permission denied on open backing store /dev/hugepages, with -object memory-backend-file,mem-path=/dev/hugepages.

Program received signal SIGSEGV, Segmentation fault.
0x00005555556e67e7 in qemu_ram_free (block=0x0) at /home/elmarco/src/qemu/exec.c:1775

---
 exec.c | 4 ++++
 1 file changed, 4 insertions(+)
exec.c +4 -0
index f398d21..965f3b2 100644
@@ -1771,6 +1771,10 @@ static void reclaim_ramblock(RAMBlock *block)
 
 void qemu_ram_free(RAMBlock *block)
 {
+    if (!block) {
+        return;
+    }
+
     qemu_mutex_lock_ramlist();
     QLIST_REMOVE_RCU(block, next);
     ram_list.mru_block = NULL;
Signature · 1 line
2.5.5
#1 lore raw
Quoted 6 lines · On 29/03/2016 13:20, [email protected] wrote:

From: Marc-André Lureau <[email protected]>

Since f1060c55bf1377b4, the pointer is directly passed to qemu_ram_free(). However, on initialization failure, it may be called with a NULL pointer. Return immediately in this case.

Quoted 8 lines

This fixes a SEGV when memory initialization failed, for example permission denied on open backing store /dev/hugepages, with -object memory-backend-file,mem-path=/dev/hugepages.

Program received signal SIGSEGV, Segmentation fault.
0x00005555556e67e7 in qemu_ram_free (block=0x0) at /home/elmarco/src/qemu/exec.c:1775

Looks good, thanks! I'll push it during hard freeze.

Paolo