tcg/i386: Check the size of instruction being translated

This fixes the bug: 'user-to-root privesc inside VM via bad translation
caching' reported by Jann Horn here:
https://bugs.chromium.org/p/project-zero/issues/detail?id=1122

Backports commit 30663fd26c0307e414622c7a8607fbc04f92ec14 from qemu
This commit is contained in:
Pranith Kumar 2018-03-02 14:19:28 -05:00 committed by Lioncash
parent b750ec2363
commit 31b977ab3e
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -5048,6 +5048,13 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
s->vex_l = 0; s->vex_l = 0;
s->vex_v = 0; s->vex_v = 0;
next_byte: next_byte:
/* x86 has an upper limit of 15 bytes for an instruction. Since we
* do not want to decode and generate IR for an illegal
* instruction, the following check limits the instruction size to
* 25 bytes: 14 prefix + 1 opc + 6 (modrm+sib+ofs) + 4 imm */
if (s->pc - pc_start > 14) {
goto illegal_op;
}
b = cpu_ldub_code(env, s->pc); b = cpu_ldub_code(env, s->pc);
s->pc++; s->pc++;
/* Collect prefixes. */ /* Collect prefixes. */