x86: check for invalid instructions with LOCK prefix

This commit is contained in:
Nguyen Anh Quynh 2015-01-05 22:18:00 +07:00
parent 18dfc1929d
commit 5323128ed2
1 changed files with 202 additions and 0 deletions

View File

@ -2001,6 +2001,207 @@ static int readOperands(struct InternalInstruction *insn)
return 0;
}
// return True if instruction is illegal to use with prefixes
// or False otherwise
static bool invalidPrefix(struct InternalInstruction *insn)
{
// LOCK prefix
if (insn->prefixPresent[0xf0]) {
switch(insn->instructionID) {
default:
// invalid LOCK
return true;
// DEC
case X86_DEC16m:
case X86_DEC32m:
case X86_DEC64_16m:
case X86_DEC64_32m:
case X86_DEC64m:
case X86_DEC8m:
// ADC
case X86_ADC16mi:
case X86_ADC16mi8:
case X86_ADC16mr:
case X86_ADC16rm:
case X86_ADC32mi:
case X86_ADC32mi8:
case X86_ADC32mr:
case X86_ADC32rm:
case X86_ADC64mi32:
case X86_ADC64mi8:
case X86_ADC64mr:
case X86_ADC64rm:
case X86_ADC8mi:
case X86_ADC8mi8:
case X86_ADC8mr:
case X86_ADC8rm:
case X86_ADCX32rm:
case X86_ADCX64rm:
// AND
case X86_AND16mi:
case X86_AND16mi8:
case X86_AND16mr:
case X86_AND16rm:
case X86_AND32mi:
case X86_AND32mi8:
case X86_AND32mr:
case X86_AND32rm:
case X86_AND64mi32:
case X86_AND64mi8:
case X86_AND64mr:
case X86_AND64rm:
case X86_AND82_8mi8:
case X86_AND8mi:
case X86_AND8mr:
case X86_AND8rm:
// BTC
case X86_BTC16mi8:
case X86_BTC16mr:
case X86_BTC32mi8:
case X86_BTC32mr:
case X86_BTC64mi8:
case X86_BTC64mr:
// BTR
case X86_BTR16mi8:
case X86_BTR16mr:
case X86_BTR32mi8:
case X86_BTR32mr:
case X86_BTR64mi8:
case X86_BTR64mr:
// BTS
case X86_BTS16mi8:
case X86_BTS16mr:
case X86_BTS32mi8:
case X86_BTS32mr:
case X86_BTS64mi8:
case X86_BTS64mr:
// CMPXCHG
case X86_CMPXCHG16rm:
case X86_CMPXCHG32rm:
case X86_CMPXCHG64rm:
case X86_CMPXCHG8rm:
// INC
case X86_INC16m:
case X86_INC32m:
case X86_INC64_16m:
case X86_INC64_32m:
case X86_INC64m:
case X86_INC8m:
// NEG
case X86_NEG16m:
case X86_NEG32m:
case X86_NEG64m:
case X86_NEG8m:
// NOT
case X86_NOT16m:
case X86_NOT32m:
case X86_NOT64m:
case X86_NOT8m:
// OR
case X86_OR16mi:
case X86_OR16mi8:
case X86_OR16mr:
case X86_OR16rm:
case X86_OR32mi:
case X86_OR32mi8:
case X86_OR32mr:
case X86_OR32mrLocked:
case X86_OR32rm:
case X86_OR64mi32:
case X86_OR64mi8:
case X86_OR64mr:
case X86_OR64rm:
case X86_OR82_8mi8:
case X86_OR8mi:
case X86_OR8mr:
case X86_OR8rm:
// SBB
case X86_SBB16mi:
case X86_SBB16mi8:
case X86_SBB16mr:
case X86_SBB16rm:
case X86_SBB32mi:
case X86_SBB32mi8:
case X86_SBB32mr:
case X86_SBB32rm:
case X86_SBB64mi32:
case X86_SBB64mi8:
case X86_SBB64mr:
case X86_SBB64rm:
case X86_SBB8mi:
case X86_SBB8mi8:
case X86_SBB8mr:
case X86_SBB8rm:
// SUB
case X86_SUB16mi:
case X86_SUB16mi8:
case X86_SUB16mr:
case X86_SUB16rm:
case X86_SUB32mi:
case X86_SUB32mi8:
case X86_SUB32mr:
case X86_SUB32rm:
case X86_SUB64mi32:
case X86_SUB64mi8:
case X86_SUB64mr:
case X86_SUB64rm:
case X86_SUB82_8mi8:
case X86_SUB8mi:
case X86_SUB8mr:
case X86_SUB8rm:
// XADD
case X86_XADD16rm:
case X86_XADD32rm:
case X86_XADD64rm:
case X86_XADD8rm:
// XCHG
case X86_XCHG16rm:
case X86_XCHG32rm:
case X86_XCHG64rm:
case X86_XCHG8rm:
// XOR
case X86_XOR16mi:
case X86_XOR16mi8:
case X86_XOR16mr:
case X86_XOR16rm:
case X86_XOR32mi:
case X86_XOR32mi8:
case X86_XOR32mr:
case X86_XOR32rm:
case X86_XOR64mi32:
case X86_XOR64mi8:
case X86_XOR64mr:
case X86_XOR64rm:
case X86_XOR82_8mi8:
case X86_XOR8mi:
case X86_XOR8mr:
case X86_XOR8rm:
// this instruction can be used with LOCK prefix
return false;
}
}
// no invalid prefixes
return false;
}
/*
* decodeInstruction - Reads and interprets a full instruction provided by the
* user.
@ -2032,6 +2233,7 @@ int decodeInstruction(struct InternalInstruction *insn,
readOpcode(insn) ||
getID(insn) ||
insn->instructionID == 0 ||
invalidPrefix(insn) ||
readOperands(insn))
return -1;