Formally Secure Compilation -...

25
Formally Secure Compilation Cătălin Hrițcu Inria Paris 1 https ://secure-compilation.github.io of Unsafe Low-level Components

Transcript of Formally Secure Compilation -...

Page 1: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Formally Secure Compilation

Cătălin Hrițcu

Inria Paris

1

https://secure-compilation.github.io

of Unsafe Low-level Components

Page 2: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Parcurs profesional

• 2001 - 2005 - Infoiași - student la licență

• 2005 - 2011 - Saarland University - MSc & PhD

• 2011 - 2013 - U. of Pennsylvania - PostDoccu Benjamin Pierce, DARPA CRASH/SAFE

• 2013 - acum - Inria Paris - Cercetător

• 2017 - 2021 - ERC Starting Grant SECOMP - PI

• 2017 - 2020 - DARPA SSITH/HOPE - coPI

Page 3: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Computers are insecure

• devastating low-level vulnerabilities

• teasing out 2 important security problems:

1. inherently insecure low-level languages

– memory unsafe: any buffer overflow can be catastrophic allowing remote attackers to gain complete control

2. unsafe interaction with unsafe code

– even code written in safer languageshas to interoperate with unsafe code

– unsafe interaction: safety guarantees lost

3

Page 4: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

How did we get here?

• programming languages, compilers,and hardware architectures

– designed in an era of scarce hardware resources

– too often trade off security for efficiency

• the world has changed (2017 vs 1972*)

– security matters, hardware resources abundant

– time to revisit some tradeoffs

4

* “...the number of UNIX installations has grown to 10, with more expected...”-- Dennis Ritchie and Ken Thompson, June 1972

Page 5: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

tpc’ tm3’

Key enabler: Micro-Policies

5

pc tpc

r0 tr0

r1 tr1

mem[0] tm0

“store r0 r1” tm1

mem[2] tm2

mem[3] tm3

tpc tr0 tr1 tm3 tm1

monitorallow

tpc’ tm3’

tpc

tr0

tr1

tm1

store

software monitor’s decision is hardware cached

software-defined, hardware-accelerated, tag-based monitoring

disallowpolicy violation stopped!

(e.g. out of bounds write)

tm3

tm3≠

tm3

=

Page 6: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

• low level + fine grained: unbounded per-word metadata, checked & propagated on each instruction

• flexible: tags and monitor defined by software

• efficient: software decisions hardware cached

• expressive: complex policies for secure compilation

• secure and simple enough to verify security in Coq

• real: FPGA implementation on top of RISC-V

6

Micro-policies are cool!

Page 7: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

• information flow control (IFC)

• monitor self-protection

• protected compartments

• dynamic sealing

• heap memory safety

• code-data separation

• control-flow integrity (CFI)

• taint tracking

• ...

Expressiveness

7

Verified(in Coq)

Evaluated (<10% runtime overhead)

[Oakland’15]

[POPL’14]

[ASPLOS’15]

Way beyond MPX, SGX, SSM, etc

Page 8: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

• Formal methods & architecture & systems

• Previous: DARPA CRASH/SAFE (2011-2014)

• Current: DARPA SSITH/HOPE (2017-2020)

• PIs:

– Draper Labs: Arun Thomas, Chris Casinghino

– Dover Microsystems: Greg Sullivan

– DornerWorks: Nathan Studer, David Johnson

– UPenn: André DeHon, Benjamin Pierce

– Inria Paris: Cătălin Hrițcu

– Portland State: Andrew Tolmach

– MIT: Howie Shrobe

Micro-Policies Project

8

Page 9: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

ERC SECOMP Grand Challenge

Use micro-policies to build the first efficient formally

secure compilers for realistic programming languages

9

1. Provide secure semantics for low-level languages

– C with protected components and memory safety

2. Enforce secure interoperability with unsafe code

– ASM, C, and Low*

[= safe C subset embedded in F* for verification]

(2017-2021)

Page 10: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Goal: achieving secure compilation at scale

10

miTLS*

CompSec+

KremSec

memory safe C component

protecting component boundaries

legacy C component

CompSec

ASM component

Low* language(safe C subset in F*)

C language+ components+ memory safety

ASM language(RISC-V + micro-policies)

Page 11: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Formally Secure Compilationof Unsafe Low-level Components

Page 12: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Collaborators

CătălinHrițcu

MarcoStronati

ArthurAzevedo

de Amorim

Ana NoraEvans

DeepakGarg Marco

PatrignaniAndrewTolmach

BenjaminPierce

GuglielmoFachini

ThéoLaurent

YannisJuglaretCarmine

Abate

Inria Paris CMU U. Virginia ENS Paris UPenn Portland State MPI-SWS U. Trento

Page 13: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Compartmentalizationfor unsafe, low-level languages

• Add components to C-like language

– interacting only via strictly enforced interfaces

• Secure compilation chain

– use low-level security mechanisms to efficiently enforce:

component separation, call and return discipline, ...

• Interesting attacker model

– mutual distrust, dynamic compromise, least privilege

• e.g. dynamic compromise = "each component should be protected

from all the others until it becomes compromised and starts

attacking the remaining uncompromised components"

Goal: Formalize this

Goal: Build this

13

Page 14: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Formally secure compilation

high-levelattacker

low-levelattacker

source

target

compiler

Benefit: sound security reasoning in the source languageforget about compilation chain (linker, loader, runtime)forget that libraries are written in a lower-level language

secure

secure

program behavior

program behavior

compilercorrectness

(e.g. CompCert)

holy grail of preserving security all the way down

securecompilation

component

component

notenough

no extra powerprotected e.g. arbitrary machine codee.g. compromised C code

e.g. safe C code

Page 15: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Fully abstract compilation

15

high-levelattacker

low-levelattacker

1st high-level component

1st compiledcomponent

high-levelattacker

low-levelattacker

2nd high-level component

2nd compiledcomponent

≁high-levelattacker∃

low-levelattacker∃

.

. ≁

compiler compiler

preservation of observational equivalence

Page 16: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Undefined behavior

#include <string.h>

int main (int argc, char **argv)

{

char c[12];

strcpy(c, argv[1]);

return 0;

}

$ gcc target.c -fno-stack-protector$ ./a.out haha$ ./a.out hahahahahahahahahahazsh: segmentation fault (core dumped)

Buffer overflow

Page 17: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Source reasoning vs undefined behavior

• Source reasoning

= We want to reason formally about securitywith respect to source language semantics

• Undefined behavior

= can't be expressed at all by source language semantics!

• Observational equivalence doesn't work with undefined behavior!?

– int buf[5]; buf[42] ~ int buf[5]; buf[43]?

• Can we somehow avoid undefined behavior?

Page 18: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Full abstractionwith mutually distrustful components

18

i1 i2 i3 i4 i5

C1 C2 C3 C4 C5↓ ↓ ↓ ↓ ↓

i1 i2 i3 i4 i5

C1 A2 C3 A4 A5

∀compromise scenarios.

[Beyond Good and Evil - Juglaret, Hrițcu, et al, CSF’16]

if C1, C3, D1, D3 fully defined and

∃ high-level attack from some fully defined A2, A4, A5

∃ low-level attack from compromised C2↓, C4↓, C5↓

Limitation: static compromise model: C1, C3, D1, D3 get guarantees only if perfectly safe(i.e. fully defined = do not exhibit undefined behavior in any context)

This is the most we were able to achieve for full abstraction!

i1 i2 i3 i4 i5

D1 A2 D3 A4 A5

i1 i2 i3 i4 i5

D1 C2 D3 C4 C5↓ ↓ ↓ ↓ ↓

Page 19: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Static compromise not good enoughneither C1 not C2 are fully defined

yet C1 is protected until calling C1.parse

and C2 can't actually be compromised

Page 20: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

New secure compilation criterion:Robust Compilation

robust trace property preservation(robust = in adversarial context)

intuition:– stronger than compiler correctness

– seems weaker than full abstraction+ compiler correctness

less extensional than full abstraction

20

high-levelattacker

low-levelattacker

high-level component

compiledcomponent

high-levelattackercausing t

low-levelattackercausing t

.

.

compiler

∀(bad, attack) trace t

Advantages: easier to realistically achieve and prove at scaleuseful: preservation of invariants and other integrity propertiesmore intuitive to security people (generalizes to hyperproperties!)extends to unsafe languages (supporting dynamic compromise)

Page 21: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Dynamic compromise

[When Good Components Go Bad - Fachini, Stronati, Hrițcu, et al]

i1 i2 i3

C0 C1 C2

∃ a dynamic compromise scenario explaining t in source languagefor instance ∃[A1,A2] leading to the following compromise sequence:

↓ ↓ ↓ ⇓ t

i1 i2 i3

C0 C1 C2⇓ m1;Undef(C1)

↯(0)

(1)i1 i2 i3

C0 A1 C2⇓ m2;Undef(C2)

(2)i1 i2 i3

C0 A1 A2⇓ t

Trace is very helpful- detect undefined behavior- rewind execution

Page 22: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Now we know what these words mean!

Mutual distrust

Dynamic compromise

Least privilege

C1 A2 C3 A4 A5

C0 A1 C2 ⇓ m2; Undef(C2)↯

i1 i2 i3

C0 A1 C2

(at least in the setting of compartmentalization for unsafe low-level languages)

[When Good Components Go Bad - Fachini, Stronati, Hrițcu, et al]

Page 23: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Simple Secure Compilation Chain

Compartmentalized unsafe source

Compartmentalized abstract machine

Buffers, procedures, componentsinteracting via strictly enforced interfaces

Micro-policy machine

Standardmachine

Simple RISC abstract machine with

build-in compartmentalization

Inline reference monitor enforcing:- component separation- procedure call and return discipline

software fault isolation

Tag-based reference monitor enforcing:- component separation- procedure call and return discipline

Verified(in Coq)

Systematically tested (with QuickChick)

fallback

Page 24: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Beyond trace properties

[Robust Hyperproperty Preservation for Secure Compilation - Garg, Hrițcu, et al]

back-translating contexts∀P∀Ct∃Cs∀t...

back-translatingfinite trace prefixes∀P∀Ct∀t∃Cs...

Legend(Trace) property = set of tracesHyperproperty = set of sets of traces

Page 25: Formally Secure Compilation - Proseccoprosecco.gforge.inria.fr/personal/hritcu/talks/2017-12-18-Secure... · Formally secure compilation high-level attacker low-level attacker source

Compartmentalization mechanisms

• practically deployed ones

– process-level privilege separation (all web browsers)

– software fault isolation (SFI, Google Native Client)

– hardware enclaves (Intel SGX, ARM TrustZone)

• and more on drawing boards:

– WebAssembly (WASM)

– capability machines (CHERI)

– tagged architectures (micro-policies)

25