verified translation validation of static analyses
play

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


  1. 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

  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: 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». Behaviors = termination / divergence / undefined («going wrong») 
 + trace of I/O operations performed 2

  3. Our methodology We program the compiler inside Coq. Language Definition compiler (S: program) := ... Compiler Semantics We state its correctness w.r.t. a formal specification of the language semantics. Soundness Proof Theorem compiler_is_correct : ∀ S C, compiler S = OK (C) � safe (S) � 
 Logical «C behaves like S». Framework (here Coq) We interactively and mechanically prove this theorem Proof. ...(* a few months later *) ... Qed. parser.ml compiler.ml pprinter.ml We extract an OCaml implementation of the compiler. Extraction compiler. 3

  4. The formally verified part of the CompCert side-e ff ects out type elimination of expressions loop simplifications Compcert C Clight C#minor Optimizations : constant prop., CSE, tail calls, stack allocation of «&»variables (LCM), (software pipelining) 
 CFG construction instruction expr. decomp. selection RTL CminorSel Cminor (instruction scheduling) register allocation (IRC) spilling, reloading linearization calling conventions of the CFG LTL LTLin Linear layout of stack frames asm code generation ASM Mach 4

  5. Verification patterns (for each compilation pass) Verified transformation Verified translation validation transformation transformation validator = formally verified = not verified 5

  6. Same methodology We program the static analyzer inside Coq. Language Definition analyzer (p: program) := ... Static Analyzer Compiler Semantics We state its correctness w.r.t. a formal specification of the language semantics. Soundness Proof Theorem analyzer_is_sound : ∀ P, analyzer P = Yes � 
 Logical safe(P). Framework (here Coq) We interactively and mechanically prove this theorem Proof. ... (* a few months later *) ... Qed. parser.ml pprinter.ml analyzer.ml We extract an OCaml implementation of the analyzer. Extraction analyzer. 6

  7. The Verasco static analyzer CompCert C Clight C#minor ... CompCert compiler OK/Alarm Abstract interpreter control flow State abstraction states Numerical abstraction integer and floating-point arithmetic Symbolic Congruences Intervals Polyhedra Linearization Octagons equalities Communication channels 7

  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 • Di ffi culty 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

  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. int *x; int *x; int t[3]; int t[3]; /* … */ /* … */ assert (x==t || x==t+1 || x==t+2); y = *x; y = *x; • Relative safety: P 1 is safe under the knowledge that P 2 is safe • An instance of relational verification 9

  10. Methodology Verasco p Verasco Def S p Φ Φ v : [l,h] i; ⇾ assert (l ≤ v && v ≤ h); i; safe S ( p ) safe S ( p Φ ) h · i CompCert CompCert h Φ i [ p ] h Φ i Def T [ p Φ ] safe T ([ p Φ ]) [ p ] safe T ([ p ]) Cosafe T [ p ] | = T h Φ i safe T ([ p ] h Φ i ) 10

  11. Instantiation of the methodology Focus on points-to annotations 
 Each memory access is annotated with an optional set of symbolic pointers. /* 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; Di ffi culty: handling local variables 
 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 …}

  12. Forging pointers: the shadow stack int f(int* z) { int y, *x; /* ... */ /* x � main@t_1[2..4] ∪ main@t_2[6..8] */ y = *x; /* ... */ return …} Di ffi culty: 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).

  13. Example of shadow stack shadow stack int* STK[2048]; stack pointer int CNT = 0; int main(void) { int main_stk[9013]; prologue (push) CNT = CNT+1; STK[CNT] = main_stk; /* ... call to f ... */ epilogue (pop) 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 …}

  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

  15. Use case: cryptographic constant-time points-to Verasco p Verasco defensive p Φ Φ encoder (C#minor) points-to CompCert CompCert translator points-to defensive h Φ i [ p ] h Φ i [ p Φ ] encoder [ p ] (RTL) RTL points-to CompCert relative-safety translator checker Mach constant-time analyzer 15

  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 di ff erential verification Improves a previous security analysis at pre-assembly level 16

  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

  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. . Schneider. Enforceable security policies . ACM Transactions on • F Information and System Security. 2000. . Piessens. Provably correct inline • M. Dam, B. Jacobs, A. Lundblad, F monitoring for multithreaded Java-like programs . Journal of Computer Security, 2010. 18

  19. Questions ? 19

Recommend


More recommend