From dd6d9498939071e8e24358de0df917af96e09d45 Mon Sep 17 00:00:00 2001 From: NopeCharon <115794254+NopeCharon@users.noreply.github.com> Date: Mon, 16 Nov 2026 01:32:18 +0530 Subject: [PATCH] x86: Ignore the MPX BND prefix on near branches 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. --- priv/guest_x86_toIR.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/priv/guest_x86_toIR.c b/priv/guest_x86_toIR.c index 7292a9c94..acf69b199 100644 --- a/priv/guest_x86_toIR.c +++ b/priv/guest_x86_toIR.c @@ -8775,7 +8775,25 @@ DisResult disInstr_X86_WRK ( } break; } - default: + case 0xF2: { + /* F2 prefix on a near call, jump or return is the MPX BND + prefix, which can safely be ignored. Otherwise it is + REPNE (or part of an SSE opcode), handled below. */ + UChar op1 = getIByte(delta+1); + UChar op2 = getIByte(delta+2); + if ((op1 >= 0x70 && op1 <= 0x7F) + || op1 == 0xC2 || op1 == 0xC3 + || op1 == 0xE8 || op1 == 0xE9 || op1 == 0xEB + || (op1 == 0x0F && op2 >= 0x80 && op2 <= 0x8F) + || (op1 == 0xFF + && (gregOfRM(op2) == 2 || gregOfRM(op2) == 4))) { + DIP("bnd "); + } else { + goto not_a_prefix; + } + break; + } + default: goto not_a_prefix; } n_prefixes++;