Control Flow Integrity

Introduction


What is control-flow? transfer? hijack? (1)


What is control-flow? transfer? hijack? (2)


Control transfer instruction protection


Attack model with memory corruption attack

Exploit types Defence mechanism
Code corruption attack Instruction Set Randomize
Control-flow hijack attack ASLR, Control-flow Integrity
Data-only attack Data Integrity, Data-flow Integrity
Information attack Data Space Randomization

Control-flow hijack attack

  1. Modify a code pointer to the address of shellcode/gadget
    • Defense by ASLR
  2. Use pointer by indirect transfer instruction(call/jump or return)
    • Defense by Control-flow Integrity

Attacker tries memory corruption for control-flow hijacking


Control-Flow Integrity


How to enfoce the CFI?

  1. Generate CFG
  2. Enumerate all possible targets
  3. Enforce CFI
  4. Execute a runtime monitor

Before enforcing CFI

void bar(); void baz(); void buz(); void bez(int, int);

void foo(int usr) {
  void (*func)();

  if (usr == MAGIC)
    func = bar;
  else
    func = baz;

  func();
}

After enforcing CFI

void bar(); void baz(); void buz(); void bez(int, int);

void foo(int usr) {
  void (*func)();

  if (usr == MAGIC)
    func = bar;
  else
    func = baz;

  // a) all functions {bar, baz, buz, bez, foo} are allowed
  // b) all functions with prototype "void (*)()" are allowed
  //    i.e., {bar, baz, buz}
  // c) only address taken functions are allowed
  //    i.e., {bar, baz}
  CHECK_CFI_FORWARD(func);
  func();

  // backward edge CFI check
  CHECK_CFI_BACKWARD();
}

Kind of CFI

Forward-edge CFI

Backward-edge CFI


CFI implementations comparison


Enforcing Forward-Edge Control-Flow Integrity in GCC & LLVM (Google 2014)

CFI implementations have been research prototypes . . . Implementations of fine-grained, forward-edge CFI enforcement and analysis for GCC and LLVM.


Think over..


Refereces