From 4cdf419d72984c5c197cd793d943695a0487f350 Mon Sep 17 00:00:00 2001 From: maxv Date: Sun, 17 Feb 2019 20:25:46 +0000 Subject: [PATCH] Fix handling of SIB instructions. We were jumping to the SIB node _before_ fetching the displacement, so the node would always think there was no displacement. This didn't alter the final GPA we would be touching - because it is fetched from the kernel directly and not from the computation -, but it altered the instruction length, and on some guests (like Fedora 64bit), the VCPU would resume execution at the wrong RIP and crash. Now these guests work. --- lib/libnvmm/libnvmm_x86.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libnvmm/libnvmm_x86.c b/lib/libnvmm/libnvmm_x86.c index f8909aaba859..c9ecc9371097 100644 --- a/lib/libnvmm/libnvmm_x86.c +++ b/lib/libnvmm/libnvmm_x86.c @@ -1,4 +1,4 @@ -/* $NetBSD: libnvmm_x86.c,v 1.23 2019/02/15 16:42:27 maxv Exp $ */ +/* $NetBSD: libnvmm_x86.c,v 1.24 2019/02/17 20:25:46 maxv Exp $ */ /* * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -2233,15 +2233,15 @@ node_regmodrm(struct x86_decode_fsm *fsm, struct x86_instr *instr) strg->u.reg = reg; } + /* The displacement applies to RM. */ + strm->disp.type = get_disp_type(instr); + if (has_sib(instr)) { /* Overwrites RM */ fsm_advance(fsm, 1, node_sib); return 0; } - /* The displacement applies to RM. */ - strm->disp.type = get_disp_type(instr); - if (is_rip_relative(fsm, instr)) { /* Overwrites RM */ strm->type = STORE_REG;