• Aucun résultat trouvé

Compilation for the Composition of Software Protections for Embedded Systems

N/A
N/A
Protected

Academic year: 2021

Partager "Compilation for the Composition of Software Protections for Embedded Systems"

Copied!
26
0
0

Texte intégral

(1)

HAL Id: cea-01273410

https://hal-cea.archives-ouvertes.fr/cea-01273410

Submitted on 13 Feb 2016

HAL is a multi-disciplinary open access

archive for the deposit and dissemination of sci-entific research documents, whether they are pub-lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.

Compilation for the Composition of Software Protections for Embedded Systems

Thierno Barry, Damien Couroussé, Bruno Robisson

To cite this version:

Thierno Barry, Damien Couroussé, Bruno Robisson. Compilation for the Composition of Software Protections for Embedded Systems. 5ème édition de la rencontre Crypto’Puce, May 2015, Île de Porquerolles, France. �cea-01273410�

(2)

www.cea.fr  

Compila(on  for  the  composi(on  

of  so2ware  protec(ons  for  

embedded  systems

 

Thierno  

B

ARRY1

   

Damien  

C

OUROUSSÉ1  

Bruno  

R

OBISSON2  

1

CEA  –  LIST  /  DACLE    

2

CEA  /  DPACA  

Firstname.LASTNAME@cea.fr  

Crypto’Puce  2015  

 

Porquerolles  Tuesday,  May  5,    2015  

(3)

Cliquez  pour  modifier  le  style  du  (tre  

A

FFILIATION

   

DACLE

 

Département  Architecture,  ConcepVon  et  Logiciels  Embarqués  

 

LIALP  

Laboratoire  Infrastructures  Atelier  Logiciels  sur  Puce

 

SCSN

 

Service  Calcul  et  Systèmes  Numériques

 

SAS  

Systèmes  et  Architectures  Sécurisés

 

CMP

 

Centre  Microélectronique  de  Provence

 

AutomaVc  control  (centralized  and  distributed  )  

Middleware  and  communicaVon    

CompilaVon  and  code  generaVon  

Methods  and  tools:  design  flow  for  HW/SW  integraVon  

(4)

Cliquez  pour  modifier  le  style  du  (tre  

C

ONTEXT

 

Nowadays,  embedded  systems  have  increasingly  become  criVcal  part  of  our  

daily  life  

1  

Side  channel  aaacks  

Observing  physical  quanVVes  of  the  device   during  operaVon    

One  of  the  major  threats  against  these  systems  are  physical  aMacks  

There  are  two  main  categories  

InjecVng  a  fault  in  order  to  disrupt  the  normal   funcVoning  of  the  device  

Fault  aaacks  

2  

(5)

Cliquez  pour  modifier  le  style  du  (tre  

O

BJECTIVE

 

Proposing  a  tool  for  composing  several  soeware  protecVons  against  

physical  aaacks  

Through  a  compilaVon  toolchain  

also  called:  

CompilaVon  for  security  

Our  work  involves  two  disciplines:  

Physical  security  

CompilaVon  

1   2  

(6)

Cliquez  pour  modifier  le  style  du  (tre  

O

UTLINE

 

ExisVng  countermeasures  against  physical  aaacks  

Concluding  remarks  

Our  approach  

A  safari  inside  a  compiler  

why  compilaVon  +  security  is  not  obvious  ?  

Why  operaVng  inside  a  compiler?  

First  results  

(7)

Cliquez  pour  modifier  le  style  du  (tre  

E

XISTING

 

COUNTERMEASURES

 

Side  Channel  AMacks  

Work  because  there  is  a  correlaVon  between  the  operaVons  being  

processed  and  some  observable  physical  quanVVes    

The  objecVve  of  countermeasures  is:  

OperaVons   Physical  quanVVes  

Two  concepts:  

Soeware  

InserVon  of  dummy  instrucVons   InstrucVons  shuffling  

Hardware  

Randomize  the  power  consumpVon   Equalize  the  power  consumpVon  

v

m

 =  v  

 m  

v

m

 =  v  +  m  

v

m

 =  v  x  m  

è    Boolean   è    Modular  addiVon   è    Modular  mulVplicaVon  

Masking  

1   2  

Hiding  

Concealing  each  intermediate  

value  

v

 by  a  random  value  

m

 such  

as:  

v

m

 =  v  op  m  

(8)

Cliquez  pour  modifier  le  style  du  (tre  

E

XISTING

 

COUNTERMEASURES

 

Fault  AMacks  

Based  on  fault  models  where  an  aaacker  can:  

Skip  an  instrucVon  

Replace  an  instrucVon  with  another  one  

Corrupt  data  being  transferred  from/to  memory    

Proposed  countermeasures  are:  

InstrucVons  redundancy     Control  flow  hardening   CRC  /  Parity  Check  /  …  

(9)

Cliquez  pour  modifier  le  style  du  (tre  

E

XISTING

 

COUNTERMEASURES

 

Concluding  

remarks    

We  noVce  two  approaches  for  applying  countermeasures    

Source  Code     Compiler   Binary  Code   Secured  ?   Secure  source   code   Countermeasure   applicaVon  

source  to  source  approach

 

Problems:  

None  of  security  properVes  applied  to   the  source  code  are  guaranteed  aeer   the  compilaVon  

Except  if  all  the  compiler  code  

opVmizers  are  disabled    as  suggested  

in  [Eldib  et  al.  2014]  

Leads  to  very  high  execuVon  overheads:  

è  +  400%  in  [Lalande  et  al.    2014]  

At  the  source  code  level

 

1  

(10)

Cliquez  pour  modifier  le  style  du  (tre  

E

XISTING

 

COUNTERMEASURES

 

Concluding  

remarks    

At  Assembly  level

 

Source  code  

Compiler  

Unsecure  

Binary  code   Disassembler   Assembly   code   Assembler   Secure  Binary   code   Secure   Assembly  code   Countermeasure   applicaVon  

Problems:  

Lack  of  visibility  program  context  

Oeen  ad-­‐hoc  [Barenghi et al., 2010]

è  Overheads  ++  

Assembly  approach

 

(11)

Cliquez  pour  modifier  le  style  du  (tre  

E

XISTING

 

COUNTERMEASURES

 

Concluding  

remarks    

 

[Regazzoni  et  al.  2008]  and  [Luo  et  al.  2014]  

have  shown  that  a  code  protected  against  

Fault  aaacks  may  increase  the  power  leakage  

è

 and  then  become  more  vulnerable  to  power  analysis  aaacks  

How  to  take  into  account  several  threats  inside  a  countermeasure  ?  

(12)

Cliquez  pour  modifier  le  style  du  (tre  

Source  code   Compiler   Unsecure   Binary  code   Disassembler   Assembly   code   Assembler   Secure  Binary   code   Secure   Assembly  code   Countermeasur e  applicaVon   Source  Code     Compiler   Binary  Code   Secured  ?   Secure  source   code   Countermeasure   applicaVon  

O

UR

 

APPROACH

   

ComposiVon  of    several  protecVons    

Binary  code  protected  against  several  

aaacks  

Source   code   CompilaVon   +  security   Secure   binary  code  

(13)

Cliquez  pour  modifier  le  style  du  (tre  

O

UTLINE

 

ExisVng  countermeasures  against  physical  aaacks  

Concluding  remarks  

Our  approach  

A  safari  inside  a  compiler  

why  compilaVon  +  security  is  not  obvious  ?  

Why  operaVng  inside  a  compiler?  

First  results  

(14)

Cliquez  pour  modifier  le  style  du  (tre  

A  

SAFARI

 

INSIDE

 

A

 

COMPILER

 

What  is  a  compiler  ?

 

Source  code   Machine  code  

Compiler  

The  source  code  passes  through  several  transformaVons  and  representaVon    

before  the  Machine  code    

Each  one  is  suitable  for  some  kind  of  tasks  of  the  compiler  

Modern  compilers  are  structured  in  3  phases:  

Front  end  

Middle  end  

Back  end  

(15)

Cliquez  pour  modifier  le  style  du  (tre  

A  

SAFARI

 

INSIDE

 

A

 

COMPILER

 

Front  end

 

Lexical  

Analysis   Analysis  Syntax     Checking  Type     generaVon  IR  

Reads  the  source  code  

and  splits  it  into  a  list  of   tokens    e.g.:    

if   (   x   >   0   )   {   Return   a   +   b   ;   }  

Take  the  list  of  tokens,     built  the  AST    è  check   the  validity  of  the  syntax    

if   >   x   0   ret   +   a   b   Source  code   If (x > 0){ return a+b; } … %cmp = icmp sgt i32 %x, 0 br i1 %cmp, label %if.then, … %if.then:

%add = add nsw i32 %a, %b

store i32 %add, i32* %retval

br label %return …

(16)

Cliquez  pour  modifier  le  style  du  (tre  

A  

SAFARI

 

INSIDE

 

A

 

COMPILER

 

Middle  end

 

Takes  as  input  the  Intermediate  representaVon    

The  IR  is  supposed  to  be  language  and  target  independent  

Front  end  

Middle  end  

Back  end  

Language  dependent   Target  dependent  

C,    C++,    Java,    Fortran,  …   x86,  ARM,  MIPS,  SPARC  …  

A  countermeasure  applied  at  the  

middle  end  

remain  valid  for  all  languages  

and  targets  supported  by  the  compiler  

 

(17)

Cliquez  pour  modifier  le  style  du  (tre  

A  

SAFARI

 

INSIDE

 

A

 

COMPILER

 

Middle  end

 

The  majority  of  code  opVmizer  are  applied  at  

middle  end

   

Among  them  we  have:  

Global  Value  Numbering  (GVN)

 

Remove  all  redundant  instrucVons  

int x = 0;

int y = f(x);

for(int i=1; i<= 100; i++)

if(i > 0)

x = x + 1;

else

x = x – 1;

y = f(x)

Dead  Code  EliminaVon  (DCE)

 

Dead  Store  EliminaVon  (DSE)

 

Remove  all  unreachable  instrucVons  

Remove  memory  wriVngs  that  are  never  read  

int x = 0;

int y = f(x);

for(int i=1; i<= 100; i++)

x = x + 1; y = f(x) int x = 0; int y = f(x); x = 100; y = f(x) int y = f(0); int x = 100; y = f(x) int y = f(100);

(18)

Cliquez  pour  modifier  le  style  du  (tre  

A  

SAFARI

 

INSIDE

 

A

 

COMPILER

 

Middle  end

 

Loop  Invariant  Code  MoVon  (LICM)

 

•  LOOP-­‐UNROLLING  /  LOOP  UNSWITCH    

bool flag;

for(int i=7; i*i< 1000; i++){

flag = verdict(1); if(flag == true) foo(); else bar(); } bool flag;

for(int i=0; i<25; i++){

flag = verdict(1); if(flag == true) foo(); else bar(); } 31*31  =  961   32*32  =  1024   è i  =  [7-­‐32]  è  [0-­‐25]  

bool flag = verdict(1);

for(int i=0; i<25; i++){

if(flag == true)

foo(); else

bar(); }

bool flag = verdict(1);

if(flag == true)

for(int i=0; i<25; i++)

foo(); else

for(int i=0; i<25; i++)

(19)

Cliquez  pour  modifier  le  style  du  (tre  

A  

SAFARI

 

INSIDE

 

A

 

COMPILER

 

Back  end

 

Takes  the  IR  as  input    

InstrucVons  selecVons  

InstrucVon  scheduling    

Register  allocaVon  

Machine  code  emission  

Convert  the  IR  to  a  representaVon  close  to  the   target  architecture    

Rearrange  instrucVons

 

to  obtain  the  best  

execuVon  order  in  order  to  avoid  stalls  inside  the  

pipeline  

Find  the  best  way  to  assign  physical  registers  to   variables  in  order  to  reduce  register  pressure  and   avoid  memory  spills    

(20)

Cliquez  pour  modifier  le  style  du  (tre  

C

OMPILATION

 

VS

.  S

ECURITY

 

GeneraVon  of    executable  code  for  a   target  architecture  

C

O M P I L A T I O N

 

S

E C U R I T Y

 

G

O A L

 

Making  the  execuVon  as  fast  as  

possible  

H

O W

?  

Safety  

Resistance  against  aaacks  

Adding  instrucVon  redundancy   InserVon  of  dummy  instrucVons  

Random  scheduling    (shuffling)  

Masking  intermediate  values   Removing  any  instrucVon  redundancy  

Dead  code/store  eliminaVon     Smart  scheduling  

(21)

Cliquez  pour  modifier  le  style  du  (tre  

W

HY

 

OPERATING

 

INSIDE

 

A

 

COMPILER

?  

Possibility  to  reduce  the  cost  of  the  security  

We  can  decide  where  and  when  to  apply  security    

We  can  ensure  that  the  security  won’t  be  removed  by  the  compiler   We  can  take  advantage  of  code  opVmizaVon  

We  have  a  complete  view  on  the  program  being  compiled  

1  

We  have  control  over  code  opVmizers  

2  

We  can  scale  the  security  level  relaVve  to  opVmizaVon  level  

(22)

Cliquez  pour  modifier  le  style  du  (tre  

F

IRST

 

RESULTS

 

With  a  very  opVmal  overhead  thanks  to  our  hacked  register  allocator

 

1  

W

HY

?

 

With  an  

Assembly

 approach,  when  comes  to  duplicate  an  instrucVon  like:  

add R0, R0, R1

Just  doing      

addadd R0, R0, R1 R0, R0, R1

is  invalid  because  

R0

 is  both  source  and  desVnaVon  

An  extra  available  register  is  needed  to  save  

R0

:  

mov add R0, R2, R1R2, R0

How  to  find  an  extra  available  register?

 

Instruc(on  duplica(on  (ID)  inside  the  compiler  

you  are  designing  an  ad-­‐hoc  countermeasure     and  you  know  how  many  registers  are  

available  [Barenghi  et  al.,  2010]  

 

1  

you  parse  your  assembly  code  (not  easy)  

2   push R2 mov R2, R0 mov R2, R0 add R0, R2, R1 add R0, R2, R1 pop R2 mov R2, R0 mov R2, R0 add R0, R2, R1 add R0, R2, R1

3   Save  an  restore    

push R2

mov R2, R0

add R0, R2, R1

(23)

Cliquez  pour  modifier  le  style  du  (tre  

F

IRST

 

RESULTS

 

With  a  very  opVmal  overhead  thanks  to  our  hacked  register  allocator  (RA)

 

1  

Instruc(on  duplica(on  (ID)  inside  the  compiler  

opcode Rdst, Rsrc1, Rsrc2 (Rdst != Rsrc1) and (Rdst != Rsrc2)

We  modified  our  RA  in  such  a  way  that  the  desVnaVon  register  is  always  

different  to  source  registers:

 

Instead  of  generaVng:

 

T

HAT

S

 

WHY

 

add R0, R0, R1

We  automaVcally  generate:

 

add R0, R1, R2

and  duplicaVng  such  an  instrucVon  is  straigh•orward

 

addadd R0, R1, R2 R0, R1, R2

with  a  reduced  overhead  compared  to:

 

mov R2, R0 mov R2, R0 add R0, R2, R1 add R0, R2, R1

X  4

 

push R2 mov R2, R0 mov R2, R0 add R0, R2, R1 add R0, R2, R1 pop R2

and

 

X  6

 

X  2

 

(24)

Cliquez  pour  modifier  le  style  du  (tre  

F

IRST

 

RESULTS

 

With  a  very  opVmal  overhead  thanks  to  our  hacked  register  allocator  (RA)

 

1  

Instruc(on  duplica(on  (ID)  inside  the  compiler  

Our  duplicaVon  process  is  done  before  the  instrucVon  scheduling

 

2  

The  compiler  will  rearrange  the  instrucVons  in  order  to  find  the  best  execuVon  order   As  a  consequence:  

 è  duplicated  instrucVons  may  not  necessary  be  glued  

add R0, R1, R2

store R9, r5

add R0, R1, R2

store R9, r5

add R0, R1, R2

(25)

Cliquez  pour  modifier  le  style  du  (tre  

O

UTLOOK

 

Our  objecVve  is  not  to  produce  new  unknown  countermeasure  

The  next  step  is  to  implement  power  analysis  countermeasures  in  

our  compiler    

B

UT

 

Finding  a  way  to  combine  them  in  a  single  tool,  without  marginalizing  

the  execuVon  performance    

And  then  implemenVng  a  unified  countermeasure  model    

Proving  the  validity  of  the  model  

(26)

Thank  you  for  your  aaenVon  

Références

Documents relatifs

To test whether the vesicular pool of Atat1 promotes the acetyl- ation of -tubulin in MTs, we isolated subcellular fractions from newborn mouse cortices and then assessed

Néanmoins, la dualité des acides (Lewis et Bronsted) est un système dispendieux, dont le recyclage est une opération complexe et par conséquent difficilement applicable à

Cette mutation familiale du gène MME est une substitution d’une base guanine par une base adenine sur le chromosome 3q25.2, ce qui induit un remplacement d’un acide aminé cystéine

En ouvrant cette page avec Netscape composer, vous verrez que le cadre prévu pour accueillir le panoramique a une taille déterminée, choisie par les concepteurs des hyperpaysages

Chaque séance durera deux heures, mais dans la seconde, seule la première heure sera consacrée à l'expérimentation décrite ici ; durant la seconde, les élèves travailleront sur

A time-varying respiratory elastance model is developed with a negative elastic component (E demand ), to describe the driving pressure generated during a patient initiated

The aim of this study was to assess, in three experimental fields representative of the various topoclimatological zones of Luxembourg, the impact of timing of fungicide

Attention to a relation ontology [...] refocuses security discourses to better reflect and appreciate three forms of interconnection that are not sufficiently attended to