Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3...

69
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

Transcript of Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3...

Page 1: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Compilation and optimization with security annotations

Son Tuan VuAdvisors: Karine Heydemann, Arnaud de Grandmaison, Albert Cohen

Team AlsocLaboratoire d’Informatique de Paris 6

08 April 2019

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

Page 2: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Outline

1 Introduction

2 Proposed solutions

3 Conclusion

4 References

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

Page 3: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Background and motivation

Annotations = program properties + extra information

Applied to security, safety, real-time, optimization

Expressing programproperties

Providing extrainformation

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 transformationSource level to binary level

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

Page 4: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Related work

Annotation languagesGNU 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 behaviorsAugment compiler optimizations [NZ13]Automatic code hardening at compilation time [Hil14]Flow information for Worst-Case Execution Time (WCET) analysis atbinary level [SCG+18]

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

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

Page 5: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 loopfor (i = 0; i < PIN_SIZE; i++)

if (userPin[i] != cardPin[i])diff = 1;

// Loop protection against fault attacksif (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

Page 6: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 loopfor (i = 0; i < PIN_SIZE; i++)

if (userPin[i] != cardPin[i])diff = 1;

// Loop protection against fault attacksif (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

Page 7: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 loopfor (i = 0; i < PIN_SIZE; i++)

if (userPin[i] != cardPin[i])diff = 1;

// Loop protection against fault attacksif (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

Page 8: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 attacksif (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

Page 9: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 loopfor (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

Page 10: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Problem statement

(1)Annotated

source code

(3)Binary

+Annotations

Source codeanalysis tool

Binary analysistool

(2)Compiler

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

2 An annotation-aware, optimizing, LLVM-based compilation frameworkwhich 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

Page 11: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Outline

1 Introduction

2 Proposed solutionsSource-level annotation languageBinary-level representation of the annotation languageAnnotations in LLVM: representation and propagation

3 Conclusion

4 References

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

Page 12: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Outline

1 Introduction

2 Proposed solutionsSource-level annotation languageBinary-level representation of the annotation languageAnnotations in LLVM: representation and propagation

3 Conclusion

4 References

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

Page 13: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation language by example: functional propertiesACSL already allows specifying program functional properties

verifyPIN returns BOOL_TRUE only when PIN codes match

#define ANNOT(s) __attribute__ (( annotate(s)))

// Function annotationANNOT("\\ 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

Page 14: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation language by example: non-functional propertiesIntroduce semantic predicates to specify non-functional properties

Card PIN code must be kept secret

#define ANNOT(s) __attribute__ (( annotate(s)))

// Variable annotationint verifyPIN(ANNOT("\\ invariant \\ secret ()") char *cardPin ,

char *userPin ,int *cnt) {

...}

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

Page 15: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation language by example: non-functional propertiesIntroduce 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 annotationprop1: 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

Page 16: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation language by example: side-effect propertiesIntroduce 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 annotationprop1: 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

Page 17: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation language summary

Annotation = Annotated Entity ∧ Predicate ∧ Predicate VariablesAnnotated Entity = Function ∨ Variable ∨ StatementPredicate = Logic Predicate ∨ Semantic PredicatePredicate Variable = Variable Referenced in Predicate

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

Page 18: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Outline

1 Introduction

2 Proposed solutionsSource-level annotation languageBinary-level representation of the annotation languageAnnotations in LLVM: representation and propagation

3 Conclusion

4 References

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

Page 19: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 andsemantic variables

Annotation"argc == 3"

Parameter"argc"

Subprogram"main"

Annotatedentity

Function annotation

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

SemanticVariable"count"

Statement annotation

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

Page 20: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Outline

1 Introduction

2 Proposed solutionsSource-level annotation languageBinary-level representation of the annotation languageAnnotations in LLVM: representation and propagation

3 Conclusion

4 References

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

Page 21: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation representation in LLVM

C sourcecode Front-end

LLVM IRMiddle-end

Object file+

DWARF

OptimizedLLVM IR

Back-end

Existing metadata mechanism to convey extra information about thecode

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

Page 22: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation representation in LLVM

C sourcecode Front-end

LLVM IRMiddle-end

Object file+

DWARF

OptimizedLLVM IR

Back-end

Existing metadata mechanism to convey extra information about thecode

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 toopainful to maintain⇒ annotation markers (≈ memory fences) to delimit the regioncorresponding to an annotated statement

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

Page 23: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation representation in LLVM

C sourcecode Front-end

LLVM IRMiddle-end

Object file+

DWARF

OptimizedLLVM IR

Back-end

Existing metadata mechanism to convey extra information about thecode

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 toopainful to maintain⇒ annotation markers (≈ memory fences) to delimit the regioncorresponding to an annotated statement⇒ inspired by lifetime markers: all instructions from a start marker toa corresponding end marker are annotated

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

Page 24: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation representation in LLVM: function and variable

Function + variable annotation metadata

predicate

reference to debug info metadatafor the annotated entity

reference to debug info metadatafor the predicate variables (if any)

Emitted by clang

Propagated and emitted to thebinary using the same mechanismas debug info metadata

DIAnnotation"argc == 3"

DISubprogram"main"

DILocalVariable"argc"

referencedvariable

annotatedentity

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

Page 25: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation representation in LLVM: statement

Statement annotation metadata

predicate

reference to debug info metadatafor the predicate variables (if any)

Emitted by clang

Propagated and emitted to thebinary using the same mechanismas debug info metadata

Embedded in the annotationmarkers

DIAnnotation"count == 10"

NULL

GenericDINode"count"

annotatedentity

referencedvariable

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

Page 26: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation representation in LLVM: statement

Statement annotation metadata

predicate

reference to debug info metadatafor the predicate variables (if any)

Emitted by clang

Propagated and emitted to thebinary using the same mechanismas debug info metadata

Embedded in the annotationmarkers

DIAnnotation"count == 10"

NULL

GenericDINode"count"

Annotationmarkers

annotatedentity

referencedvariable

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

Page 27: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: challenge

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Goal: preserving1 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 notinteract with optimizations

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

Page 28: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: challenge

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Goal: preserving1 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 notinteract with optimizations

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

Page 29: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: challenge

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Goal: preserving1 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 notinteract with optimizations

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

Page 30: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: challenge

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Goal: preserving1 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 notinteract with optimizations

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

Page 31: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: challenge

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Goal: preserving1 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 notinteract with optimizations

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

Page 32: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: problems

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation

2 Statement annotation propagationAnnotated instructions removed

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

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

Page 33: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: problems

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

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

2 Statement annotation propagationAnnotated instructions removed

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

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

Page 34: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: problems

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

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

2 Statement annotation propagationAnnotated instructions removed

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

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

Page 35: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: problems

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

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

2 Statement annotation propagationAnnotated instructions removed

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

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

Page 36: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: problems

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation

2 Statement annotation propagationAnnotated instructions removed

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

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

Page 37: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: problems

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation

2 Statement annotation propagationAnnotated instructions removed

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

⇒ How to preserve an annotated region?

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

Page 38: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: problems

C source code Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Challenge: preserve + propagate annotations

...

Two different types of problems:

1 Debug info propagation

2 Statement annotation propagationAnnotated instructions removed

Annotated instructions merged with not annotated ones, or with onesannotated 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

Page 39: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)2 Optimization conditions for the annotated region

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

⇒ annotation markers only guarantee for memory accesses andinstructions with side-effects

What about constants, registers, instructions without side-effects?

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

Page 40: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)

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

⇒ annotation markers only guarantee for memory accesses andinstructions with side-effects

What about constants, registers, instructions without side-effects?

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

Page 41: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)

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

⇒ annotation markers only guarantee for memory accesses andinstructions with side-effects

What about constants, registers, instructions without side-effects?

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

Page 42: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: SSA barriers

annotationend

annotationstart

annotationend

%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

Page 43: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: SSA barriers

annotationend

annotationstart

annotationend

%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

Page 44: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: SSA barriers

annotationend

annotationstart

annotationend

%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

Page 45: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: SSA barriers

annotationend

annotationstart

annotationend

%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

Page 46: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Annotation propagation in LLVM: complete flow

Current implementation

Middle-end

Object file +DWARF

+Annotation DIE

OptimizedLLVM IR +AnnotationMetadata

Back-end

LLVM IR+

AnnotationMetadata

Front-endAnnotated Csource 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

Page 47: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 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 theoptimizations 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

Page 48: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated regionDefault to the same level as other regions

Can be controlled by additional, annotation-specific constraints on theoptimizations 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

Page 49: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated regionDefault to the same level as other regions

Can be controlled by additional, annotation-specific constraints on theoptimizations 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

Page 50: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated regionDefault to the same level as other regions

Can be controlled by additional, annotation-specific constraints on theoptimizations 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

Page 51: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated regionDefault to the same level as other regions

Can be controlled by additional, annotation-specific constraints on theoptimizations 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

Page 52: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated regionDefault to the same level as other regions

Can be controlled by additional, annotation-specific constraints on theoptimizations 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

Page 53: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Statement annotation propagation in LLVM: correctness

An annotated region is preserved1 Isolation conditions (can be relaxed, depending on the annotation’s

nature)⇒ guaranteed by annotation markers + SSA barriers

2 Optimizations of the annotated regionDefault to the same level as other regions

Can be controlled by additional, annotation-specific constraints on theoptimizations 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

Page 54: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Validation: methodology

1 Annotating the source code2 Compiling at LLVM -O23 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

Page 55: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Validation: methodology

1 Annotating the source code2 Compiling at LLVM -O23 Verifying manually in the binary

DWARF sectionCorrect 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

Page 56: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Validation: methodology

1 Annotating the source code2 Compiling at LLVM -O23 Verifying manually in the binary

DWARF sectionCorrect 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

Page 57: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Validation: methodology

1 Annotating the source code2 Compiling at LLVM -O23 Verifying manually in the binary

DWARF sectionCorrect 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

Page 58: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Validation: methodology

1 Annotating the source code2 Compiling at LLVM -O23 Verifying manually in the binary

DWARF sectionCorrect 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

Page 59: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Validation: benchmarks and results

Applications tested + annotations consideredVerifyPIN 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

Resultsannotations 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

Page 60: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Validation: benchmarks and results

Applications tested + annotations consideredVerifyPIN 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

Resultsannotations 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

Page 61: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 protectionProtection Exec. instr. Protection Exec. instr.

O0 3 126 3 1299O2 + volatile 3 89 3 890O2 + annotation 3 62 3 629

O2 7 24 7 130

SSA barriers preserve the protections and region isolation while enablingheavy optimizations (-O2)

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

Page 62: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 protectionProtection Exec. instr. Protection Exec. instr.

O0 3 126 3 1299O2 + volatile 3 89 3 890O2 + annotation 3 62 3 629

O2 7 24 7 130

SSA barriers preserve the protections and region isolation while enablingheavy optimizations (-O2)

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

Page 63: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Outline

1 Introduction

2 Proposed solutions

3 Conclusion

4 References

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

Page 64: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Conclusion

(1)Annotated

source code

(3)Binary

+Annotations

Source codeanalysis tool

Binary analysistool

(2)Compiler

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

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

Page 65: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Perspectives

Evaluation of the annotation propagation impact on the compiler andthe 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

Page 66: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Perspectives

Evaluation of the annotation propagation impact on the compiler andthe 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

Page 67: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

Outline

1 Introduction

2 Proposed solutions

3 Conclusion

4 References

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

Page 68: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

References I

Louis Dureuil, Guillaume Petiot, Marie-Laure Potet, Thanh-Ha Le, Aude Crohen, andPhilippe 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 InternationalWorkshop, 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 NetworkSecurity, ACNS’06, pages 239–252, Berlin, Heidelberg, 2006. Springer-Verlag.

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

Page 69: Son Tuan Vullvm.org/devmtg/2019-04/slides/SRC-TuanVu...Outline 1 Introduction 2 Proposedsolutions 3 Conclusion 4 References Son Tuan Vu (LIP6) EuroLLVM 2019 08 April 2019 2 / 34

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 Symposiumon 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, MichaelSchmidt, 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