Formal Verification of Binary Code Roberto Guanciale // - - PowerPoint PPT Presentation

formal verification of binary code
SMART_READER_LITE
LIVE PREVIEW

Formal Verification of Binary Code Roberto Guanciale // - - PowerPoint PPT Presentation

Formal Verification of Binary Code Roberto Guanciale // a0=GETBYTE(s0, 3); ldr r3, [r7, #84] lsrs r3, r3, #24 uxtb r3, r3 str r3, [r7, #48] ... // v0=*(Te[0] + a0); ldr r3, [r7, #48] lsls r2, r3, #2 ldr r3, [pc,


slide-1
SLIDE 1

Formal Verification of Binary Code

Roberto Guanciale

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5

// a0=GETBYTE(s0, 3); ldr r3, [r7, #84] lsrs r3, r3, #24 uxtb r3, r3 str r3, [r7, #48] ... // v0=*(Te[0] + a0); ldr r3, [r7, #48] lsls r2, r3, #2 ldr r3, [pc, #928] ; AesEncrypt+0x428 adds r3, r2, r3 ldr r3, [r3, #0] str r3, [r7, #32] ... // t0 = v0 ^ v1 ^ v2 ^ v3 ^ rk[0]

slide-6
SLIDE 6

// a0=GETBYTE(s0, 3); ldr r3, [r7, #84] lsrs r3, r3, #24 uxtb r3, r3 str r3, [r7, #48] ... // v0=*(Te[0] + a0); ldr r3, [r7, #48] lsls r2, r3, #2 ldr r3, [pc, #928] ; AesEncrypt+0x428 adds r3, r2, r3 ldr r3, [r3, #0] str r3, [r7, #32] ... // t0 = v0 ^ v1 ^ v2 ^ v3 ^ rk[0]

slide-7
SLIDE 7

Binary Analysis Frameworks

  • Valgrind
  • BAP
  • Angr
slide-8
SLIDE 8

Binary Analysis Frameworks

  • Valgrind
  • BAP
  • Angr

Peripheral Model MMU Model System Security

slide-9
SLIDE 9

Binary Analysis Frameworks

  • Valgrind
  • BAP
  • Angr
slide-10
SLIDE 10

Binary Analysis Frameworks

  • Valgrind
  • BAP
  • Angr
slide-11
SLIDE 11
  • Implemented using Interactive Theorem Prover (HOL4)

○ => Machine checkable proofs

  • Formal semantics if ISAs (ARM/Risc-V/etc)
  • Formal semantics of BinaryIntermediateRepresentation

○ Similar to LLVM IR ○ Language designed to automate analysis ■ Program not in memory / Assertions

  • Verified theories and proof producing analyses

○ Transpilation ○ Contract based verification ○ ...

Certifying (Proof-producing) Analysis of Binaries

slide-12
SLIDE 12

Certifying Transpilation

0: pop R1 4: push R1 [0 { R1 := MEM[SP]; SP := SP-4; PC := PC+4; JMP 4}] [4 { MEM := MEM with [SP<-R1]; SP := SP+4; PC := PC+4; JMP 8}]

slide-13
SLIDE 13

Certifying Transpilation

0: pop R1 4: push R1 [0 { R1 := MEM[SP]; SP := SP-4; PC := PC+4; JMP 4}] [4 { ASSERT(SP not in CODE SECTION); MEM := MEM with [SP<-R1]; SP := SP+4; PC := PC+4; JMP 8}]

slide-14
SLIDE 14

Contract Based Verification:

  • For structured program

○ {P} statements {Q}

  • For unstructured program?
slide-15
SLIDE 15

Contract Based Verification:

  • For structured program

○ {P} statements {Q}

  • For unstructured program?
slide-16
SLIDE 16

Contract Based Verification:

  • For structured program

○ {P} statements {Q}

  • For unstructured program?

○ {P} program: A1 -> A2 {Q}

slide-17
SLIDE 17

Contract Based Verification:

  • For structured program

○ {P} statements {Q}

  • For unstructured program?

○ {P} program: A1 -> A2 {Q}

  • Semi-automatic verification

○ Weakest precondition: WP ○ SMT solver P ⇒ WP

slide-18
SLIDE 18

Contract Based Verification:

  • For structured program

○ {P} statements {Q}

  • For unstructured program?

○ {P} program: A1 -> A2 {Q}

  • Semi-automatic verification

○ Weakest precondition: WP ○ SMT solver P ⇒ WP

slide-19
SLIDE 19

Contract Based Verification:

  • For structured program

○ {P} statements {Q}

  • For unstructured program?

○ {P} program: A1 -> A2 {Q}

  • Semi-automatic verification

○ Weakest precondition: WP ○ SMT solver P ⇒ WP

slide-20
SLIDE 20

Contract Based Verification:

  • For structured program

○ {P} statements {Q}

  • For unstructured program?

○ {P} program: A1 -> A2 {Q}

  • Semi-automatic verification

○ Weakest precondition: WP ○ SMT solver P ⇒ WP

slide-21
SLIDE 21

Compositional Logic For Binary Code

slide-22
SLIDE 22

Compositional Logic For Binary Code

slide-23
SLIDE 23

Compositional Logic For Binary Code

slide-24
SLIDE 24

Putting things together

slide-25
SLIDE 25

Putting things together

slide-26
SLIDE 26

Putting things together

slide-27
SLIDE 27

Putting things together

slide-28
SLIDE 28

Putting things together

slide-29
SLIDE 29

Real world usage

  • Transpilation:

○ ~ 5 instructions / s ○ numlib / wolf-ssl / lua / SQLite / libc ○ ARMv8 / Cortex M0 / Ongoing Risc-V

  • Weakest precondition

○ ~ 1 instruction / s ○ fragments consisting of 10/100 instructions (i.e. AES loop body)

slide-30
SLIDE 30

Thank You

https://github.com/kth-step/HolBA

  • Side channel analysis
  • Symbolic execution

○ WCET ○ Translation validation

  • Kernel verification