construction of a semantic model construction of a
play

Construction of a Semantic Model Construction of a Semantic Model - PowerPoint PPT Presentation

Construction of a Semantic Model Construction of a Semantic Model for a Typed Assembly Language Gang Tan, Andrew Appel, Kedar Swadi and Dinghao Wu Princeton University Jan 11, 2004 Extensible systems Extensible systems code extensions host


  1. Construction of a Semantic Model Construction of a Semantic Model for a Typed Assembly Language Gang Tan, Andrew Appel, Kedar Swadi and Dinghao Wu Princeton University Jan 11, 2004

  2. Extensible systems Extensible systems code extensions host Applet, plug-in Web browser Device drivers Operating system Packet filters Routers VB Add-ins PowerPoint 2 VMCAI 04

  3. Security concerns Security concerns code host How to give this untrusted code direct access without violating host’s safety policy? g f y p y We consider the case of machine/assembly code 3 VMCAI 04

  4. Typed Assembly Languages (TAL) yp y g g ( ) [Morrisett, Walker, Crary and Glew 1999] φ 0 L 0 : B 0 φ 1 L 1 : B B 1 Type Cheker M h host φ n L n : B n • Loop invariants – in terms of types – generated by a compiler • Type checks the assembly code yp y 4 VMCAI 04

  5. TAL type checking TAL type checking φ 0 L 0 : B 0 φ 1 φ L : L 1 : Γ B 1 C M M φ n L n : B n n • Hoare-logic style checking: pre- and postconditions oa e og c sty e c ec g: p e a d postco d t o s 5 VMCAI 04

  6. Checking instructions Checking instructions φ 0 L 0 : φ 1 L 1 : M φ n φ n M L n : n Can we trust these rules! 6 VMCAI 04

  7. Can we trust these typing rules? Can we trust these typing rules? • For small systems, maybe yes. • Production-scale low-level type systems • Production-scale low-level type systems – Huge: LTAL by Chen et al. has 1200 operators & rules! – Complex: because of intricate machine semantics Complex: because of intricate machine semantics • Think about condition code types – We routinely find and fix bugs in its early versions We routinely find and fix bugs in its early versions 7 VMCAI 04

  8. The type safety theorem The type-safety theorem Type Type Cheker host host 8 VMCAI 04

  9. Semantic model approach Semantic model approach • A classic idea: give a model in some logic so • A classic idea: give a model in some logic so that the rule can be proved as a lemma 9 VMCAI 04

  10. What we need to model What we need to model Previous work This talk • Models for safety of code, instructions, types, … – [Appel & Felty 2000, Michael & Appel 2000] pp y pp • We also need models for typing judgments • Goal: give models to typing judgments – Prove all the typing rules as derived lemmas P ll h i l d i d l – Verify the type-safety theorem 10 VMCAI 04

  11. Axiomatization of Sparc machine A i ti ti f S hi • Our step relation is deliberately partial O l i i d lib l i l – Omit any steps that would violate the safety policy • Mixing of machine semantics and safety policy is to follow standard practice in type theory 11 VMCAI 04

  12. Safety definition Safety definition • A state is safe for k steps • Safe code r m a a a L 12 VMCAI 04

  13. codeptr types codeptr types • Address l has type codeptr( φ ) if it is safe to pass the p ( φ ) yp p control to l, provided that φ is satisfied – Safety within k steps • ( m,l ) : codeptr( φ ) ≡ ∀ k . ( m,l ) : k codeptr( φ ) – Safe for any number of steps 13 VMCAI 04

  14. Constructing a safety proof Constructing a safety proof φ 0 L 0 : φ 1 L 1 : M φ n L n : • The goal: safe_state( k,r,m ) for any natural number k – ∀ k . ( m , L 0 ) : k codeptr( φ 0 ) • Do it by induction – safe_state(0, r,m ) is vacuously true – safe_state( k,r,m ) ⇒ safe_state( k +1, r,m ) ? (need a stronger induction hypothesis!) 14 VMCAI 04

  15. Simultaneous induction over all labels Simultaneous induction over all labels φ 0 L 0 : φ 1 L 1 : M φ n L n : • The goal ∀ k . ( m , L 0 ) : codeptr( φ 0 ) p ( φ 0 ) g ( , 0 ) • Induction hypothesis: ∀ l ,k . ( m , l ) : k codeptr( φ l ) – simultaneously prove that all labels are safe for k steps simultaneously prove that all labels are safe for k steps 15 VMCAI 04

  16. An example of the inductive case An example of the inductive case • Prove ( m ,4) : k+ 1 codeptr( φ 4 ) • Induction hypothesis has yp – ( m ,0) : k codeptr( φ 0 ) r m r’ m’ int int int int a a k M M 4 pc pc . . . . . . . 16 VMCAI 04

  17. The model of instruction judgment • For any state ( r,m ) and k such that – (r, m ) : φ – Instruction i is at location l – ( m , l + 4) : k codeptr( φ 0 ) and m : k Γ • Prove that ( m , l ) : k+ 1 codeptr( φ ) 17 VMCAI 04

  18. The model of The model of • m : Δ (C) is to describe the program in the memory m : Δ (C) is to describe the program in the memory • m : Γ means that the program respects all the loop invariants • The model can be written as – If we define Δ( C) ( ) Γ Γ 18 VMCAI 04

  19. The type safety theorem The type-safety theorem 19 VMCAI 04

  20. Implementations Implementations • Successfully defined the models of typing judgments in LTAL • Proved the type safety theorem and the typing rules of instructions • All the proofs are implemented in Twelf and machine checkable machine checkable 20 VMCAI 04

  21. FPCC system FPCC system Compiler 170,000 lines in ML TYPED ASSEMBLY LANGUAGE model of judgments; subtyping subtyping proof of f f theorems typing rules TYPED MACHINE LANGUAGE 1 120,000 lines in Twelf l lf abstract model of types instruction nstruct on s instruction machine states decoder 2,000 lines in Twelf Sparc Logic spec. 21 VMCAI 04

  22. Related work Related work • Proof of the type safety theorem – Necula had 12 pages in his thesis – The TAL paper by Morrisett et al. had 8 pages – Paper proofs; not machine checked Paper proofs; not machine checked – Not proofs about their implemented systems • A syntactic approach to prove type soundness [Hamid et al. 2002 , Crary 2003] – Type soundness theorem based on an abstract machine – A simulation relation between the abstract machine and the real A simulation relation between the abstract machine and the real machine • Models for unstructured programs with goto statements and l b l labels [de Bruin 1981] – Domain-theoretic models – k -th approximations of code behavior respects invariants k th approximations of code behavior respects invariants 22 VMCAI 04

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