vellvm verifying transforma2ons of the llvm ir
play

Vellvm: Verifying Transforma2ons of the LLVM IR Steve - PowerPoint PPT Presentation

Vellvm: Verifying Transforma2ons of the LLVM IR Steve Zdancewic Jianzhou Zhao Milo M.K. Mar2n Santosh NagarakaGe University of Pennsylvania Rutgers


  1. Vellvm: ¡Verifying ¡ Transforma2ons ¡of ¡the ¡LLVM ¡IR ¡ Steve ¡Zdancewic ¡ Jianzhou ¡Zhao ¡ Milo ¡M.K. ¡Mar2n ¡ Santosh ¡NagarakaGe ¡ University ¡of ¡Pennsylvania ¡ Rutgers ¡University ¡

  2. Mo2va2on: ¡SoHBound/CETS ¡ [NagarakaGe, ¡et ¡al. ¡ PLDI ¡ ¡’09, ¡ISMM ¡‘10 ] � • Buffer ¡overflow ¡vulnerabili2es. ¡ • Detect ¡spa2al/temporal ¡memory ¡ safety ¡viola2ons ¡in ¡legacy ¡C ¡code. ¡ • Implemented ¡as ¡an ¡LLVM ¡pass. ¡ • What ¡about ¡correctness? ¡ hGp://www.cis.upenn.edu/acg/soHbound/ ¡

  3. Mo2va2on:Compiler ¡Bugs ¡ ¡ [Yang ¡et ¡al. ¡PLDI ¡2011] ¡ Random ¡test-­‑case ¡ 79 ¡bugs: ¡ ¡ genera2on � 25 ¡cri2cal � 202 ¡bugs ¡ Source ¡ 325 ¡bugs ¡in ¡ Programs ¡ LLVM ¡ total ¡ {8 ¡other ¡C ¡compilers} � Verified ¡Compila2on: ¡ ¡Compcert ¡ ¡[Leroy ¡et ¡al.] ¡ ¡ ¡ ¡ ¡(Not ¡directly ¡applicable ¡to ¡LLVM) ¡

  4. LLVM ¡Compiler ¡Infrastructure ¡ [LaGner ¡et ¡al. ¡] ¡ LLVM ¡ Typed ¡SSA ¡ Front ¡ Code ¡ IR � Ends ¡ Gen/Jit ¡ Op2miza2ons/ ¡ Transforma2ons � Analysis �

  5. LLVM ¡Compiler ¡Infrastructure ¡ [LaGner ¡et ¡al.] ¡ LLVM ¡ Typed ¡SSA ¡ Front ¡ Code ¡ IR � Ends ¡ Gen/Jit ¡ Op2miza2ons/ ¡ Transforma2ons � Analysis �

  6. The ¡Vellvm ¡Project ¡ [Zhao ¡et ¡al. ¡POPL ¡2012, ¡CPP ¡2012, ¡PLDI ¡2013] ¡ • Formal ¡seman2cs ¡ • Facili2es ¡for ¡crea2ng ¡ simula2on ¡proofs ¡ Typed ¡SSA ¡ • Implemented ¡in ¡Coq ¡ IR � • Extract ¡passes ¡for ¡use ¡ with ¡LLVM ¡compiler ¡ Op2miza2ons/ ¡ • Example: ¡verified ¡ Transforma2ons � memory ¡safety ¡ instrumenta2on ¡ Analysis �

  7. Vellvm ¡Framework ¡ Coq ¡ Type ¡System ¡ Opera2onal ¡ and ¡SSA ¡ Seman2cs ¡ Memory ¡ Syntax ¡ Model ¡ Proof ¡Techniques ¡& ¡Metatheory ¡ Extract ¡ OCaml ¡Bindings ¡ LLVM ¡ Printer ¡ Parser ¡ C ¡Source ¡ LLVM ¡ LLVM ¡ Other ¡ Target � Transform � Code � IR � IR � Op2miza2ons �

  8. Vellvm ¡Framework ¡ Coq ¡ Type ¡System ¡ Opera2onal ¡ and ¡SSA ¡ Seman2cs ¡ Memory ¡ Syntax ¡ Model ¡ Proof ¡Techniques ¡& ¡Metatheory ¡ Extract ¡ Verified ¡ Transform � OCaml ¡Bindings ¡ LLVM ¡ Printer ¡ Parser ¡ C ¡Source ¡ LLVM ¡ LLVM ¡ Other ¡ Target � Code � IR � IR � Op2miza2ons �

  9. Plan ¡ • Tour ¡of ¡the ¡LLVM ¡IR ¡ ¡ • Vellvm ¡infrastructure ¡ – Opera2onal ¡Seman2cs ¡ – SSA ¡Metatheory ¡+ ¡Proof ¡Techniques ¡ • Case ¡studies: ¡ – SoHBound ¡memory ¡safety ¡ – mem2reg ¡ • Conclusion ¡

  10. ¡LLVM ¡IR ¡by ¡Example ¡ entry: Control-­‑flow ¡Graphs: ¡ r 0 = ... r 1 = ... + ¡Labeled ¡blocks ¡ ¡ ¡ r 2 = ... loop: r 3 = ... r 4 = r 1 x r 2 r 5 = r 3 + r 4 r 6 = r 5 ≥ 100 exit: r 7 = ... r 8 = r 1 x r 2 r 9 = r 7 + r 8

  11. ¡LLVM ¡IR ¡by ¡Example ¡ entry: Control-­‑flow ¡Graphs: ¡ r 0 = ... r 1 = ... + ¡Labeled ¡blocks ¡ ¡ ¡ r 2 = ... + ¡Binary ¡Opera2ons ¡ loop: r 3 = ... r 4 = r 1 x r 2 r 5 = r 3 + r 4 r 6 = r 5 ≥ 100 exit: r 7 = ... r 8 = r 1 x r 2 r 9 = r 7 + r 8

  12. ¡LLVM ¡IR ¡by ¡Example ¡ entry: Control-­‑flow ¡Graphs: ¡ r 0 = ... r 1 = ... + ¡Labeled ¡blocks ¡ ¡ ¡ r 2 = ... + ¡Binary ¡Opera2ons ¡ br r 0 loop exit + ¡ Branches/Return ¡ loop: r 3 = ... r 4 = r 1 x r 2 r 5 = r 3 + r 4 r 6 = r 5 ≥ 100 br r 6 loop exit exit: r 7 = ... r 8 = r 1 x r 2 r 9 = r 7 + r 8 ret r 9

  13. ¡LLVM ¡IR ¡by ¡Example ¡ entry: Control-­‑flow ¡Graphs: ¡ r 0 = ... r 1 = ... + ¡Labeled ¡blocks ¡ ¡ ¡ r 2 = ... + ¡Binary ¡Opera2ons ¡ br r 0 loop exit + ¡ Branches/Return ¡ + ¡Sta2c ¡Single ¡Assignment ¡ loop: r 3 = ... r 4 = r 1 x r 2 ¡ ¡ ¡(each ¡variable ¡assigned ¡ r 5 = r 3 + r 4 r 6 = r 5 ≥ 100 ¡ ¡ ¡ ¡only ¡ once , ¡sta2cally) ¡ br r 6 loop exit exit: r 7 = ... r 8 = r 1 x r 2 r 9 = r 7 + r 8 ret r 9

  14. ¡LLVM ¡IR ¡by ¡Example ¡ entry: Control-­‑flow ¡Graphs: ¡ r 0 = ... r 1 = ... + ¡Labeled ¡blocks ¡ ¡ ¡ r 2 = ... + ¡Binary ¡Opera2ons ¡ br r 0 loop exit + ¡Branches/Return ¡ + ¡Sta2c ¡Single ¡Assignment ¡ loop: r 3 = φ [0;entry][r 5 ;loop] + ¡φ ¡nodes ¡ r 4 = r 1 x r 2 r 5 = r 3 + r 4 r 6 = r 5 ≥ 100 br r 6 loop exit exit: r 7 = φ [0;entry][r 5 ;loop] r 8 = r 1 x r 2 r 9 = r 7 + r 8 ret r 9

  15. ¡LLVM ¡IR ¡by ¡Example ¡ entry: Control-­‑flow ¡Graphs: ¡ r 0 = ... r 1 = ... + ¡Labeled ¡blocks ¡ ¡ ¡ r 2 = ... + ¡Binary ¡Opera2ons ¡ br r 0 loop exit + ¡Branches/Return ¡ + ¡Sta2c ¡Single ¡Assignment ¡ loop: r 3 = φ [0;entry][r 5 ;loop] + ¡φ ¡nodes ¡ r 4 = r 1 x r 2 r 5 = r 3 + r 4 r 6 = r 5 ≥ 100 ¡ ¡(choose ¡values ¡based ¡ br r 6 loop exit ¡ ¡ ¡on ¡predecessor ¡blocks) ¡ exit: r 7 = φ [0;entry][r 5 ;loop] r 8 = r 1 x r 2 r 9 = r 7 + r 8 ret r 9

  16. Plan ¡ • Tour ¡of ¡the ¡LLVM ¡IR ¡ ¡ • Vellvm ¡infrastructure ¡ – Opera2onal ¡Seman2cs ¡ – SSA ¡Metatheory ¡+ ¡Proof ¡Techniques ¡ • Case ¡studies: ¡ – SoHBound ¡memory ¡safety ¡ – mem2reg ¡ • Conclusion ¡

  17. Structured ¡Data ¡in ¡LLVM ¡ • LLVM’s ¡IR ¡is ¡uses ¡types ¡to ¡describe ¡the ¡structure ¡of ¡data. ¡ ty ::= � � N-­‑bit ¡integers ¡ | � i1 | i8 | i32 |… � � | � [ <#elts> x t ] � arrays ¡ � � � � func>on ¡types ¡ � | � r (ty 1 , ty 2 , … , ty n ) � � structures ¡ | � {ty 1 , ty 2 , … , ty n } � � pointers ¡ | � ty* � � � � � � � named ¡(iden>fied) ¡type ¡ | � %Tident � � � � � Return ¡Types ¡ r ::= � � � ty ¡ ¡ ¡ first-­‑class ¡type ¡ � no ¡return ¡value ¡ � void � • <#elts> ¡is ¡an ¡integer ¡constant ¡>= ¡0 ¡ • (Recursive) ¡Structure ¡types ¡can ¡be ¡named ¡at ¡the ¡top ¡level: ¡ %T1 = type {ty 1 , ty 2 , … , ty n } ¡ 17 ¡

  18. LLVM’s ¡memory ¡model ¡ %ST = type {i10,[10 x i8*]} � High-­‑level ¡ • Manipulate ¡structured ¡types. ¡ Representa2on ¡ %val = load %ST* %ptr � i10 ¡ … � i8* ¡ store %ST* %ptr, %new � i8* ¡ i8* ¡ i8* ¡ i8* ¡ i8* ¡ i8* ¡ i8* ¡ i8* ¡ i8* ¡

  19. LLVM’s ¡memory ¡model ¡ %ST = type {i10,[10 x i8*]} � Low-­‑level ¡ Representa2on ¡ High-­‑level ¡ • Manipulate ¡structured ¡types. ¡ b(10, ¡136) ¡ 0 ¡ Representa2on ¡ 1 ¡ b(10, ¡2) ¡ %val = load %ST* %ptr � i10 ¡ 2 ¡ uninit ¡ … � i8* ¡ 3 ¡ store %ST* %ptr, %new � uninit ¡ i8* ¡ 4 ¡ ptr(Blk32,0,0) ¡ i8* ¡ • Seman2cs ¡is ¡given ¡in ¡terms ¡of ¡ 5 ¡ ptr(Blk32,0,1) ¡ i8* ¡ 6 ¡ ptr(Blk32,0,2) ¡ byte-­‑oriented ¡low-­‑level ¡ i8* ¡ 7 ¡ ptr(Blk32,0,3) ¡ memory. ¡ i8* ¡ 8 ¡ ptr(Blk32,8,0) ¡ i8* ¡ – padding ¡& ¡alignment ¡ 9 ¡ ptr(Blk32,8,1) ¡ i8* ¡ – physical ¡subtyping ¡ 10 ¡ ptr(Blk32,8,2) ¡ i8* ¡ 11 ¡ ptr(Blk32,8,3) ¡ i8* ¡ 12 ¡ … ¡ … ¡ … ¡

  20. Adap2ng ¡CompCert’s ¡Memory ¡Model ¡ ✗ ¡ Blk0 ¡ Blk1 ¡ • Code ¡lives ¡in ¡blocks ¡ b(10, ¡136) ¡ 0 ¡ • Represent ¡pointers ¡abstractly ¡ 1 ¡ b(10, ¡2) ¡ 2 ¡ – block ¡+ ¡offset ¡ ¡ uninit ¡ 3 ¡ uninit ¡ • Deallocate ¡by ¡invalida2ng ¡ 4 ¡ ptr(Blk32,0,0) ¡ blocks ¡ ¡ 5 ¡ ptr(Blk32,0,1) ¡ • Allocate ¡by ¡crea2ng ¡new ¡ 6 ¡ ptr(Blk32,0,2) ¡ 7 ¡ ptr(Blk32,0,3) ¡ blocks ¡ 8 ¡ ptr(Blk32,8,0) ¡ – infinite ¡memory ¡available ¡ 9 ¡ ptr(Blk32,8,1) ¡ 10 ¡ ptr(Blk32,8,2) ¡ 11 ¡ ptr(Blk32,8,3) ¡ 12 ¡ … ¡ … ¡ … ¡

  21. Adap2ng ¡CompCert’s ¡Memory ¡Model ¡ Blk32 ¡ Blk0 ¡ Blk1 ¡ b(10, ¡136) ¡ 0 ¡ b(16, ¡1) ¡ 0 ¡ 1 ¡ 1 ¡ b(10, ¡2) ¡ b(16, ¡0) ¡ 2 ¡ 2 ¡ uninit ¡ uninit ¡ 3 ¡ 3 ¡ uninit ¡ uninit ¡ 4 ¡ 4 ¡ ptr(Blk32,0,0) ¡ uninit ¡ 5 ¡ 5 ¡ ptr(Blk32,0,1) ¡ uninit ¡ 6 ¡ 6 ¡ ptr(Blk32,0,2) ¡ uninit ¡ 7 ¡ 7 ¡ ptr(Blk32,0,3) ¡ uninit ¡ 8 ¡ 8 ¡ ptr(Blk32,8,0) ¡ ptr(Blk1,0,0) ¡ 9 ¡ 9 ¡ ptr(Blk32,8,1) ¡ ptr(Blk1,0,1) ¡ 10 ¡ 10 ¡ ptr(Blk32,8,2) ¡ ptr(Blk1,0,2) ¡ 11 ¡ 11 ¡ ptr(Blk32,8,3) ¡ ptr(Blk1,0,3) ¡ 12 ¡ 12 ¡ … ¡ … ¡ … ¡ … ¡ … ¡ … ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend