From 6b413ffa97be6a821e833e73d371687034cfee28 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Tue, 9 Apr 2019 09:28:32 -0400 Subject: [PATCH] target/i386: Generate #UD for LOCK on a register increment Fix a TCG crash due to attempting an atomic increment operation without having set up the address first. This is a similar case to that dealt with in commit e84fcd7f662a0d8198703, and we fix it in the same way. Fixes: https://bugs.launchpad.net/qemu/+bug/1807675 Backports commit 8cb2ca3d7479748587313f0b34034a3f8aa08c92 from qemu --- qemu/target/i386/translate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qemu/target/i386/translate.c b/qemu/target/i386/translate.c index 78865673..34bd826c 100644 --- a/qemu/target/i386/translate.c +++ b/qemu/target/i386/translate.c @@ -1564,6 +1564,11 @@ static void gen_inc(DisasContext *s, TCGMemOp ot, int d, int c) TCGv cpu_cc_src = tcg_ctx->cpu_cc_src; if (s->prefix & PREFIX_LOCK) { + if (d != OR_TMP0) { + /* Lock prefix when destination is not memory */ + gen_illegal_opcode(s1); + return; + } tcg_gen_movi_tl(tcg_ctx, s->T0, c > 0 ? 1 : -1); tcg_gen_atomic_add_fetch_tl(tcg_ctx, s->T0, s->A0, s->T0, s->mem_index, ot | MO_LE);