82
Lecture : What is Secure Compilation? Secure Compilation Seminar Marco Patrignani

Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Lecture 1: What is SecureCompilation?

Secure Compilation Seminar

Marco Patrignani

1

Page 2: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

What is a Compiler

https://en.wikipedia.org/wiki/Compiler

In this course:

• only care about the code generation phase• takes programs written in asource language S

• output programs written in atarget language T

• it is a function from S to T: J⋅KST

2

Page 3: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

What is a Compiler

https://en.wikipedia.org/wiki/Compiler

In this course:

• only care about the code generation phase• takes programs written in asource language S

• output programs written in atarget language T

• it is a function from S to T: J⋅KST

2

Page 4: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

What is a Compiler

https://en.wikipedia.org/wiki/Compiler

In this course:

• only care about the code generation phase

• takes programs written in asource language S

• output programs written in atarget language T

• it is a function from S to T: J⋅KST

2

Page 5: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

What is a Compiler

https://en.wikipedia.org/wiki/Compiler

In this course:

• only care about the code generation phase• takes programs written in asource language S

• output programs written in atarget language T

• it is a function from S to T: J⋅KST

2

Page 6: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

What is a Compiler

https://en.wikipedia.org/wiki/Compiler

In this course:

• only care about the code generation phase• takes programs written in asource language S

• output programs written in atarget language T

• it is a function from S to T: J⋅KST

2

Page 7: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

What is a Compiler

https://en.wikipedia.org/wiki/Compiler

In this course:

• only care about the code generation phase• takes programs written in asource language S

• output programs written in atarget language T

• it is a function from S to T: J⋅KST2

Page 8: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #1: Insecure Compilation1 public class Account2 private int balance = 0;3

4 public void deposit( int amount )5 this.balance += amount;

No access to balance from outsideAccount

enforced by the language

Javasourc

e

3

Page 9: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #1: Insecure Compilation1 public class Account2 private int balance = 0;3

4 public void deposit( int amount )5 this.balance += amount;

No access to balance from outsideAccount

enforced by the language

Javasourc

e

3

Page 10: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #1: Insecure Compilation1 public class Account2 private int balance = 0;3

4 public void deposit( int amount )5 this.balance += amount;

No access to balance from outsideAccount

enforced by the language

Javasourc

e

3

Page 11: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #1: Insecure Compilation1 public class Account2 private int balance = 0;3

4 public void deposit( int amount )5 this.balance += amount;

1 typedef struct account_t {2 int balance = 0;3 void ( ∗deposit ) ( struct Account∗, int ) =

deposit_f;4 } Account;5

6 void deposit_f( Account∗ a, int amount ) {7 a→balance += amount;8 return;9 }

Javasourc

e

Ctarg

et

Pointer arithmetic in C leads tosecurity violation: undesired access to

balance

Security is not preserved.

2

Page 12: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #1: Insecure Compilation1 public class Account2 private int balance = 0;3

4 public void deposit( int amount )5 this.balance += amount;

1 typedef struct account_t {2 int balance = 0;3 void ( ∗deposit ) ( struct Account∗, int ) =

deposit_f;4 } Account;5

6 void deposit_f( Account∗ a, int amount ) {7 a→balance += amount;8 return;9 }

Pointer arithmetic in C leads tosecurity violation: undesired access to

balance

Security is not preserved.

2

Page 13: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Secure Compilation

• Q: what does it mean to preserve securityproperties across compilation?

• long standing question• many anwers have been given, we focus onthe formal ones

• conceptually:“take what was secure in the source and

preserve it in the target”

Even more questions!• how do we identify (or specify)what is secure in the source?

• how do we preserve the meaningof a security property?

anwers provided in this seminar

3

Page 14: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Secure Compilation

• Q: what does it mean to preserve securityproperties across compilation?

• long standing question

• many anwers have been given, we focus onthe formal ones

• conceptually:“take what was secure in the source and

preserve it in the target”

Even more questions!• how do we identify (or specify)what is secure in the source?

• how do we preserve the meaningof a security property?

anwers provided in this seminar

3

Page 15: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Secure Compilation

• Q: what does it mean to preserve securityproperties across compilation?

• long standing question• many anwers have been given, we focus onthe formal ones

• conceptually:“take what was secure in the source and

preserve it in the target”

Even more questions!• how do we identify (or specify)what is secure in the source?

• how do we preserve the meaningof a security property?

anwers provided in this seminar

3

Page 16: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Secure Compilation

• Q: what does it mean to preserve securityproperties across compilation?

• long standing question• many anwers have been given, we focus onthe formal ones

• conceptually:“take what was secure in the source and

preserve it in the target”

Even more questions!• how do we identify (or specify)what is secure in the source?

• how do we preserve the meaningof a security property?

anwers provided in this seminar

3

Page 17: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Secure Compilation

• Q: what does it mean to preserve securityproperties across compilation?

• long standing question• many anwers have been given, we focus onthe formal ones

• conceptually:“take what was secure in the source and

preserve it in the target”

Even more questions!• how do we identify (or specify)what is secure in the source?

• how do we preserve the meaningof a security property?

anwers provided in this seminar

3

Page 18: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Secure Compilation

• Q: what does it mean to preserve securityproperties across compilation?

• long standing question• many anwers have been given, we focus onthe formal ones

• conceptually:“take what was secure in the source and

preserve it in the target”

Even more questions!• how do we identify (or specify)what is secure in the source?

• how do we preserve the meaningof a security property?

anwers provided in this seminar

3

Page 19: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #2: Confidentiality

Confidential: adjective

spoken, written, acted on, etc., in strictprivacy or secrecy; secret:

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 0;5 return 0;6 }

Javasourc

e

• Q: how do we know that secret isconfidential?

4

Page 20: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #2: Confidentiality

Confidential: adjective

spoken, written, acted on, etc., in strictprivacy or secrecy; secret:

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 0;5 return 0;6 }

Javasourc

e

• Q: how do we know that secret isconfidential?

4

Page 21: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #2: Confidentiality

Confidential: adjective

spoken, written, acted on, etc., in strictprivacy or secrecy; secret:

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 0;5 return 0;6 }

Javasourc

e

• Q: how do we know that secret isconfidential?

4

Page 22: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• a possible answer to the questions before

• and to many more questions posed aboutprogramming languages

5

Page 23: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• a possible answer to the questions before• and to many more questions posed aboutprogramming languages

5

Page 24: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Quiz #1: Are these Equivalent Programs?

1 public Bool getTrue( x : Bool )2 return true;

1 public Bool getTrue( x : Bool )2 return x or true;

1 public Bool getTrue( x : Bool )2 return x and false;

1 public Bool getTrue( x : Bool )2 return false;

1 public Bool getFalse( x : Bool )2 return x and true;

• P1

• P2

• P3

• P4

• P5

≃ctx

≃ctx

Program equivalences (generally) are:• reflexive• transitive• symmetric

aka: relations

6

Page 25: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Quiz #1: Are these Equivalent Programs?

1 public Bool getTrue( x : Bool )2 return true;

1 public Bool getTrue( x : Bool )2 return x or true;

1 public Bool getTrue( x : Bool )2 return x and false;

1 public Bool getTrue( x : Bool )2 return false;

1 public Bool getFalse( x : Bool )2 return x and true;

• P1

• P2

• P3

• P4

• P5

≃ctx

≃ctx

Program equivalences (generally) are:• reflexive• transitive• symmetric

aka: relations

6

Page 26: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Quiz #1: Are these Equivalent Programs?

1 public Bool getTrue( x : Bool )2 return true;

1 public Bool getTrue( x : Bool )2 return x or true;

1 public Bool getTrue( x : Bool )2 return x and false;

1 public Bool getTrue( x : Bool )2 return false;

1 public Bool getFalse( x : Bool )2 return x and true;

• P1

• P2

• P3

• P4

• P5

≃ctx

≃ctx

Program equivalences (generally) are:• reflexive• transitive• symmetric

aka: relations

6

Page 27: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• Q: When are two programs equivalent?

• When they behave the same even if theyare different

• Semantics (behaviour) VS Syntax (outlook)• we care about the former, not the latter!

Defining a security property usingprogram equivalence:

to find two programs that, albeitsyntactically different, both behave ina way that respects the property, no

matter how they are used.

7

Page 28: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• Q: When are two programs equivalent?

• When they behave the same

even if theyare different

• Semantics (behaviour) VS Syntax (outlook)• we care about the former, not the latter!

Defining a security property usingprogram equivalence:

to find two programs that, albeitsyntactically different, both behave ina way that respects the property, no

matter how they are used.

7

Page 29: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• Q: When are two programs equivalent?

• When they behave the same even if theyare different

• Semantics (behaviour) VS Syntax (outlook)• we care about the former, not the latter!

Defining a security property usingprogram equivalence:

to find two programs that, albeitsyntactically different, both behave ina way that respects the property, no

matter how they are used.

7

Page 30: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• Q: When are two programs equivalent?

• When they behave the same even if theyare different

• Semantics (behaviour) VS Syntax (outlook)

• we care about the former, not the latter!

Defining a security property usingprogram equivalence:

to find two programs that, albeitsyntactically different, both behave ina way that respects the property, no

matter how they are used.

7

Page 31: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• Q: When are two programs equivalent?

• When they behave the same even if theyare different

• Semantics (behaviour) VS Syntax (outlook)• we care about the former, not the latter!

Defining a security property usingprogram equivalence:

to find two programs that, albeitsyntactically different, both behave ina way that respects the property, no

matter how they are used.

7

Page 32: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Program Equivalence

• Q: When are two programs equivalent?

• When they behave the same even if theyare different

• Semantics (behaviour) VS Syntax (outlook)• we care about the former, not the latter!

Defining a security property usingprogram equivalence:

to find two programs that, albeitsyntactically different, both behave ina way that respects the property, no

matter how they are used.

7

Page 33: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #4: Confidentiality as P.Eq.

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 0;5 return 0;6 }

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 1;5 return 0;6 }

With a Java-like semantics, secret isnever accessed from outside.

With a C-like semantics, secret can beaccessed from outisde.

The Language defines how to reason(it’s what programmers already do!)

8

Page 34: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #4: Confidentiality as P.Eq.

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 0;5 return 0;6 }

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 1;5 return 0;6 }

With a Java-like semantics, secret isnever accessed from outside.

With a C-like semantics, secret can beaccessed from outisde.

The Language defines how to reason(it’s what programmers already do!)

8

Page 35: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #4: Confidentiality as P.Eq.

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 0;5 return 0;6 }

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 1;5 return 0;6 }

With a Java-like semantics, secret isnever accessed from outside.

With a C-like semantics, secret can beaccessed from outisde.

The Language defines how to reason(it’s what programmers already do!)

8

Page 36: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #4: Confidentiality as P.Eq.

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 0;5 return 0;6 }

1 private secret : Int = 0;2

3 public setSecret( ) : Int {4 secret = 1;5 return 0;6 }

With a Java-like semantics, secret isnever accessed from outside.

With a C-like semantics, secret can beaccessed from outisde.

The Language defines how to reason(it’s what programmers already do!)

8

Page 37: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #5: Integrity as P.Eq.1 public proxy( callback : Unit → Unit ) : Int {2 var secret = 0;3 callback();4 if ( secret == 0 ) {5 return 0;6 }7 return 1;8 }

1 public proxy( callback : Unit → Unit ) : Int {2 var secret = 0;3 callback();4 return 0;5 }

Integrity: internal consistency or lackof corruption in data.

Maintenance of invariants

9

Page 38: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #5: Integrity as P.Eq.1 public proxy( callback : Unit → Unit ) : Int {2 var secret = 0;3 callback();4 if ( secret == 0 ) {5 return 0;6 }7 return 1;8 }

1 public proxy( callback : Unit → Unit ) : Int {2 var secret = 0;3 callback();4 return 0;5 }

Integrity: internal consistency or lackof corruption in data.

Maintenance of invariants

9

Page 39: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #5: Integrity as P.Eq.1 public proxy( callback : Unit → Unit ) : Int {2 var secret = 0;3 callback();4 if ( secret == 0 ) {5 return 0;6 }7 return 1;8 }

1 public proxy( callback : Unit → Unit ) : Int {2 var secret = 0;3 callback();4 return 0;5 }

Integrity: internal consistency or lackof corruption in data.

Maintenance of invariants

9

Page 40: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #6: Memory Allocation as P.Eq.

1 public newObjects( ) : Object {2 var x = new Object();3 var y = new Object();4 return x;5 }

1 public newObjects( ) : Object {2 var x = new Object();3 var y = new Object();4 return y;5 }

Guessing addresses in memory leadsto common exploits: ROP, return to

libc, violation of ASLR . . .

10

Page 41: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #6: Memory Allocation as P.Eq.

1 public newObjects( ) : Object {2 var x = new Object();3 var y = new Object();4 return x;5 }

1 public newObjects( ) : Object {2 var x = new Object();3 var y = new Object();4 return y;5 }

Guessing addresses in memory leadsto common exploits: ROP, return to

libc, violation of ASLR . . .

10

Page 42: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Expressing Program Equivalence

This (≃ctx ) is called

Contextual Equivalence

(also, observational equivalence)

11

Page 43: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Expressing Program Equivalence

This (≃ctx ) is called

Contextual Equivalence

(also, observational equivalence)

11

Page 44: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 45: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 46: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 47: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P . P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 48: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 49: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 50: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 51: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 52: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 53: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Contextual Equivalence (CEQ)

Two programs are equivalent if no matter whatexternal observer interacts with them thatobserver cannot distinguish the programs.

P1 ≃ctx P2def= ∀P. P ;P1↓P ;P2

• the external observer is generallycalled context

• it is a program, written in thesame language as P1 and P2

• it is the same program P

interacting with both P1 and P2 intwo different runs

• so it cannot express out oflanguage attacks (e.g., sidechannels)

• often we write it C or C

• interaction means link and runtogether (like a library)

• often we write it C [P1]

• distinguishing means: terminatewith different values

• the observer basically asks thequestion: is this program P1?

• if the observer can find a way todistinguish P1 from P2, it willreturn true, otherwise false

• often we use divergence andtermination as opposed to thisboolean termination

12

Page 54: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #7: CEQ1 private secret : Int = 0; //P12 public setSecret( ) : Int {3 secret = 0;4 return 0;5 }

1 private secret : Int = 0; //P22 public setSecret( ) : Int {3 secret = 1;4 return 0;5 }

1 // Observer P in Java2 public static isItP1( ) : Bool {3 Secret.getSecret();4 ...5 }

Java

Java

Java

13

Page 55: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #7: CEQ1 private secret : Int = 0; //P12 public setSecret( ) : Int {3 secret = 0;4 return 0;5 }

1 private secret : Int = 0; //P22 public setSecret( ) : Int {3 secret = 1;4 return 0;5 }

1 // Observer P in Java2 public static isItP1( ) : Bool {3 Secret.getSecret();4 ...5 }

Java

Java

Java13

Page 56: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Example #8: CEQ1 typedef struct secret { // P12 int secret = 0;3 void ( ∗setSec ) ( struct Secret∗ ) = setSec;4 } Secret;5 void setSec( Secret∗ s ) { s→secret = 0; return; }

1 typedef struct secret { // P22 int secret = 0;3 void ( ∗setSec ) ( struct Secret∗ ) = setSec;4 } Secret;5 void setSec( Secret∗ s ) { s→secret = 1; return; }

1 // Observer P in C2 int isItP1( ){3 struct Secret x;4 sec = &x + sizeof(int);5 if ∗sec == 0 then return true else return false6 }

C

C

C

14

Page 57: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Inequivalences as Security Violations

• if the programs are not equivalent (≄ctx )then the intended security property isviolated

• this hardly happens as source languagesare high level

When does inequivalences escape theprogrammer’s reasoning?

1. if languages have complexfeatures

2. if there are more languagesinvolved (e.g., multiple targetlanguages)

15

Page 58: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Inequivalences as Security Violations

• if the programs are not equivalent (≄ctx )then the intended security property isviolated

• this hardly happens as source languagesare high level

When does inequivalences escape theprogrammer’s reasoning?

1. if languages have complexfeatures

2. if there are more languagesinvolved (e.g., multiple targetlanguages)

15

Page 59: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Inequivalences as Security Violations

• if the programs are not equivalent (≄ctx )then the intended security property isviolated

• this hardly happens as source languagesare high level

When does inequivalences escape theprogrammer’s reasoning?

1. if languages have complexfeatures

2. if there are more languagesinvolved (e.g., multiple targetlanguages)

15

Page 60: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Inequivalences as Security Violations

• if the programs are not equivalent (≄ctx )then the intended security property isviolated

• this hardly happens as source languagesare high level

When does inequivalences escape theprogrammer’s reasoning?

1. if languages have complexfeatures

2. if there are more languagesinvolved (e.g., multiple targetlanguages)

15

Page 61: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Inequivalences as Security Violations

• if the programs are not equivalent (≄ctx )then the intended security property isviolated

• this hardly happens as source languagesare high level

When does inequivalences escape theprogrammer’s reasoning?

1. if languages have complexfeatures

2. if there are more languagesinvolved (e.g., multiple targetlanguages)

15

Page 62: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Preserving Equivalences in Compilation

Back to our question . . .

• Q: what does it mean to preserve securityproperties across compilation?

A possible answer:

• Given source equivalent programs (whichhave a security property), compile theminto equivalent target programs

• Assumption 1: the securityproperty is captured in the sourceby program equivalence

• Crucial: being equivalent in thetarget means contextualequivalence w.r.t. targetobservers (i.e., target programs)

• These are the attackers in thesecure compilation setting

16

Page 63: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Preserving Equivalences in Compilation

Back to our question . . .

• Q: what does it mean to preserve securityproperties across compilation?

A possible answer:

• Given source equivalent programs (whichhave a security property), compile theminto equivalent target programs

• Assumption 1: the securityproperty is captured in the sourceby program equivalence

• Crucial: being equivalent in thetarget means contextualequivalence w.r.t. targetobservers (i.e., target programs)

• These are the attackers in thesecure compilation setting

16

Page 64: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Preserving Equivalences in Compilation

Back to our question . . .

• Q: what does it mean to preserve securityproperties across compilation?

A possible answer:

• Given source equivalent programs (whichhave a security property), compile theminto equivalent target programs

• Assumption 1: the securityproperty is captured in the sourceby program equivalence

• Crucial: being equivalent in thetarget means contextualequivalence w.r.t. targetobservers (i.e., target programs)

• These are the attackers in thesecure compilation setting

16

Page 65: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Preserving Equivalences in Compilation

Back to our question . . .

• Q: what does it mean to preserve securityproperties across compilation?

A possible answer:

• Given source equivalent programs (whichhave a security property), compile theminto equivalent target programs

• Assumption 1: the securityproperty is captured in the sourceby program equivalence

• Crucial: being equivalent in thetarget means contextualequivalence w.r.t. targetobservers (i.e., target programs)

• These are the attackers in thesecure compilation setting

16

Page 66: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Preserving Equivalences in Compilation

Back to our question . . .

• Q: what does it mean to preserve securityproperties across compilation?

A possible answer:

• Given source equivalent programs (whichhave a security property), compile theminto equivalent target programs

• Assumption 1: the securityproperty is captured in the sourceby program equivalence

• Crucial: being equivalent in thetarget means contextualequivalence w.r.t. targetobservers (i.e., target programs)

• These are the attackers in thesecure compilation setting

16

Page 67: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

A compiler is secure if, given source equivalentprograms, it compiles them into equivalenttarget programs

J⋅KST is FAC#1 def= ∀P1,P2

if P1 ≃ctx P2

then JP1KST≃ctxJP2K

ST

Right?

17

Page 68: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

A compiler is secure if, given source equivalentprograms, it compiles them into equivalenttarget programs

J⋅KST is FAC#1 def= ∀P1,P2

if P1 ≃ctx P2

then JP1KST≃ctxJP2K

ST

Right?

17

Page 69: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

A compiler is secure if, given source equivalentprograms, it compiles them into equivalenttarget programs

J⋅KST is FAC#1 def= ∀P1,P2

if P1 ≃ctx P2

then JP1KST≃ctxJP2K

ST

Right?

17

Page 70: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

A compiler is secure if, given source equivalentprograms, it compiles them into equivalenttarget programs

J⋅KST is FAC#1 def= ∀P1,P2

if P1 ≃ctx P2

then JP1KST≃ctxJP2K

ST

Right?

17

Page 71: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

A compiler is secure if, given source equivalentprograms, it compiles them into equivalenttarget programs

J⋅KST is FAC#1 def= ∀P1,P2

if P1 ≃ctx P2

then JP1KST≃ctxJP2K

ST

Right?

17

Page 72: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

A compiler is secure if, given source equivalentprograms, it compiles them into equivalenttarget programs

J⋅KST is FAC#1 def= ∀P1,P2

if P1 ≃ctx P2

then JP1KST ≃ctx JP2K

ST

Right?

17

Page 73: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

A compiler is secure if, given source equivalentprograms, it compiles them into equivalenttarget programs

J⋅KST is FAC#1 def= ∀P1,P2

if P1 ≃ctx P2

then JP1KST≃ctxJP2K

ST

Right?17

Page 74: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

Wrong.

An empty translation would fit FAC#1!

We need the compiler also to be correct.Roughly, turn⇒ into a ⇐⇒ :1

J⋅KST is FAC def= ∀P1,P2

P1 ≃ctx P2 ⇐⇒ JP1KST≃ctxJP2K

ST

Note: ⇐ does not mean compiler correctness inthe general sense, but it’s a consequence

1Abadi ’99 18

Page 75: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

Wrong.

An empty translation would fit FAC#1!

We need the compiler also to be correct.Roughly, turn⇒ into a ⇐⇒ :1

J⋅KST is FAC def= ∀P1,P2

P1 ≃ctx P2 ⇐⇒ JP1KST≃ctxJP2K

ST

Note: ⇐ does not mean compiler correctness inthe general sense, but it’s a consequence

1Abadi ’99 18

Page 76: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

Wrong.

An empty translation would fit FAC#1!

We need the compiler also to be correct.Roughly, turn⇒ into a ⇐⇒ :1

J⋅KST is FAC def= ∀P1,P2

P1 ≃ctx P2 ⇐⇒ JP1KST≃ctxJP2K

ST

Note: ⇐ does not mean compiler correctness inthe general sense, but it’s a consequence

1Abadi ’99 18

Page 77: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Fully Abstract Compilation

Wrong.

An empty translation would fit FAC#1!

We need the compiler also to be correct.Roughly, turn⇒ into a ⇐⇒ :1

J⋅KST is FAC def= ∀P1,P2

P1 ≃ctx P2 ⇐⇒ JP1KST≃ctxJP2K

ST

Note: ⇐ does not mean compiler correctness inthe general sense, but it’s a consequence1Abadi ’99 18

Page 78: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Remarks on Fully Abstract Compilation

• widely adopted since 1999

• only preserves security property expressedas program equivalence

• not the silver bullet: the papers will presentshortcomings of fully abstract compilation

19

Page 79: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Remarks on Fully Abstract Compilation

• widely adopted since 1999• only preserves security property expressedas program equivalence

• not the silver bullet: the papers will presentshortcomings of fully abstract compilation

19

Page 80: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Remarks on Fully Abstract Compilation

• widely adopted since 1999• only preserves security property expressedas program equivalence

• not the silver bullet: the papers will presentshortcomings of fully abstract compilation

19

Page 81: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Conclusion

• program equivalences can be used todefine security properties

• preserving (and reflecting) equivalencescan be used to define a secure compiler

20

Page 82: Lecture 1: What is Secure Compilation? - Secure ... · Example #1: Insecure Compilation 1 publicclass Account 2 privateint balance= 0; 3 4 public voiddeposit(int amount) 5 this.balance

Further Reading

Short(ish) and high-level(ish):• Martin Abadi. 1999. Protection inprogramming-language translations. In SecureInternet programming

• Andrew Kennedy. 2006. Securing the .NETProgramming Model. Theoretical Computer Science364 (2006)

• Joachim Parrow. 2014. General conditions for FullAbstraction. Math Struct Comp Science (2014)

• Daniele Gorla and Uwe Nestman. 2014. FullAbstraction for Expressiveness: History, Myths andFacts. Math Struct Comp Science (2014)

21