Compilation and optimization with security annotations Son Tuan Vu - - PowerPoint PPT Presentation

compilation and optimization with security annotations
SMART_READER_LITE
LIVE PREVIEW

Compilation and optimization with security annotations Son Tuan Vu - - PowerPoint PPT Presentation

Compilation and optimization with security annotations Son Tuan Vu Advisors: Karine Heydemann, Arnaud de Grandmaison, Albert Cohen Team Alsoc Laboratoire dInformatique de Paris 6 08 April 2019 Son Tuan Vu (LIP6) EuroLLVM 2019 08 April


slide-1
SLIDE 1

Compilation and optimization with security annotations

Son Tuan Vu

Advisors: Karine Heydemann, Arnaud de Grandmaison, Albert Cohen

Team Alsoc Laboratoire d’Informatique de Paris 6

08 April 2019

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 1 / 34

slide-2
SLIDE 2

Outline

1

Introduction

2

Proposed solutions

3

Conclusion

4

References

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

slide-3
SLIDE 3

Background and motivation

Annotations = program properties + extra information Applied to security, safety, real-time, optimization

Expressing program properties Providing extra information

Annotations Safety Security

Performance

  • Program functional

analysis

  • Code optimization
  • WCET analysis
  • Side-channel

attacks analysis

  • Fault attacks

analysis

  • Automatic code

hardening

  • ...

Annotations are consumed by program analysis or transformation Source level to binary level

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 3 / 34

slide-4
SLIDE 4

Related work

Annotation languages

GNU attributes, Microsoft’s SAL, JML for Java, ACSL for C, etc. At source-level

⇒ No annotation language covers the wide range of security properties Other usages than specifying program behaviors

Augment compiler optimizations [NZ13] Automatic code hardening at compilation time [Hil14] Flow information for Worst-Case Execution Time (WCET) analysis at binary level [SCG+18]

⇒ No compiler propagating annotations until the binary other than WCET-aware compilers

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 4 / 34

slide-5
SLIDE 5

Examples of properties: authentication code [DPP+16]

int verifyPIN(char *cardPin , char *userPin , int *cnt) { int i; int diff; if (* cnt > 0) { diff = 0; // Comparison loop for (i = 0; i < PIN_SIZE; i++) if (userPin[i] != cardPin[i]) diff = 1; // Loop protection against fault attacks if (i != PIN_SIZE) return BOOL_FALSE; if (diff == 0) { // PIN codes match *cnt = MAX_ATTEMPT ; return BOOL_TRUE; } else { // PIN codes differ (* cnt)--; return BOOL_FALSE; } } return BOOL_FALSE; } Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 5 / 34

slide-6
SLIDE 6

Examples of properties: authentication code [DPP+16]

int verifyPIN(char *cardPin , char *userPin , int *cnt) { int i; int diff; if (* cnt > 0) { diff = 0; // Comparison loop for (i = 0; i < PIN_SIZE; i++) if (userPin[i] != cardPin[i]) diff = 1; // Loop protection against fault attacks if (i != PIN_SIZE) return BOOL_FALSE; if (diff == 0) { // PIN codes match *cnt = MAX_ATTEMPT ; return BOOL_TRUE; } else { // PIN codes differ (* cnt)--; return BOOL_FALSE; } } return BOOL_FALSE; }

Functional property: verifyPIN returns BOOL_TRUE only when PIN codes match

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 5 / 34

slide-7
SLIDE 7

Examples of properties: authentication code [DPP+16]

int verifyPIN(char *cardPin , char *userPin , int *cnt) { int i; int diff; if (* cnt > 0) { diff = 0; // Comparison loop for (i = 0; i < PIN_SIZE; i++) if (userPin[i] != cardPin[i]) diff = 1; // Loop protection against fault attacks if (i != PIN_SIZE) return BOOL_FALSE; if (diff == 0) { // PIN codes match *cnt = MAX_ATTEMPT ; return BOOL_TRUE; } else { // PIN codes differ (* cnt)--; return BOOL_FALSE; } } return BOOL_FALSE; }

Non-functional property: Card PIN code must be kept secret

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 5 / 34

slide-8
SLIDE 8

Examples of properties: authentication code [DPP+16]

int verifyPIN(char *cardPin , char *userPin , int *cnt) { int i; int diff; if (* cnt > 0) { diff = 0; /* ********* Comparison loop ********* */ for (i = 0; i < PIN_SIZE; i++) if (userPin[i] != cardPin[i]) diff = 1; // Loop protection against fault attacks if (i != PIN_SIZE) return BOOL_FALSE; if (diff == 0) { // PIN codes match *cnt = MAX_ATTEMPT ; return BOOL_TRUE; } else { // PIN codes differ (* cnt)--; return BOOL_FALSE; } } return BOOL_FALSE; }

Non-functional property: Comparison loop must be executed exactly PIN_SIZE times

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 5 / 34

slide-9
SLIDE 9

Examples of properties: authentication code [DPP+16]

int verifyPIN(char *cardPin , char *userPin , int *cnt) { int i; int diff; if (* cnt > 0) { diff = 0; // Comparison loop for (i = 0; i < PIN_SIZE; i++) if (userPin[i] != cardPin[i]) diff = 1; /* ********* Loop protection against fault attacks ********* */ if (i != PIN_SIZE) return BOOL_FALSE; if (diff == 0) { // PIN codes match *cnt = MAX_ATTEMPT ; return BOOL_TRUE; } else { // PIN codes differ (* cnt)--; return BOOL_FALSE; } } return BOOL_FALSE; }

Non-functional property: Loop protection should not be removed by compiler optimizations

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 5 / 34

slide-10
SLIDE 10

Problem statement

(1) Annotated source code (3) Binary + Annotations Source code analysis tool Binary analysis tool (2) Compiler

1 A source-level annotation language to express a wide range of

properties

2 An annotation-aware, optimizing, LLVM-based compilation framework

which consumes/produces/propagates annotations

3 A binary-level representation for the source-level annotation language Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 6 / 34

slide-11
SLIDE 11

Outline

1

Introduction

2

Proposed solutions Source-level annotation language Binary-level representation of the annotation language Annotations in LLVM: representation and propagation

3

Conclusion

4

References

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 7 / 34

slide-12
SLIDE 12

Outline

1

Introduction

2

Proposed solutions Source-level annotation language Binary-level representation of the annotation language Annotations in LLVM: representation and propagation

3

Conclusion

4

References

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 8 / 34

slide-13
SLIDE 13

Annotation language by example: functional properties

ACSL already allows specifying program functional properties verifyPIN returns BOOL_TRUE only when PIN codes match

#define ANNOT(s) __attribute__ (( annotate(s))) // Function annotation ANNOT("\\ ensures \\ result == BOOL_TRUE &&" " \\ forall i; 0 <= i < PIN_SIZE: userPin[i] == cardPin[i];" "\\ ensures \\ result == BOOL_FALSE &&" " \\ exists i; 0 <= i < PIN_SIZE: userPin[i] != cardPin[i];") int verifyPIN(char *cardPin , char *userPin , int *cnt) { ... } Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 9 / 34

slide-14
SLIDE 14

Annotation language by example: non-functional properties

Introduce semantic predicates to specify non-functional properties Card PIN code must be kept secret

#define ANNOT(s) __attribute__ (( annotate(s))) // Variable annotation int verifyPIN(ANNOT("\\ invariant \\ secret ()") char *cardPin , char *userPin , int *cnt) { ... } Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 10 / 34

slide-15
SLIDE 15

Annotation language by example: non-functional properties

Introduce semantic predicates to specify non-functional properties Loop protection does not get removed

#define ANNOT(s) __attribute__ (( annotate(s))) int verifyPIN(char *cardPin , char *userPin , int *cnt) { int i; int diff; if (* cnt > 0) { diff = 0; for (i = 0; i < PIN_SIZE; i++) if (userPin[i] != cardPin[i]) diff = 1; // Statement annotation prop1: ANNOT("\\ ensures \\ sensitive ();") if (i != PIN_SIZE) return BOOL_FALSE; if (diff == 0) { *cnt = MAX_ATTEMPT ; return BOOL_TRUE; } else { (* cnt)--; return BOOL_FALSE; } } return BOOL_FALSE; } Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 11 / 34

slide-16
SLIDE 16

Annotation language by example: side-effect properties

Introduce semantic variables to capture side-effects of the code Comparison loop must be executed exactly PIN_SIZE times

#define ANNOT(s) __attribute__ (( annotate(s))) int verifyPIN(char *cardPin , char *userPin , int *cnt) { int i; int diff; if (* cnt > 0) { diff = 0; // Statement annotation prop1: ANNOT("\\ ensures \\ count () == PIN_SIZE;") for (i = 0; i < PIN_SIZE; i++) if (userPin[i] != cardPin[i]) diff = 1; if (i != PIN_SIZE) return BOOL_FALSE; if (diff == 0) { *cnt = MAX_ATTEMPT ; return BOOL_TRUE; } else { (* cnt)--; return BOOL_FALSE; } } return BOOL_FALSE; } Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 12 / 34

slide-17
SLIDE 17

Annotation language summary

Annotation = Annotated Entity ∧ Predicate ∧ Predicate Variables Annotated Entity = Function ∨ Variable ∨ Statement Predicate = Logic Predicate ∨ Semantic Predicate Predicate Variable = Variable Referenced in Predicate

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 13 / 34

slide-18
SLIDE 18

Outline

1

Introduction

2

Proposed solutions Source-level annotation language Binary-level representation of the annotation language Annotations in LLVM: representation and propagation

3

Conclusion

4

References

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 14 / 34

slide-19
SLIDE 19

Extending DWARF debugging format

Executable program = tree of Debugging Information Entries (DIEs) DIE = tag + attribute(s) + child DIEs (if any) Introduce new tags and attributes to represent annotations and semantic variables

Annotation "argc == 3" Parameter "argc" Subprogram "main" Annotated entity

Function annotation

Annotation "count == 10" 0xA0 ... 0xAB Semantic Variable "count"

Statement annotation

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 15 / 34

slide-20
SLIDE 20

Outline

1

Introduction

2

Proposed solutions Source-level annotation language Binary-level representation of the annotation language Annotations in LLVM: representation and propagation

3

Conclusion

4

References

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 16 / 34

slide-21
SLIDE 21

Annotation representation in LLVM

C source code Front-end LLVM IR Middle-end Object file + DWARF Optimized LLVM IR Back-end

Existing metadata mechanism to convey extra information about the code Debug info: only metadata preserved and emitted into the binary ⇒ used to represent function and variable annotations

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 17 / 34

slide-22
SLIDE 22

Annotation representation in LLVM

C source code Front-end LLVM IR Middle-end Object file + DWARF Optimized LLVM IR Back-end

Existing metadata mechanism to convey extra information about the code Debug info: only metadata preserved and emitted into the binary ⇒ used to represent function and variable annotations Debug info: does have representation for source statements, but too painful to maintain ⇒ annotation markers (≈ memory fences) to delimit the region corresponding to an annotated statement

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 17 / 34

slide-23
SLIDE 23

Annotation representation in LLVM

C source code Front-end LLVM IR Middle-end Object file + DWARF Optimized LLVM IR Back-end

Existing metadata mechanism to convey extra information about the code Debug info: only metadata preserved and emitted into the binary ⇒ used to represent function and variable annotations Debug info: does have representation for source statements, but too painful to maintain ⇒ annotation markers (≈ memory fences) to delimit the region corresponding to an annotated statement ⇒ inspired by lifetime markers: all instructions from a start marker to a corresponding end marker are annotated

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 17 / 34

slide-24
SLIDE 24

Annotation representation in LLVM: function and variable

Function + variable annotation metadata predicate reference to debug info metadata for the annotated entity reference to debug info metadata for the predicate variables (if any) Emitted by clang Propagated and emitted to the binary using the same mechanism as debug info metadata

DIAnnotation "argc == 3" DISubprogram "main" DILocalVariable "argc" referenced variable annotated entity Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 18 / 34

slide-25
SLIDE 25

Annotation representation in LLVM: statement

Statement annotation metadata predicate reference to debug info metadata for the predicate variables (if any) Emitted by clang Propagated and emitted to the binary using the same mechanism as debug info metadata

DIAnnotation "count == 10" NULL GenericDINode "count" annotated entity referenced variable Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 19 / 34

slide-26
SLIDE 26

Annotation representation in LLVM: statement

Statement annotation metadata predicate reference to debug info metadata for the predicate variables (if any) Emitted by clang Propagated and emitted to the binary using the same mechanism as debug info metadata Embedded in the annotation markers

DIAnnotation "count == 10" NULL GenericDINode "count" Annotation markers annotated entity referenced variable Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 19 / 34

slide-27
SLIDE 27

Annotation propagation in LLVM: challenge

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Goal: preserving

1 the annotated entity 2 the predicate variables 3 the annotation metadata itself Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 20 / 34

slide-28
SLIDE 28

Annotation propagation in LLVM: challenge

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Goal: preserving

1 the annotated entity

⇒ maintain correct debug info for variable and function annotations

2 the predicate variables 3 the annotation metadata itself Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 20 / 34

slide-29
SLIDE 29

Annotation propagation in LLVM: challenge

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Goal: preserving

1 the annotated entity

⇒ maintain correct debug info for variable and function annotations ⇒ maintain correct annotated region for statement annotations

2 the predicate variables 3 the annotation metadata itself Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 20 / 34

slide-30
SLIDE 30

Annotation propagation in LLVM: challenge

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Goal: preserving

1 the annotated entity

⇒ maintain correct debug info for variable and function annotations ⇒ maintain correct annotated region for statement annotations

2 the predicate variables

⇒ maintain correct debug info for these variables

3 the annotation metadata itself Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 20 / 34

slide-31
SLIDE 31

Annotation propagation in LLVM: challenge

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Goal: preserving

1 the annotated entity

⇒ maintain correct debug info for variable and function annotations ⇒ maintain correct annotated region for statement annotations

2 the predicate variables

⇒ maintain correct debug info for these variables

3 the annotation metadata itself

⇒ annotation metadata is kept aside from the code and does not interact with optimizations

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 20 / 34

slide-32
SLIDE 32

Annotation propagation in LLVM: problems

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Two different types of problems:

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 21 / 34

slide-33
SLIDE 33

Annotation propagation in LLVM: problems

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation

Maintaining debug info = best-effort, no guarantee Implementation bugs Our biggest hurdle: correct location ranges for auto variables

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 21 / 34

slide-34
SLIDE 34

Annotation propagation in LLVM: problems

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation

Maintaining debug info = best-effort, no guarantee Implementation bugs Our biggest hurdle: correct location ranges for auto variables ⇒ analysis on the generated binary to recover the information

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 21 / 34

slide-35
SLIDE 35

Annotation propagation in LLVM: problems

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation

Maintaining debug info = best-effort, no guarantee Implementation bugs Our biggest hurdle: correct location ranges for auto variables ⇒ analysis on the generated binary to recover the information ⇒ assume that debug info is correct for now

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 21 / 34

slide-36
SLIDE 36

Annotation propagation in LLVM: problems

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation 2 Statement annotation propagation

Annotated instructions removed Annotated instructions merged with not annotated ones, or with ones annotated with a different annotation

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 21 / 34

slide-37
SLIDE 37

Annotation propagation in LLVM: problems

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation 2 Statement annotation propagation

Annotated instructions removed Annotated instructions merged with not annotated ones, or with ones annotated with a different annotation

⇒ How to preserve an annotated region?

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 21 / 34

slide-38
SLIDE 38

Annotation propagation in LLVM: problems

C source code Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation 2 Statement annotation propagation

Annotated instructions removed Annotated instructions merged with not annotated ones, or with ones annotated with a different annotation

⇒ How to preserve an annotated region? ⇒ What does "preserving an annotated region" even mean?

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 21 / 34

slide-39
SLIDE 39

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)

2 Optimization conditions for the annotated region Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 22 / 34

slide-40
SLIDE 40

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)

no external instructions should get into the region no annotated instructions should get out of the region

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 22 / 34

slide-41
SLIDE 41

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)

no external instructions should get into the region no annotated instructions should get out of the region

⇒ annotation markers only guarantee for memory accesses and instructions with side-effects What about constants, registers, instructions without side-effects?

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 22 / 34

slide-42
SLIDE 42

Statement annotation propagation in LLVM: SSA barriers

annotation end annotation start annotation end %a = load %b = use %a %c = use %b %d = use %a %e = use i32 3 Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 23 / 34

slide-43
SLIDE 43

Statement annotation propagation in LLVM: SSA barriers

annotation end annotation start annotation end %a = load %b = use %a %c = use %b1 %d = use %a %b1 = annotation_use %b %e = use i32 3

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 23 / 34

slide-44
SLIDE 44

Statement annotation propagation in LLVM: SSA barriers

annotation end annotation start annotation end %a = load %b = use %a %c = use %b2 %d = use %a1 %b2 = annotation_use %b1 %a1 = annotation_use %a %3 = annotation_use i32 3 %e = use %3 %b1 = annotation_use %b

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 23 / 34

slide-45
SLIDE 45

Statement annotation propagation in LLVM: SSA barriers

annotation end annotation start annotation end %a = load %b = use %a %b1 = annotation_use %b %b2 = annotation_use %b1 %a1 = annotation_use %a %3 = annotation_use i32 3 %c = use %b2 %d = use %a1 %e = use %3

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 23 / 34

slide-46
SLIDE 46

Annotation propagation in LLVM: complete flow

Current implementation

Middle-end Object file + DWARF + Annotation DIE Optimized LLVM IR + Annotation Metadata Back-end LLVM IR + Annotation Metadata Front-end Annotated C source code

Annotation metadata + annotation markers emission

  • SSA barriers emission
  • Annotation markers + SSA barriers

= intrinsics with side-effects

  • Annotation markers = pseudo-instructions with side-effects,

used to compute address ranges for annotated statement

  • SSA barriers = pseudo-instructions with side-effects,

constrained to have same source and destination register

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 24 / 34

slide-47
SLIDE 47

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature) ⇒ guaranteed by annotation markers + SSA barriers

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 25 / 34

slide-48
SLIDE 48

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature) ⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated region

Default to the same level as other regions

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 25 / 34

slide-49
SLIDE 49

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature) ⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated region

Default to the same level as other regions Can be controlled by additional, annotation-specific constraints on the

  • ptimizations allowed within the annotated region

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 25 / 34

slide-50
SLIDE 50

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature) ⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated region

Default to the same level as other regions Can be controlled by additional, annotation-specific constraints on the

  • ptimizations allowed within the annotated region

no optimization

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 25 / 34

slide-51
SLIDE 51

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature) ⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated region

Default to the same level as other regions Can be controlled by additional, annotation-specific constraints on the

  • ptimizations allowed within the annotated region

no optimization less optimizing than the default level

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 25 / 34

slide-52
SLIDE 52

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature) ⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated region

Default to the same level as other regions Can be controlled by additional, annotation-specific constraints on the

  • ptimizations allowed within the annotated region

no optimization ⇒ guaranteed by inserting SSA barriers inside the annotated region less optimizing than the default level

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 25 / 34

slide-53
SLIDE 53

Statement annotation propagation in LLVM: correctness

An annotated region is preserved

1 Isolation conditions (can be relaxed, depending on the annotation’s

nature) ⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated region

Default to the same level as other regions Can be controlled by additional, annotation-specific constraints on the

  • ptimizations allowed within the annotated region

no optimization ⇒ guaranteed by inserting SSA barriers inside the annotated region less optimizing than the default level

⇒ ideal solution: per-region optimization mechanism

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 25 / 34

slide-54
SLIDE 54

Validation: methodology

1 Annotating the source code 2 Compiling at LLVM -O2 3 Verifying manually in the binary Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 26 / 34

slide-55
SLIDE 55

Validation: methodology

1 Annotating the source code 2 Compiling at LLVM -O2 3 Verifying manually in the binary

DWARF section

Correct annotation DIE

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 26 / 34

slide-56
SLIDE 56

Validation: methodology

1 Annotating the source code 2 Compiling at LLVM -O2 3 Verifying manually in the binary

DWARF section

Correct annotation DIE Correct debug info for annotated function or variable

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 26 / 34

slide-57
SLIDE 57

Validation: methodology

1 Annotating the source code 2 Compiling at LLVM -O2 3 Verifying manually in the binary

DWARF section

Correct annotation DIE Correct debug info for annotated function or variable Correct debug info for predicate variables

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 26 / 34

slide-58
SLIDE 58

Validation: methodology

1 Annotating the source code 2 Compiling at LLVM -O2 3 Verifying manually in the binary

DWARF section

Correct annotation DIE Correct debug info for annotated function or variable Correct debug info for predicate variables

.text section: code generated for the annotated statement (respecting isolation + optimization conditions)

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 26 / 34

slide-59
SLIDE 59

Validation: benchmarks and results

Applications tested + annotations considered

VerifyPIN without protection: function behavior VerifyPIN + Control Flow Integrity protection [LHB14]: protection VerifyPIN + loop protection [Wit]: protection First-order masked AES [HOM06]: secret + masked variables RSA [DPP+16]: random functions and variables SHA [GRE+01]: random functions and variables

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 27 / 34

slide-60
SLIDE 60

Validation: benchmarks and results

Applications tested + annotations considered

VerifyPIN without protection: function behavior VerifyPIN + Control Flow Integrity protection [LHB14]: protection VerifyPIN + loop protection [Wit]: protection First-order masked AES [HOM06]: secret + masked variables RSA [DPP+16]: random functions and variables SHA [GRE+01]: random functions and variables

Results

annotations found in DWARF section BUT auto variable location ranges might be erroneous ⇒ patch submitted to fix the bug protections preserved in machine code

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 27 / 34

slide-61
SLIDE 61

Validation: preserving the protection

Protection inserted at source level might be removed by optimizations Traditionally, 2 solutions to preserve the protections:

Compiling without optimization (-O0) Using fragile programming tricks (e.g. volatile)

Preliminary comparison: simulated for ARM Cortex-M3

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 28 / 34

slide-62
SLIDE 62

Validation: preserving the protection

Protection inserted at source level might be removed by optimizations Traditionally, 2 solutions to preserve the protections:

Compiling without optimization (-O0) Using fragile programming tricks (e.g. volatile)

Preliminary comparison: simulated for ARM Cortex-M3

VerifyPIN + loop protection VerifyPIN + CFI protection Protection

  • Exec. instr.

Protection

  • Exec. instr.

O0 ✓ 126 ✓ 1299 O2 + volatile ✓ 89 ✓ 890 O2 + annotation ✓ 62 ✓ 629 O2 ✗ 24 ✗ 130 SSA barriers preserve the protections and region isolation while enabling heavy optimizations (-O2)

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 28 / 34

slide-63
SLIDE 63

Outline

1

Introduction

2

Proposed solutions

3

Conclusion

4

References

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 29 / 34

slide-64
SLIDE 64

Conclusion

(1) Annotated source code (3) Binary + Annotations Source code analysis tool Binary analysis tool (2) Compiler

1 ACSL-based source-level annotation language for wide range of

properties

2 Mechanisms towards annotation-aware compilation framework 3 DWARF extension for binary-level annotation representation Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 30 / 34

slide-65
SLIDE 65

Perspectives

Evaluation of the annotation propagation impact on the compiler and the generated executable performance Automatic process to validate annotation correctness Per-region fine-grained optimization control

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 31 / 34

slide-66
SLIDE 66

Perspectives

Evaluation of the annotation propagation impact on the compiler and the generated executable performance Automatic process to validate annotation correctness Per-region fine-grained optimization control PhD graduation

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 31 / 34

slide-67
SLIDE 67

Outline

1

Introduction

2

Proposed solutions

3

Conclusion

4

References

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 32 / 34

slide-68
SLIDE 68

References I

Louis Dureuil, Guillaume Petiot, Marie-Laure Potet, Thanh-Ha Le, Aude Crohen, and Philippe de Choudens. Fissc: A fault injection and simulation secure collection. pages 3–11, 09 2016.

  • M. R. Guthaus, J. S. Ringenberg, D. Ernst, T. M. Austin, T. Mudge, and R. B. Brown.

Mibench: A free, commercially representative embedded benchmark suite. In Proceedings of the Workload Characterization, 2001. WWC-4. 2001 IEEE International Workshop, WWC ’01, pages 3–14, Washington, DC, USA, 2001. IEEE Computer Society. Christoph Hillebold. Compiler-assisted integrits against fault injection attacks. Master’s thesis, University of Technology, Graz, December 2014. Christoph Herbst, Elisabeth Oswald, and Stefan Mangard. An aes smart card implementation resistant to power analysis attacks. In Proceedings of the 4th International Conference on Applied Cryptography and Network Security, ACNS’06, pages 239–252, Berlin, Heidelberg, 2006. Springer-Verlag.

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 33 / 34

slide-69
SLIDE 69

References II

Jean-François Lalande, Karine Heydemann, and Pascal Berthomé. Software countermeasures for control flow integrity of smart card C codes. In Miroslaw Kutylowski and Jaideep Vaidya, editors, ESORICS - 19th European Symposium

  • n Research in Computer Security, volume 8713 of Lecture Notes in Computer Science,

pages 200–218, Wroclaw, Poland, September 2014. Springer International Publishing. Kedar S. Namjoshi and Lenore D. Zuck. Witnessing program transformations. In Francesco Logozzo and Manuel Fähndrich, editors, Static Analysis, pages 304–323, Berlin, Heidelberg, 2013. Springer Berlin Heidelberg. Bernhard Schommer, Christoph Cullmann, Gernot Gebhard, Xavier Leroy, Michael Schmidt, and Simon Wegener. Embedded Program Annotations for WCET Analysis. In WCET 2018: 18th International Workshop on Worst-Case Execution Time Analysis, volume 63, Barcelona, Spain, July 2018. Dagstuhl Publishing. Marc Witteman. Secure Application Programming in the Presence of Side Channel Attacks. Technical report.

Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 34 / 34