]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
target/i386/tcg: validate segment registers
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 14 Nov 2025 23:57:52 +0000 (00:57 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 17 Nov 2025 08:49:26 +0000 (09:49 +0100)
Correctly reject invalid segment registers, including CS when used as
the destination of a MOV.  Ignore the REX prefix as well.

Fixes: 5e9e21bcc4d ("target/i386: move 60-BF opcodes to new decoder", 2024-05-07)
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3195
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
target/i386/tcg/decode-new.c.inc

index 805cfd08e83e193f3094e7a33d89c85481e1eb7f..0f8c5d1693845a8ef71efa49c9e62d3684f10802 100644 (file)
@@ -2059,7 +2059,12 @@ static bool decode_op(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode,
 
     case X86_TYPE_S:  /* reg selects a segment register */
         op->unit = X86_OP_SEG;
-        goto get_reg;
+        op->n = (get_modrm(s, env) >> 3) & 7;
+        /* Values outside [CDEFGS]S, as well as storing to CS, are invalid.  */
+        if (op->n >= 6 || (op->n == R_CS && op == &decode->op[0])) {
+            return false;
+        }
+        break;
 
     case X86_TYPE_P:
         op->unit = X86_OP_MMX;