Using LLVM to guarantee program integrity
Simon Cook
Using LLVM to guarantee program integrity Simon Cook Background - - PowerPoint PPT Presentation
Using LLVM to guarantee program integrity Simon Cook Background Compiling for security is becoming increasingly important Finding bugs through AddressSanitizer, MemorySanitizer, etc. Research programs such as LADA Use of
Simon Cook
return values are correct
Each instruction becomes dependent on the previous one Given an instruction π½", and internal state π$, we can produce the encoded instruction πΉ" and output state π"
π½" π$ πΉ" π"
πΉ" π$ π½" π"
add r0, r1 0xbeef
At run time, the hardware can use the same state, and using the encoded instruction, reproduce the original instruction
0xbeef add r0, r1
lsli $r10, $r2, 2 919a 4000 andi $r13, $r3, 5 5d87 4002 add $r2, $r13, $r10 aa82 0900 jmp $r0 0050 int foo(int x, int y) { return (4*x) + (y&5); }
π½" π½. π½/ π½0
lsli 0001 0203 andi 0405 0607 add 0809 0a0b jmp 0c0d π , β π , β π , β π , β
π½" π$ πΉ" π½. π" πΉ. π½/ π. πΉ/ π½0 π/ πΉ0
; BB#0: movi $r10, 0 809e 4000 bne .LBB0_2, $r4, $r10 e2c6 0100 ; BB#1: mov $r2, $r3 9812 .LBB0_2: jmp $r0 0050 int foo(int x, int y, bool z) { return z ? x : y; }
π½" π½. π½/ π½0
π , β π , β
π½0 π/ πΉ0 π½0 π2 πΉ0
For two cases, this may be solvable, but not for blocks with many direct predecessors
; BB#0: movi $r10, 0 809e 4000 bne .LBB0_2, $r4, $r10 e2c6 0100 _correction_value_ .... ; BB#1: mov $r2, $r3 9812 .LBB0_2: jmp $r0 0050 int foo(int x, int y, bool z) { return z ? x : y; }
π½" π½. π· π½/ π½0
π , β π , β
π½0 π/ πΉ0 π½0 π· πΉ0
π , β π , β
π½. π" πΉ. π· π" πΉ3
int foo(int x) { return bar(x+2); } subi $r1, $r1, 2 4a16 stw [$r1, 0], $r0 4038 addi $r2, $r2, 2 9214 bal bar, $r0 00c2 0000 ldw $r0, [$r1, 0] 0828 addi $r1, $r1, 2 4a14 jmp $r0 0050
π½" π½. π½/ π½0 π½4 π½5 π½6
π0
foo.c bar.c baz.c
Pros
enables system for entire CU
Cons
across entire project
needs patching
size
In the end we decided not to go down this route
Pros
βnon-secureβ functions
functions it was requested for
Cons
needs patching
attribute to all declarations of a function
not the same as to unprotected
let isCall = 1 in def JAL : Inst_rrr <0x2, 0x9, (outs), (ins i64imm:$ i64imm:$flags flags, GR64:$rD, GR64:$rB), "jal\t $rD, $rBβ, [(AAPcall timm timm:$ :$flags flags, GR64:$rD, GR64:$rB)]>;
===--- CF encoding statistics for 'main' ---=== Bytes added: 10 Words added: 5 NOP gaps added: 3 Enable/Disable insns added: 1
1 Function Start Address Group 2 Function End Address 6 Call Site Call Target 11 Count Target 1 Target 2
simon@shadowfax$ llvm-objdump -d a.out a.out: file format ELF32-aap Disassembly of section .text: Section has correction values, printing real instructions foo: 8000000: [8f39] 91 9a 40 00 lsli $r10, $r2, 2 8000004: [81ca] 5d 87 40 02 andi $r13, $r3, 5 8000008: [053b] aa 82 09 00 add $r2, $r13, $r10 800000c: [93e4] 00 50 jmp $r0