Verified translation validation of static analyses Sandrine Blazy - - PowerPoint PPT Presentation

verified translation validation of static analyses
SMART_READER_LITE
LIVE PREVIEW

Verified translation validation of static analyses Sandrine Blazy - - PowerPoint PPT Presentation

Verified translation validation of static analyses Sandrine Blazy joint work with Gilles Barthe, Vincent Laporte, David Pichardie and Alix Trieu IFIP WG 1.9/2.15, Leuven, 2017-05-11 1 Background: verifying a compiler Compiler + proof that the


slide-1
SLIDE 1

Verified translation validation of static analyses

Sandrine Blazy

1

joint work with Gilles Barthe, Vincent Laporte, David Pichardie and Alix Trieu IFIP WG 1.9/2.15, Leuven, 2017-05-11

slide-2
SLIDE 2

Background: verifying a compiler

Compiler + proof that the compiler does not introduce bugs CompCert, a moderately optimizing C compiler usable for critical embedded software

  • Fly-by-wire software, Airbus A380 and A400M, FCGU (3600 files): 


mostly control-command code generated from Scade block diagrams + mini. OS

We prove the following semantic preservation property: Behaviors = termination / divergence / undefined («going wrong») 
 + trace of I/O operations performed For all source programs S and compiler-generated code C, if the compiler generates machine code C from source S, without reporting a compilation error, 
 and S has a safe behavior,
 then «C behaves like S».

2

slide-3
SLIDE 3

Our methodology

We program the compiler inside Coq. Definition compiler (S: program) := ... We state its correctness w.r.t. a formal specification of the language semantics. Theorem compiler_is_correct : ∀ S C, compiler S = OK (C) safe (S) 
 «C behaves like S». We interactively and mechanically prove this theorem

  • Proof. ...(* a few months later *) ...

Qed. We extract an OCaml implementation of the compiler. Extraction compiler.

Logical Framework

(here Coq)

Compiler Language Semantics

parser.ml pprinter.ml compiler.ml

Soundness Proof

3

slide-4
SLIDE 4

The formally verified part of the CompCert

type elimination loop simplifications CFG construction

  • expr. decomp.

spilling, reloading calling conventions

Compcert C Clight C#minor Cminor CminorSel RTL LTL LTLin Linear Mach ASM

side-effects out

  • f expressions

stack allocation

  • f «&»variables

Optimizations: constant prop., CSE, tail calls,

(LCM), (software pipelining)


instruction selection register allocation (IRC) linearization

  • f the CFG

layout of stack frames asm code generation (instruction scheduling)

4

slide-5
SLIDE 5

Verification patterns (for each compilation pass)

5

Verified transformation transformation transformation validator Verified translation validation = formally verified = not verified

slide-6
SLIDE 6

Same methodology

We program the static analyzer inside Coq. Definition analyzer (p: program) := ... We state its correctness w.r.t. a formal specification of the language semantics. Theorem analyzer_is_sound : ∀ P, analyzer P = Yes 
 safe(P). We interactively and mechanically prove this theorem

  • Proof. ... (* a few months later *) ...

Qed. We extract an OCaml implementation of the analyzer. Extraction analyzer.

Logical Framework

(here Coq)

Compiler Language Semantics

parser.ml pprinter.ml

Soundness Proof

6

Static Analyzer

analyzer.ml

slide-7
SLIDE 7

The Verasco static analyzer

7

CompCert compiler ...

states State abstraction control flow Abstract interpreter OK/Alarm

Clight CompCert C C#minor

integer and floating-point arithmetic

Congruences

Intervals

Polyhedra Octagons Symbolic equalities Linearization

Numerical abstraction

Communication channels

slide-8
SLIDE 8

Abstract interpretation of low-level programs ?

  • Abstract interpretation traditionally performed at source level
  • Need for analyzing lower-levels
  • Ex1: compiler optimization (intermediate level)
  • Ex2: security analysis performed at assembly level
  • Difficulty of the analysis (e.g. keeping track of symbolic equalities

between values contained in memory cells - incl. points-to information - and alignment of memory accesses)

  • Our solution: a general and lightweight methodology for carrying the

results of a source analyzer down to lower-level representations

  • 3 use cases: CSE optimization, constant-time analysis, resource

analysis

8

slide-9
SLIDE 9

Our methodology

  • Inlining enforceable properties
  • properties that can be enforced using runtime monitors 


Inlining a monitor yields a defensive form (i.e. a program instrumented with runtime checks)
 Enforcing a program to follow a property amounts to checking that it is safe.

  • Relative safety: P1 is safe under the knowledge that P2 is safe
  • An instance of relational verification

9

int *x; int t[3]; /* … */ y = *x; int *x; int t[3]; /* … */ assert (x==t || x==t+1 || x==t+2); y = *x;

slide-10
SLIDE 10

Methodology

10

p Φ

pΦ [p]hΦi hΦi

DefS DefT

h·i

CosafeT

[pΦ] [p]

[p] | =T hΦi

safeT ([p]) safeS(p)

safeT ([p]hΦi) safeT ([pΦ])

safeS(pΦ)

Verasco Verasco CompCert CompCert

v : [l,h] i; ⇾ assert (l≤v && v≤h); i;

slide-11
SLIDE 11

Instantiation of the methodology

Focus on points-to annotations
 Each memory access is annotated with an optional set of symbolic pointers. Difficulty: handling local variables


/* x t1[2..4] ∪ t2[6..8] */ assert (x==t1+2||x==t1+3||x==t1+4 ||x==t2+6||x==t2+7||x==t2+8); y = *x; int main(void) { int t_1[12], t_2[9001]; ... call to f ... return …} int f(int* z) { int y, *x; /* ... */ /* x main@t_1[2..4] ∪ main@t_2[6..8] */ y = *x; /* ... */ return …}

slide-12
SLIDE 12

Forging pointers: the shadow stack

Difficulty: handling local variables
 Solution: use of a shadow stack

  • We need to compute some concrete pointers that are symbolically given

by the annotations.

  • We make each function leak a pointer to its stack frame into a global

variable (a.k.a. the shadow stack).

int f(int* z) { int y, *x; /* ... */ /* x main@t_1[2..4] ∪ main@t_2[6..8] */ y = *x; /* ... */ return …}

slide-13
SLIDE 13

Example of shadow stack

int* STK[2048]; int CNT = 0; int main(void) { int main_stk[9013]; CNT = CNT+1; STK[CNT] = main_stk; /* ... call to f ... */ CNT = CNT-1; return … } int f(int* z) { int f_stk[2]; CNT = CNT+1; STK[CNT] = f_stk; /* ... */ /* x -1[2..4] ∪ -1[18..20] */ assert(f_stk[1]==STK[CNT-1]+2 || f_stk[1]==STK[CNT-1]+3 || ... ); f_stk[0] = *(f_stk[1]); /* ... */ CNT = CNT-1; return …}

prologue (push) epilogue (pop) stack pointer shadow stack

slide-14
SLIDE 14

Use case: cryptographic constant-time

Constant-time policy: the control flow and sequence of memory accesses of a program do not depend on some of its inputs (tagged as secret). 
 Use of the points-to information from Verasco to keep track of security levels, and exploit this information in an information-flow type system (Mach level)

  • avoid the need to rewrite programs
  • handle larger programs

We were able to automatically prove that programs verify the constant-time policy.
 Benchmarks: mainly PolarSSL and NaCl cryptographic libraries

14

slide-15
SLIDE 15

Use case: cryptographic constant-time

15

p Φ

pΦ [p]hΦi hΦi [pΦ] [p] Verasco Verasco CompCert CompCert

RTL relative-safety checker

points-to defensive encoder (C#minor) points-to defensive encoder (RTL) points-to translator

CompCert

points-to translator Mach constant-time analyzer

slide-16
SLIDE 16

Conclusion

Lightweight approach to formally verify translation of static analysis results (lowering of points-to annotations) in a formally verified compiler Two main ingredients: inlining enforceable properties and differential verification Improves a previous security analysis at pre-assembly level

16

slide-17
SLIDE 17

Future work

Improve Verasco to perform a very precise taint analysis

  • Relies on a tainted semantics
  • Encouraging results on a representative benchmark
  • Main theorem: any safe program w.r.t. the tainted semantics is constant

time (paper proof) Add obfuscation transformations and check that they do not introduce side- channels

17

slide-18
SLIDE 18

References

  • G. Barthe, S. Blazy, V. Laporte, D. Pichardie, A. Trieu. Verified translation

validation of static analyses. Computer Security Foundations Symposium (CSF), 2017.

  • S. Blazy, V. Laporte, D. Pichardie. An abstract memory functor for verified

C static analyzers. ICFP 2016.

  • J.H. Jourdan, V. Laporte, S. Blazy, X. Leroy, D. Pichardie. A formally-verified

static analyzer. POPL 2015.

  • G. Barthe, G.Bertate, J.D.Campo, C.Luna, D. Pichardie. System-level non-

interference for constant-time cryptography. Conference on Computer and Communications Security (CCS), 2014.

  • F

. Schneider. Enforceable security policies. ACM Transactions on Information and System Security. 2000.

  • M. Dam, B. Jacobs, A. Lundblad, F

. Piessens. Provably correct inline monitoring for multithreaded Java-like programs. Journal of Computer Security, 2010.

18

slide-19
SLIDE 19

Questions ?

19