Skip to content

Commit

Permalink
lguest: fix crash on vmlinux images
Browse files Browse the repository at this point in the history
Typical message: 'lguest: unhandled trap 6 at 0x418726 (0x0)'

vmlinux guests were broken by 4cd8b5e
'lguest: use KVM hypercalls', which rewrites guest text from kvm hypercalls
to trap 31.

The Launcher mmaps the kernel image.  The Guest executes and
immediately faults in the first text page (read-only).  Then it hits a
hypercall, and we rewrite that hypercall, causing a copy-on-write.
But the Guest pagetables still refer to the old page: we fault again,
but as Host we see the hypercall already rewritten, and pass the fault
back to the Guest.  The Guest hasn't set up an IDT yet, so we kill it.

This doesn't happen with bzImages: they unpack themselves and so the
text pages are already read-write.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Tested-by: Patrick McHardy <kaber@trash.net>
  • Loading branch information
Matias Zabaljauregui authored and Rusty Russell committed Apr 19, 2009
1 parent ff54250 commit 88df781
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/lguest/x86/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ static void rewrite_hypercall(struct lg_cpu *cpu)
u8 insn[3] = {0xcd, 0x1f, 0x90};

__lgwrite(cpu, guest_pa(cpu, cpu->regs->eip), insn, sizeof(insn));
/* The above write might have caused a copy of that page to be made
* (if it was read-only). We need to make sure the Guest has
* up-to-date pagetables. As this doesn't happen often, we can just
* drop them all. */
guest_pagetable_clear_all(cpu);
}

static bool is_hypercall(struct lg_cpu *cpu)
Expand Down

0 comments on commit 88df781

Please sign in to comment.