Skip to content

x86 decoder: misdecoded F3/F2-prefixed instructions (CET, crc32, popcnt flags, assertion abort) #2618

Open

Description

@bbiiggppiigg

A survey of F3/F2-prefixed x86_64 instructions found several decoder problems in InstructionDecoder_x86 / common/src/arch-x86.C. These are what remains after #2617 (prefix leak + tzcnt/lzcnt) and the follow-up that applies REP/REPNZ effects only to string instructions.

How we found it

The survey put F3 or F2 in front of every one-byte, 0F, 0F 38 and 0F 3A opcode, with 24 ModRM variants each (47,472 byte strings). Each string was decoded with objdump 2.40 and with Dyninst master (64964e6). We also decoded one sample of every F3/F2-prefixed instruction found in .text of RHEL 8 libc, ld.so and libstdc++ and of TensorFlow 2.20's libtensorflow_framework.so.2. Counts below are occurrences in those binaries.

Problems

  1. CET shadow-stack instructions (in libc and ld.so)

    bytes instruction Dyninst decodes
    f3 48 0f ae eb incsspq %rbx (libc 5, ld.so 1) lfence
    f3 0f 01 6e f8 rstorssp -0x8(%rsi) (libc 4) invalid
    f3 0f 01 ea saveprevssp (libc 4) invalid
    f3 48 0f 1e c8 rdsspq %rax (libc 12, ld.so 2) REP nop %rax

    An invalid decode inside a function ends parsing there.

  2. Other instructions whose F3/F2 selects the instruction, with no table entry

    Each one is decoded as the instruction without the prefix:

    • pause (f3 90) decodes as nop;
    • wbnoinvd (f3 0f 09) decodes as wbinvd;
    • senduipi (f3 0f c7 /6, register) decodes as rdrand;
    • vmxon (f3 0f c7 /6, memory) decodes as rdrand with a memory operand;
    • mcommit (f3 0f 01 fa) decodes as invlpg;
    • the MPX bndcl/bndcu/bndcn/bndmk (f3/f2 0f 1a/0f 1b) are not decoded as such either.
  3. crc32 operands. f2 0f 38 f1 ca (crc32 %edx,%ecx, 34 in libtensorflow_framework) decodes as crc32 %xmm2,%xmm1, with XMM registers instead of general-purpose registers.

  4. popcnt flags. popcnt is listed in get_read_flags (instructionAPI/src/Operation.C) with all six flags. It reads no flags and writes all six (zf from the source, the others cleared), so it should be in get_written_flags. There are 320 popcnt in libtensorflow_framework.

  5. Assertion abort. f3 0f 38 f3 3f and f2 0f 38 f3 3f abort the process in ia32_decode_opcode with Assertion '!"Entered VEX SSE MULT table when no VEX present."' failed. Any tool that decodes these bytes, for example while parsing data as code, terminates.

  6. Register-only instructions accepted with a memory operand. movq2dq (f3 0f d6), movdq2q (f2 0f d6) and insertq (f2 0f 78) with mod != 11 are invalid (objdump: (bad)). Dyninst decodes them with a memory operand and a longer length.

  7. Undefined encodings decoded as instructions. 144 prefix/opcode/ModRM combinations that objdump reports as (bad) are decoded by Dyninst as instructions. This has low priority; the list is in the survey data.

Not covered by the survey

  • F3/F2 combined with lock (xacquire/xrelease);
  • VEX/EVEX encodings;
  • instructions with more than one of these prefixes;
  • 32-bit mode.

The survey scripts and per-case results are kept locally and can be attached on request.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions