Skip to content

Commit

Permalink
target/i386: Do not re-compute new pc with CF_PCREL
Browse files Browse the repository at this point in the history
With PCREL, we have a page-relative view of EIP, and an
approximation of PC = EIP+CSBASE that is good enough to
detect page crossings.  If we try to recompute PC after
masking EIP, we will mess up that approximation and write
a corrupt value to EIP.

We already handled masking properly for PCREL, so the
fix in b5e0d5d was only needed for the !PCREL path.

Cc: qemu-stable@nongnu.org
Fixes: b5e0d5d ("target/i386: Fix 32-bit wrapping of pc/eip computation")
Reported-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20240101230617.129349-1-richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
rth7680 authored and bonzini committed Jan 18, 2024
1 parent 3cbc17e commit a58506b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions target/i386/tcg/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2866,10 +2866,6 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
}
}
new_eip &= mask;
new_pc = new_eip + s->cs_base;
if (!CODE64(s)) {
new_pc = (uint32_t)new_pc;
}

gen_update_cc_op(s);
set_cc_op(s, CC_OP_DYNAMIC);
Expand All @@ -2885,6 +2881,8 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
tcg_gen_andi_tl(cpu_eip, cpu_eip, mask);
use_goto_tb = false;
}
} else if (!CODE64(s)) {
new_pc = (uint32_t)(new_eip + s->cs_base);
}

if (use_goto_tb && translator_use_goto_tb(&s->base, new_pc)) {
Expand Down

0 comments on commit a58506b

Please sign in to comment.