Skip to contentSkip to conversation

target/i386: Generate #UD for LOCK on a register increment

PATCH Peter Maydell 1 participant 1 message Apr 9, 2019 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Peter Maydell

author Applied
#2 lore raw
Quoted 33 lines · Paolo Bonzini
Quoted 18 lines · Peter Maydell

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.

---
 target/i386/translate.c | 5 +++++
 1 file changed, 5 insertions(+)
target/i386/translate.c +0 -0
index 49cd298374b..b725bec37cd 100644
@@ -1398,6 +1398,11 @@ static void gen_op(DisasContext *s1, int op, TCGMemOp ot, int d)
 static void gen_inc(DisasContext *s1, TCGMemOp ot, int d, int c)

target/i386/translate.c static void gen_op(DisasContext *s1, int op, TCGMemOp ot, int d) · line 1408

Quoted 10 lines
target/i386/translate.c +5 -0
 {
     if (s1->prefix & PREFIX_LOCK) {
+        if (d != OR_TMP0) {
+            /* Lock prefix when destination is not memory */
+            gen_illegal_opcode(s1);
+            return;
+        }
         tcg_gen_movi_tl(s1->T0, c > 0 ? 1 : -1);
         tcg_gen_atomic_add_fetch_tl(s1->T0, s1->A0, s1->T0,
                                     s1->mem_index, ot | MO_LE);
Quoted 1 line

Feel free to apply it yourself.

Applied to master, thanks.

-- PMM