Repository navigation
x86: Ignore the MPX BND prefix on near branches - #106
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
An F2 prefix on a near call, jump or return is the MPX BND prefix, as
emitted by -mmpx code and by BND-enabled PLT stubs ("bnd jmp"). The
x86 front end only accepted F2 in front of C3, E9 and the short Jcc
opcodes, where it treated it as a REPNE branch hint, so "bnd jmp rel8",
"bnd ret imm16", "bnd call", "bnd jcc rel32" and the indirect forms
failed to decode.
Handle F2 in the prefix loop the same way as the CS branch hint: if
the next opcode is a near Jcc (70-7F, 0F 80-8F), RET (C2/C3), CALL/JMP
rel (E8/E9/EB) or an indirect near CALL/JMP (FF /2, FF /4), skip it
and decode the branch normally. Any other F2 still falls through to
the REPNE/SSE handling. The amd64 front end already accepts BND.
Fixes angr/pyvex#298.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes angr/pyvex#298.
An F2 prefix on a near call, jump or return is the MPX BND prefix. It shows up in
-mmpxcode and in BND-enabled PLT stubs (bnd jmp *...). The x86 front end accepted F2 only beforeC3,E9and the short Jcc opcodes, where its REPNE case treats it as a branch hint. Sobnd jmp rel8(thef2 eb f5from the issue),bnd ret imm16,bnd call,bnd jcc rel32and the indirectbnd call/jmp r/m32all lifted to an emptyIjk_NoDecodeblock.This handles F2 in the prefix loop, the same way the CS (
2E) branch hint is already handled there. If the next opcode is a near Jcc (70-7F,0F 80-8F), a RET (C2/C3), a relative CALL/JMP (E8/E9/EB) or an indirect near CALL/JMP (FF /2,FF /4), the prefix is skipped and the branch decodes normally. Any other F2 (REPNE string ops, SSE, invalid uses) falls through to the existing handling unchanged. The amd64 front end already accepts BND.Checked through pyvex built against this branch:
jmp rel8/rel32,call rel32,ret,ret imm16,jz rel8/rel32,call [eax],call eax,jmp eaxandjmp [ebx+4]with an F2 prefix lifts to the same IR as the unprefixed instruction, with one extra byte of length and targets and return addresses adjusted for it. For example,f2 eb f5at 0 now givesNEXT: PUT(eip) = 0xfffffff8; Ijk_Boring, matching capstone'sbnd jmp 0xfffffff8.repne scasb,movsd xmm0, xmm1, and F2 in front of a non-branch (f2 40,f2 ff 30) behave as before.