From 158bc6474a5192bb42e8d03944ad0b689e6e2d56 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 22 Oct 2017 04:32:30 +0000 Subject: [PATCH] [X86] Don't allow gather/scatter to disassembler if memory operand does not use a SIB byte. Fixes PR34998. llvm-svn: 316282 --- llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp | 4 ++++ llvm/test/MC/Disassembler/X86/gather-novsib.txt | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 llvm/test/MC/Disassembler/X86/gather-novsib.txt diff --git a/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp b/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp index 6884f2a..e781c98 100644 --- a/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp +++ b/llvm/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp @@ -1723,6 +1723,10 @@ static int readOperands(struct InternalInstruction* insn) { if (readModRM(insn)) return -1; + // Reject if SIB wasn't used. + if (insn->eaBase != EA_BASE_sib && insn->eaBase != EA_BASE_sib64) + return -1; + // If sibIndex was set to SIB_INDEX_NONE, index offset is 4. if (insn->sibIndex == SIB_INDEX_NONE) insn->sibIndex = (SIBIndex)4; diff --git a/llvm/test/MC/Disassembler/X86/gather-novsib.txt b/llvm/test/MC/Disassembler/X86/gather-novsib.txt new file mode 100644 index 0000000..d14abc1 --- /dev/null +++ b/llvm/test/MC/Disassembler/X86/gather-novsib.txt @@ -0,0 +1,4 @@ +# RUN: llvm-mc --disassemble %s -triple=x86_64-apple-darwin9 2>&1 | grep "invalid instruction encoding" + +// This corresponds to a gather, but doesn't use a SIB byte. +0xc4,0xe2,0xe9,0x92,0x08 -- 2.7.4