Skip to content

Commit

Permalink
arch-x86: Fixed M5InternalError when decoding certain bytes
Browse files Browse the repository at this point in the history
0F 38 is the two bytes prefixes to decode a three-byte opcode.
To prevent errors, the two_bytes_opcode decoder will complain
if it tries to decode 38 as the opcode, because it is a prefix.
The decoder, will treat 38 as a prefix, preventing it to
end in the two_byte_opcode decoder.

However, using the VEX prefix is possible to reach this
forbidden state.

The set of bytes C4 01 01 38 00 will trigger the mentioned
M5InternalError.

The previous instruction is not valid, but it could be
decoded from an speculative path. In its place, a UD2
instructtion should be emitted if the VEX prefix is
present.

Change-Id: I6b7c4b3593dd8e6e8ac99aaf306b8feeb7784b56
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49990
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
  • Loading branch information
OdnetninI committed Oct 7, 2021
1 parent 2b69ff2 commit 2b46872
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/arch/x86/isa/bitfields.isa
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ def bitfield MODE mode;
def bitfield MODE_MODE mode.mode;
def bitfield MODE_SUBMODE mode.submode;

def bitfield VEX_PRESENT vex.present;
def bitfield VEX_V vex.v;
def bitfield VEX_L vex.l;
19 changes: 11 additions & 8 deletions src/arch/x86/isa/decoder/two_byte_opcodes.isa
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,17 @@
0x6: Inst::UD2();
0x7: getsec();
}
0x07: decode OPCODE_OP_BOTTOM3 {
0x0: M5InternalError::error(
{{"Three byte opcode shouldn't be handled by "
"two_byte_opcodes.isa!"}});
0x2: M5InternalError::error(
{{"Three byte opcode shouldn't be handled by "
"two_byte_opcodes.isa!"}});
default: UD2();
0x07: decode VEX_PRESENT {
0x0: decode OPCODE_OP_BOTTOM3 {
0x0: M5InternalError::error(
{{"Three byte opcode shouldn't be handled by "
"two_byte_opcodes.isa!"}});
0x2: M5InternalError::error(
{{"Three byte opcode shouldn't be handled by "
"two_byte_opcodes.isa!"}});
default: UD2();
}
0x1: UD2();
}
format Inst {
0x08: decode OPCODE_OP_BOTTOM3 {
Expand Down

0 comments on commit 2b46872

Please sign in to comment.