Skip to content

x86: Ignore the MPX BND prefix on near branches - #106

Open
NopeCharon wants to merge 1 commit into
angr:masterfrom
NopeCharon:fix/x86-bnd-prefix
Open

NopeCharon wants to merge 1 commit into
angr:masterfrom
NopeCharon:fix/x86-bnd-prefix

Conversation

@NopeCharon

Copy link
Copy Markdown

Fixes angr/pyvex#298.

An F2 prefix on a near call, jump or return is the MPX BND prefix. It shows up in -mmpx code and in BND-enabled PLT stubs (bnd jmp *...). The x86 front end accepted F2 only before C3, E9 and the short Jcc opcodes, where its REPNE case treats it as a branch hint. So bnd jmp rel8 (the f2 eb f5 from the issue), bnd ret imm16, bnd call, bnd jcc rel32 and the indirect bnd call/jmp r/m32 all lifted to an empty Ijk_NoDecode block.

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:

  • Each of jmp rel8/rel32, call rel32, ret, ret imm16, jz rel8/rel32, call [eax], call eax, jmp eax and jmp [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 f5 at 0 now gives NEXT: PUT(eip) = 0xfffffff8; Ijk_Boring, matching capstone's bnd jmp 0xfffffff8.
  • repne scasb, movsd xmm0, xmm1, and F2 in front of a non-branch (f2 40, f2 ff 30) behave as before.
  • The pyvex test suite passes.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bnd jumps not lifted

1 participant