Skip to content

Commit 2eb9be9

Browse files
committed
[X86][MC] Reject out-of-range segment and debug registers encoded with APX
APX specification states that the high bits found in REX2 used to encode GPRs can also be used to encode segment and debug registers, although all of them will #UD. Therefore, when disassembling we reject attempts to create segment or debug registers with a value of 16 or more.
1 parent 815644b commit 2eb9be9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

llvm/lib/Target/X86/Disassembler/X86Disassembler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,12 @@ static int readModRM(struct InternalInstruction *insn) {
819819
*valid = 0; \
820820
return prefix##_ES + (index & 7); \
821821
case TYPE_DEBUGREG: \
822+
if (index > 15) \
823+
*valid = 0; \
822824
return prefix##_DR0 + index; \
823825
case TYPE_CONTROLREG: \
826+
if (index > 15) \
827+
*valid = 0; \
824828
return prefix##_CR0 + index; \
825829
case TYPE_MVSIBX: \
826830
return prefix##_XMM0 + index; \

llvm/test/MC/Disassembler/X86/x86-64-err.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
# 32: into
66
0xce
77

8+
# 64: invalid instruction encoding
9+
0xd5,0xc5,0x20,0xef
10+
# 64: invalid instruction encoding
11+
0xd5,0xc5,0x21,0xef
812
# 64: invalid instruction encoding
913
0xc4,0x62,0xf9,0x18,0x20
1014
# 64: invalid instruction encoding

0 commit comments

Comments
 (0)