Directed Proof Generation for Machine Code

Aditya V. Thakur, Junghee Lim, Akash Lal, Amanda Burton, Evan Driscoll, Matt Elder, Tycho Andersen, Thomas W. Reps

Abstract

MCVETO (Machine-Code VErification TOol) is a formal verification framework designed to analyze safety properties of stripped machine code. Unlike traditional tools that rely on source code or metadata, MCVETO utilizes Directed Proof Generation (DPG) to handle the complexities of low-level binaries, including self-modifying code and instruction aliasing. By combining concrete execution traces with abstract graph refinement, the tool can either prove a program's safety or identify concrete exploits.

The Challenge of Machine-Code Analysis

Most software verification tools operate on high-level source code (e.g., C or Java). However, the compilation and optimization process can introduce behaviors not present at the source level. Furthermore, security analysts often deal with "stripped" binaries—executables lacking symbol tables, type information, or debugging data.

Machine code presents a "Wild West" for formal analysis due to several factors:

  1. Flat Memory Model: There is no inherent distinction between local variables, heap objects, and return addresses.
  2. Code-Data Ambiguity: Instructions can be modified at runtime (self-modifying code), and data can be executed as code.
  3. Instruction Aliasing: In variable-length architectures like x86, execution can potentially start in the middle of an existing instruction.

Existing tools often make unsound assumptions, such as assuming pointers never overwrite return addresses. MCVETO aims to provide a sound framework that explicitly models these low-level realities.

Methods: Directed Proof Generation

MCVETO employs Directed Proof Generation (DPG), a technique that maintains two concurrent views of a program:

  • Underapproximation: A set of concrete execution traces representing actual program runs.
  • Overapproximation: An abstract graph, represented as a Nested Word Automaton (NWA), which encompasses all possible program behaviors.
Source code (a) and its corresponding control-flow graph (b) used for analysis.

As shown in the figure above, MCVETO maps program logic into a graph-based representation. The tool disassembles instructions one-by-one during state-space exploration rather than upfront. This "trace-based disassembly" allows it to handle indirect jumps and self-modifying code naturally.

Key Innovations

  • Trace Generalization: When a concrete trace is identified, MCVETO "folds" it into a generalized NWA. By intersecting this with the abstract graph, it can eliminate entire families of infeasible paths without requiring expensive SMT solver calls for every individual step.
  • Speculative Refinement: The tool uses dataflow analysis to "guess" potential loop invariants. These guesses are incorporated into the abstract graph to determine if they help prove the safety property.
  • Architecture Independence: The core engine uses a Transformer Specification Language (TSL) to define instruction semantics, making it easy to retarget the tool from x86 to other architectures like PowerPC.
The refinement process in DPG, illustrating how the tool narrows down the search space for target states.

Soundness and Safety Properties

MCVETO explicitly models the possibility of return-address hijacking. It defines "Acceptable Executions" (AE) as those where the stack remains intact. The DPG loop is then used to find violations of this behavior, such as stack smashing. By using NWAs, the tool precisely models the call-and-return structure of programs while remaining closed under intersection—a property vital for the refinement process illustrated above.

Evaluation and Results

The authors evaluated MCVETO on a suite of 28 test cases, including standard benchmarks (SLAM, NECLA), multi-procedure tests (SYNERGY), and machine-code-specific challenges involving instruction aliasing and self-modifying code (SMC).

  • Versatility: MCVETO successfully found proofs of safety or concrete counterexamples for the majority of the test suite.
  • SMC Handling: It is among the first model checkers capable of verifying self-modifying code, verifying an SMC reachability test in under one second.
  • Bug Discovery: The tool identified a stack-smashing vulnerability in a clobbered return address test case in approximately 2 seconds.

Limitations and Future Work

While effective, the "cost of soundness" at the machine level is high. Several larger benchmarks timed out after 20 minutes due to state explosion in complex loops and deep recursion. Future research may explore exploiting the "well-behavedness" of standard compiler-generated code to accelerate analysis without sacrificing the ability to detect malicious, "malbehaved" code.

Summary updated

BibTeX
@inproceedings{thakur2010directed,
  author = {Aditya V. Thakur and Junghee Lim and Akash Lal and Amanda Burton and Evan Driscoll and Matt Elder and Tycho Andersen and Thomas W. Reps},
  title = {{Directed Proof Generation for Machine Code}},
  booktitle = {CAV},
  year = {2010},
  doi = {10.1007/978-3-642-14295-6\_27},
}
Figure