Control Flow Implementation
Control Flow Implementation
Lujo Bauer
18-732
Spring 2015
Control Hijacking Arms Race
Control
Flow
Integrity
Attacks
2
http://propercourse.blogspot.com/2010/05/i-believe-in-duct-tape.html
CFI: Goal
4
CFI: Idea
5
Attack Model
Assumptions:
Data memory is Non-Executable
Code memory is Non-Writable
6
Lecture Outline
CFI: Goal
Background: Control Flow Graph
CFI: Approach
Building on CFI
– IRM, SFI, SMAC, Protected Shadow Call Stack
Formal Study
7
Basic Block
8
CFG Definition
9
Call Graph
Nodes are functions
There is an edge (vi, vj) if function vi calls
function vj
void orange() void red(int x) void green()
{ { {
1. red(1); .. green();
2. red(2); } orange();
3. green(); }
}
10
Super Graph
1 A context sensitive
1: red
2 super‐graph for orange
3 2: red lines 1 and 2
11
Precision
12
Soundness Completeness
If analysis says X is If X is true, then
true, then X is true analysis says X is true
Things I say
True things
True things
Things I say
Context sensitive
distinguishes 2 different
calls to red()
14
Context Sensitive Example
4,5
15
Lecture Outline
CFI: Goal
Background: Control Flow Graph
CFI: Approach
Building on CFI
– IRM, SFI, SMAC, Protected Shadow Call Stack
Formal Study
16
CFI Overview
Method:
Build CFG statically, e.g., at compile time
Instrument (rewrite) binary, e.g., at install time
– Add IDs and ID checks; maintain ID uniqueness
Verify CFI instrumentation at load time
– Direct jump targets, presence of IDs and ID checks, ID uniqueness
Perform ID checks at run time
– Indirect jumps have matching IDs
17
Build CFG
direct calls
indirect calls
Two possible
return sites due to
context insensitivity
18
Instrument Binary
call 17, R: transfer control to R
only when R has label 17
Original code
Instrumented code
20
Verify CFI Instrumentation
22
Security Guarantees
23
Evaluation
24
Evaluation
Security-related experiments
– CFI protects against various specific attacks
(read Section 4.3)
25
Lecture Outline
CFI: Goal
Background: Control Flow Graph
CFI: Approach
Building on CFI
– IRM, SFI, SMAC, Protected Shadow Call Stack
Formal Study
26
SFI
27
SMAC: Generalized SFI
28
Example: CFI + SMAC
29
CFI as a Foundation for
Non-circumventable IRMs
Inlined Reference Monitors (IRM) work
correctly assuming:
– Inserted dynamic checks cannot be circumvented by
changing control flow – enforced using CFI
– IRM state cannot be modified by attacker – enforced
by SMAC
30
CFI with Context Sensitivity
31
Lecture Outline
CFI: Goal
Background: Control Flow Graph
CFI: Approach
Building on CFI
– IRM, SFI, SMAC, Protected Shadow Call Stack
Formal Study
32
Security Proof Outline
Weakness of Abadi et al. work:
Formal study uses a simple RISC‐style assembly
language, not the x86 ISA
(cf. McCamant and Morrisett’s PittSFIeld 2006)
33
Machine Model
Execution State:
34
Operational Semantics
35
Operational Semantics (normal)
: Binary relation on states that expresses normal execution steps
36
Operational Semantics (attacker)
37
Instrumentation Algorithm
Example:
– Every computed jump instruction is preceded by a
particular sequence of instructions, which depends on
a given CFG
Definition of CFG and instrumentation algorithm in paper
38
CFI Security Theorem
Small
Invariant: Trusted
Execution Computing
must Base:
follow a path in a control
flow graph
Trust (CFG)
simple created not
verifier, ahead of run time.
complex rewriter
Method:
Build CFG statically, e.g., at compile time
Instrument (rewrite) binary, e.g., at install time
– Add IDs and ID checks; maintain ID uniqueness
Verify CFI instrumentation at load time
– Direct jump targets, presence of IDs and ID checks, ID
uniqueness
Perform ID checks at run time
– Indirect jumps have matching IDs
40
Connections to Other Lectures
41
Sources
42