skip to main content
10.1145/1250734.1250743acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
Article

Certified self-modifying code

Published:10 June 2007Publication History

ABSTRACT

Self-modifying code (SMC), in this paper, broadly refers to anyprogram that loads, generates, or mutates code at runtime. It is widely used in many of the world's critical software systems tosupport runtime code generation and optimization, dynamic loading and linking, OS boot loader, just-in-time compilation, binary translation,or dynamic code encryption and obfuscation. Unfortunately, SMC is alsoextremely difficult to reason about: existing formal verification techniques-including Hoare logic and type system-consistentlyassume that program code stored in memory is fixedand immutable; this severely limits their applicability and power.

This paper presents a simple but novel Hoare-logic-like framework that supports modular verification of general von-Neumann machine code with runtime code manipulation. By dropping the assumption that code memory is fixed and immutable, we are forced to apply local reasoningand separation logic at the very beginning, and treat program code uniformly as regular data structure. We address the interaction between separation and code memory and show how to establish the frame rules for local reasoning even in the presence of SMC. Our frameworkis realistic, but designed to be highly generic, so that it can support assembly code under all modern CPUs (including both x86 andMIPS). Our system is expressive and fully mechanized. We prove itssoundness in the Coq proof assistant and demonstrate its power by certifying a series of realistic examples and applications-all of which can directly run on the SPIM simulator or any stock x86 hardware.

References

  1. A. W. Appel. Foundational proof-carrying code. In Proc. 16th IEEE Symp. on Logic in Computer Science, pages 247--258, June 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. W. Appel and A. P. Felty. A semantic model of types and machine instructions for proof-carrying code. In Proc. 27th ACM Symposium on Principles of Programming Languages, pages 243--253, Jan. 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. D. Aucsmith. Tamper resistant software: An implementation. In Proceedings of the First International Workshop on Information Hiding, pages 317--333, London, UK, 1996. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. V. Bala, E. Duesterwald, and S. Banerjia. Dynamo: a transparent dynamic optimization system. In Proc. 2000 ACM Conf. on Prog. Lang. Design and Implementation, pages 1--12, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. H. Cai, Z. Shao, and A. Vaynberg. Certified self-modifying code (extended version & coq implementation). Technical Report YALEU/DCS/TR-1379, Yale Univ., Dept. of Computer Science, Mar. 2007. http://flint.cs.yale.edu/publications/smc.html.Google ScholarGoogle Scholar
  6. K. Crary. Toward a foundational typed assembly language. In Proc. 30th ACM Symposium on Principles of Programming Languages, pages 198--212, Jan. 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. S. Debray and W. Evans. Profile-guided code compression. In Proc. 2002 ACM Conf. on Prog. Lang. Design and Implementation, pages 95--105, New York, NY, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. R. W. Floyd. Assigning meaning to programs. Communications of the ACM, Oct. 1967.Google ScholarGoogle ScholarCross RefCross Ref
  9. N. Glew and G. Morrisett. Type-safe linking and modular assembly language. In Proc. 26th ACM Symposium on Principles of Programming Languages, pages 250--261, Jan. 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. N. A. Hamid, Z. Shao, V. Trifonov, S. Monnier, and Z. Ni. A syntactic approach to foundational proof-carrying code. In Proc. 17th Annual IEEE Symp. on Logic in Computer Science, pages 89--100, July 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. G. M. Henry. Flexible high-performance matrix multiply via a self-modifying runtime code. Technical Report TR-2001-46, Department of Computer Sciences, The University of Texas at Austin, Dec. 2001.Google ScholarGoogle Scholar
  12. CAR. Hoare. Proof of a program: FIND. Communications of the ACM, Jan. 1971. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. L. Hornof and T. Jim. Certifying compilation and run-time code generation. Higher Order Symbol. Comput., 12(4):337--375, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. S. S. Ishtiaq and P. W. O'Hearn. BI as an assertion language for mutable data structures. In Proc. 28th ACM Symposium on Principles of Programming Languages, pages 14--26, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Y. Kanzaki, A. Monden, M. Nakamura, and Kichi Matsumoto. Exploiting self-modification mechanism for program protection. In COMPSAC '03, page 170, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. L. Lamport. The temporal logic of actions. ACM Transactions on Programming Languages and Systems, 16(3):872--923, May 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. J. Larus. SPIM: a MIPS32 simulator. v7.3, 2006.Google ScholarGoogle Scholar
  18. K. Lawton. BOCHS: IA-32 emulator project. v2.3, 2006.Google ScholarGoogle Scholar
  19. P. Lee and M. Leone. Optimizing ML with run-time code generation. In Proc. 1996 ACM Conf. on Prog. Lang. Design and Implementation, pages 137--148. ACM Press, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. H. Massalin. Synthesis: An Efficient Implementation of Fundamental Operating System Services. PhD thesis, Columbia University, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. N. G. Michael and A. W. Appel. Machine instruction syntax and semantics in higher order logic. In International Conference on Automated Deduction, pages 7--24, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. G. Morrisett, D. Walker, K. Crary, and N. Glew. From system F to typed assembly language. ACM Transactions on Programming Languages and Systems, 21(3):527--568, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. G. Necula. Proof-carrying code. In Proc. 24th ACM Symposium on Principles of Programming Languages, pages 106--119, New York, Jan. 1997. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Z. Ni and Z. Shao. Certified assembly programming with embedded code pointers. In Proc. 33rd ACM Symposium on Principles of Programming Languages, Jan. 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. P. Nordin and W. Banzhaf. Evolving turing-complete programs for a register machine with self-modifying code. In Proc. of the 6th International Conf. on Genetic Algorithms, pages 318--327, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. B. C. Pierce. Advanced Topics in Types and Programming Languages. The MIT Press, Cambridge, MA, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Ralph. Basics of SMC. http://web.archive.org/web/20010425070215/awc.rejects.net/files/text/sm%c.txt, 2000.Google ScholarGoogle Scholar
  28. J. Reynolds. Separation logic: a logic for shared mutable data structures. In Proc. 17th IEEE Symp. on Logic in Computer Science, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. F. M. Smith. Certified Run-Time Code Generation. PhD thesis, Cornell University, Jan. 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. The Coq Development Team, INRIA. The Coq proof assistant reference manual. The Coq release v8.0, 2004--2006.Google ScholarGoogle Scholar
  31. D. Yu, N. A. Hamid, and Z. Shao. Building certified libraries for PCC: Dynamic storage allocation. Science of Computer Programming, 50(1--3):101--127, Mar. 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Certified self-modifying code

                        Recommendations

                        Comments

                        Login options

                        Check if you have access through your login credentials or your institution to get full access on this article.

                        Sign in
                        • Published in

                          cover image ACM Conferences
                          PLDI '07: Proceedings of the 28th ACM SIGPLAN Conference on Programming Language Design and Implementation
                          June 2007
                          508 pages
                          ISBN:9781595936332
                          DOI:10.1145/1250734
                          • cover image ACM SIGPLAN Notices
                            ACM SIGPLAN Notices  Volume 42, Issue 6
                            Proceedings of the 2007 PLDI conference
                            June 2007
                            491 pages
                            ISSN:0362-1340
                            EISSN:1558-1160
                            DOI:10.1145/1273442
                            Issue’s Table of Contents

                          Copyright © 2007 ACM

                          Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

                          Publisher

                          Association for Computing Machinery

                          New York, NY, United States

                          Publication History

                          • Published: 10 June 2007

                          Permissions

                          Request permissions about this article.

                          Request Permissions

                          Check for updates

                          Qualifiers

                          • Article

                          Acceptance Rates

                          Overall Acceptance Rate406of2,067submissions,20%

                          Upcoming Conference

                          PLDI '24

                        PDF Format

                        View or Download as a PDF file.

                        PDF

                        eReader

                        View online with eReader.

                        eReader