290 likes | 450 Views
An Open Framework for Foundational Proof-Carrying Code. Xinyu Feng Yale University Joint work with Zhaozhong Ni (Yale, now at MSR), Zhong Shao (Yale) and Yu Guo (USTC). Libraries and runtime. +. Motivation. How to build fully certified software systems?. Source-level code.
E N D
An Open Framework for Foundational Proof-Carrying Code Xinyu Feng Yale University Joint work with Zhaozhong Ni (Yale, now at MSR), Zhong Shao (Yale) and Yu Guo (USTC)
Libraries and runtime + Motivation How to build fully certified software systems? Source-level code References with weak upd. Garbage collectors Dynamic mem. alloc. malloc() (strong update) Functions, exceptions, … Stacks, code pointers Concurrency Context switching & Scheduler Device drivers I/O
[Yu&Shao, ICFP’04] Motivation • All concurrency verification assumes built-in concurrency • Assume-Guarantee (A-G) reasoning • Concurrent Separation logic (CSL) • … • Context switching, scheduler • Too low-level to be certified in these logics • Threads & schedulers have never been modularly certified!
Motivation • Certify all code in a single type system/program logic? • Hard to combine all features • weak vs. strong update, functions/exceptions vs. goto’s, threads vs. thread contexts • May not be modular • Very complex, hard to use • Don’t know how to design such a logic • Certify modules using the most appropriate logic! • Modules do not use all the features at the same time • It is simpler to use specialized logic for each module
An Open Framework Certify different modules using different verification systems!
Not readily supported in Coq! Challenges • Extensibility and openness • not designed for certain specific interoperations But can we just use MLFs, e.g. Coq? • Expressiveness • type safety, concurrency properties, partial correctness, … • A general and uniform model of control flow • Allow functions certified in different systems to call each other • the key for modularity: separate verification & proof reuse • Principled interoperation with clear meta-property • properties of the whole system composed of modules
Our contributions • OCAP: an open framework • Embedding of different systems • TAL, non-CPS Hoare-logic, A-G reasoning, … • Open & Extensible • Modularity with first-class code pointers [Ni&Shao POPL’06] • Soundness • Type safety, & preservation of invariants in foreign systems • Applications • TAL + memory allocation libs. • Threads + Scheduler • The first time to modularly certify both sides • …
Outline • OCAP Framework • Certifying Threads & Schedulers
… C1 Cn L1 Ln … Sound ( )L1 ( )Ln Modeling of the machine TCB Mechanized Meta-Logic (CiC) OCAP : Overview Sound OCAP Rules OCAP Soundness Modeling of the machine Mechanized Meta-Logic (CiC)
The Machine (data heap) H f1: I1 addu … lw … sw … … j f pc 0 1 2 … f2: I2 r1 r2 r3 … rn f3: I3 (register file) R … (code heap) C (state) S ::=(H,R) (instr. seq.) I ::={fI}* (program) P ::=(C,S,pc)
The OCAP Logic : Overview • Hoare-style program logic for assembly • CPS-style reasoning • Assign a precondition to each basic block • Similar to TAL [Morrisett et al. POPL’98]
a1 a2 a3 The OCAP Logic : Overview (spec) ::={fa}* (data heap) H f1: I1 a addu … lw … sw … … j f pc 0 1 2 … f2: I2 r1 r2 r3 … rn f3: I3 (register file) R … (code heap) C (state) S ::=(H,R) (instr. seq.) I ::={fI}* (program) P ::=(C,S,pc)
codeptr a OCAP: Code pointers Support of first-class code pointers: codeptr(f,a) (f) = a (Spec) ::= {f a}* Not well-founded!
A generic specification: (CdSpec) ::=… codeptr (Spec) ::= {f }* a (Assert)a Spec State Prop () ,S. … codeptr () a OCAP: Code Pointers No interoperation between multiple systems…
OCAP: Foreign Languages (LangTy) L::= CiC Terms Type (CodeSpec) ::= CiC Terms L Inductive TalType : Type := T_int : TalType T_pair: TalType -> TalType-> TalType … Inductive Tal2Type : Type := T2_int : TalType T2_pair: TalType -> TalType-> TalType … L::= TalType | Tal2Type | … 1 ::= T_int | T_pair 11| … TalType 2 ::= T2_int | T2_pair 22| … Tal2Type
a ( )L OCAP: Specifications (LangTy)L::= CiC Terms Type (CodeSpec) ::= CiC Terms L (Interp)( )LL Assert (OCdSpec) ::= <L,( )L,> L.(L Assert)*L (Spec)::={(f1,1), … (fn,n)} (Assert)a Spec State Prop Not well-founded:
a ( )L OCAP: Specifications (LangTy)L::= CiC Terms Type (CodeSpec) ::= CiC Terms L (Interp)( )LL Assert (OCdSpec) ::= <,L,( )L,> (Spec)::={(f1,1), … (fn,n)} (Assert)a Spec State Prop (LangID)::= n nat (LangDict)D ::= {1<L1,( )L1>,…, n<Ln,( )Ln>} LangID (L.L Assert)
Selected OCAP Rules D1;1┝ C1:1’ D2;2┝ C2:2’ … (link) D1D2; 12┝ C1C2 : 1’2’ ,S.a S .(codeptr(S.R(r),)a’) S a’ = [[[ ]]]D (jr) D┝ {a}jr r codeptr(f,) ,S. (f)= [[[ ]]]D,S. ( )L.(D()=<L,( )L>)(()L S) = <,L,>
Outline • OCAP Framework • Certifying Threads & Schedulers
Threads and Scheduler • Thread code C1,…,Cn • Certified following CCAP [Yu&Shao, ICFP’04] • Assume-Guarantee reasoning • Thread modularity • Do not know about thread queue • Scheduler CS • Certified in SCAP [Feng et al. PLDI’06] • as sequential code • Manages thread queue TQ • Do not touch H SCAP CCAP +
r0 r31 H1 … pc1 pcn TQ r0 r31 H1 … pc1 pcn TQ Scheduler in SCAP ct Thread code: … jal yield ct: … yield: pick one word (pci) from TQ swap pci and r31 jr r31 ct
r0 r31 H1 … pc1 pcn TQ r0 gs (r{r1,…,r30}.[r]=[r]’) Q, Q’. p’. Q{[r31]} = Q’{[r31]’} r31 WFTQ(Q)*p’ H1 … pc1 pcn WFTQ(Q’)*p’ TQ Scheduler in SCAP ct yield: (ps, gs) pick one word (pci) from TQ swap pci and r31 jr r31 gs ps Q.WFTQ(Q) * True ct
Embedding SCAP D p ((p,g))Dscap … Soundness: … g scap┝scapC:’scap jr $ra (scap)Dscap D Dscap,┝ C:’ ’ (’scap)Dscap Dscap {scap <Lscap, (_)scap> }
p1 p2 S S’ p’1 p2 ? Threads: Assume-Guarantee A1, G1 A2, G2 Spec. for threads: (p, A, G) p: State Prop A, G: State State Prop A2 G1 Stability of p: pi S Ai S S’ pi S’
CCAP embedding ((p,A,G))ccap ,S. … Dall {ccap <Lccap, (_)ccap>, scap <Lscap, (_)scap> } ccap┝ccapCi:’ccap Dall;cy┝ Ci: ’c c (ccap) ccap ’c (’ccap) ccap y {yield <scap ,Lscap,(ps, gs)>}
the “link” rule Certify the code Dall {ccap <Lccap, (_)ccap>, scap <Lscap, (_)scap> } SCAP CCAP scap┝scapCs:’scap ccap┝ccapCi:’ccap Dall;y┝ Cs: ’y Dall;cy┝ Ci: ’c Dall; cy┝ Ci Cs: ’c ’y
Summary • It is simpler and natural to certify different modules using different logics • OCAP: framework for interoperation • Embedding • TAL: type system • SCAP: non-cps logic for assembly • CCAP: Assume-guarantee reasoning • Interoperation • TAL + newpair • Threads + Scheduler • TAL + GC (ongoing work by Lin, McCreight, et al.)
Future work • Explore the applicability of OCAP • Interoperation of different languages • Currently just for assembly language • But logics are at different levels (TAL, CCAP, …) • May support C + inlined assembly