]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm: Don't crash debug dump if address isn't in guest memory
authorPekka Enberg <penberg@cs.helsinki.fi>
Sun, 11 Apr 2010 09:45:15 +0000 (12:45 +0300)
committerPekka Enberg <penberg@cs.helsinki.fi>
Sun, 11 Apr 2010 09:45:15 +0000 (12:45 +0300)
We don't do MMU translation in the hypevisor for guest memory addresses which
causes us to try to dereference invalid pointers.  Work around the problem by
checking that a pointer is in guest memory before dumping the contents.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
tools/kvm/kvm.c

index 64316875db874e7e8cb7926d3ae7c5496ab954af..11dec87ef0e5093b515e3299a1c807f483e494fb 100644 (file)
@@ -50,6 +50,11 @@ const char *kvm_exit_reasons[] = {
        DEFINE_KVM_EXIT_REASON(KVM_EXIT_INTERNAL_ERROR),
 };
 
+static inline bool host_ptr_in_ram(struct kvm *self, void *p)
+{
+       return self->ram_start <= p && p < (self->ram_start + self->ram_size);
+}
+
 static inline uint32_t segment_to_flat(uint16_t selector, uint16_t offset)
 {
        return ((uint32_t)selector << 4) + (uint32_t) offset;
@@ -650,6 +655,9 @@ void kvm__show_code(struct kvm *self)
        printf("Code: ");
 
        for (i = 0; i < code_len; i++, ip++) {
+               if (!host_ptr_in_ram(self, ip))
+                       break;
+
                c = *ip;
 
                if (ip == guest_flat_to_host(self, ip_to_flat(self, self->regs.rip)))
@@ -678,9 +686,20 @@ void kvm__show_page_tables(struct kvm *self)
                die("KVM_GET_SREGS failed");
 
        pte4    = guest_flat_to_host(self, self->sregs.cr3);
+       if (!host_ptr_in_ram(self, pte4))
+               return;
+
        pte3    = guest_flat_to_host(self, (*pte4 & ~0xfff));
+       if (!host_ptr_in_ram(self, pte3))
+               return;
+
        pte2    = guest_flat_to_host(self, (*pte3 & ~0xfff));
+       if (!host_ptr_in_ram(self, pte2))
+               return;
+
        pte1    = guest_flat_to_host(self, (*pte2 & ~0xfff));
+       if (!host_ptr_in_ram(self, pte1))
+               return;
 
        printf("Page Tables:\n");
        if (*pte2 & (1 << 7))
@@ -700,8 +719,12 @@ void kvm__dump_mem(struct kvm *self, unsigned long addr, unsigned long size)
 
        p = guest_flat_to_host(self, addr);
 
-       for (n = 0; n < size; n+=8)
+       for (n = 0; n < size; n+=8) {
+               if (!host_ptr_in_ram(self, p + n))
+                       break;
+
                printf("  0x%08lx: %02x %02x %02x %02x  %02x %02x %02x %02x\n",
                        addr + n, p[n + 0], p[n + 1], p[n + 2], p[n + 3],
                                  p[n + 4], p[n + 5], p[n + 6], p[n + 7]);
+       }
 }