From dc702c2d98e918027ccf108fa34855cf390caac6 Mon Sep 17 00:00:00 2001 From: grehan Date: Thu, 18 Jul 2013 18:40:54 +0000 Subject: Sanity-check the vm exitcode, and exit the process if it's out-of-bounds or there is no registered handler. Submitted by: Bela Lubkin bela dot lubkin at tidalscale dot com --- usr.sbin/bhyve/bhyverun.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index cfcf7ec..43eea98 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -509,6 +509,7 @@ vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip) { cpuset_t mask; int error, rc, prevcpu; + enum vm_exitcode exitcode; if (guest_vcpu_mux) setup_timeslice(); @@ -538,8 +539,16 @@ vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip) } prevcpu = vcpu; - rc = (*handler[vmexit[vcpu].exitcode])(ctx, &vmexit[vcpu], - &vcpu); + + exitcode = vmexit[vcpu].exitcode; + if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) { + fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n", + exitcode); + exit(1); + } + + rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu); + switch (rc) { case VMEXIT_SWITCH: assert(guest_vcpu_mux); -- cgit v1.1