Skip to contentSkip to conversation

pc: check for underflow in load_linux

PATCH Applied Paolo Bonzini 2 participants 2 messages Sep 14, 2015 – Sep 16, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc: check for underflow in load_linux

If (setup_size+1)*512 is small enough, kernel_size -= setup_size can allocate a huge amount of memory. Avoid that.

---
 hw/i386/pc.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/i386/pc.c +4 -0
index 56aecce..6a312bd 100644
@@ -986,6 +986,10 @@ static void load_linux(PCMachineState *pcms,
         setup_size = 4;
     }
     setup_size = (setup_size+1)*512;
+    if (setup_size > kernel_size) {
+        fprintf(stderr, "qemu: invalid kernel header\n");
+        exit(1);
+    }
     kernel_size -= setup_size;
 
     setup  = g_malloc(setup_size);
Signature · 1 line
2.5.0
#1 lore raw
Quoted 2 lines · Paolo Bonzini

If (setup_size+1)*512 is small enough, kernel_size -= setup_size can allocate a huge amount of memory. Avoid that.

Applied to -trivial, thanks!

/mjt