Formally-Verified ASN.1 Protocol C-Language Stack

Formally-Verified ASN.1 Protocol C-Language Stack

Research Report: Formally-Verified ASN.1 Protocol C-language Stack Nika Pona Vadim Zaliva Digamma.ai Carnegie Mellon University Department of Electrical and Computer Engineering [email protected] [email protected] Abstract—We describe our approach and progress in verifi- TBSCertificate ::= SEQUENCE{ cation of a mature open-source ASN.1 compiler, ASN1C, using version [0] INTEGER, the Coq proof assistant. Once completed, our project will pro- serialNumber INTEGER, vide state-of-the-art high assurance suitable for mission-critical signature AlgorithmIdentifier, systems. Furthermore, since formal verification will be layered issuer Name, atop a well-tested ASN.1 stack, it will combine the benefits of subject Name, high-performance portable stack implementation with formal subjectPublicKeyInfo SubjectPublicKeyInfo, correctness guarantees. As an essential step in our approach, } the project will also provide a formalization of a key part of the ASN.1 standard. Such formal specification could subsequently be SubjectPubicKeyInfo ::= SEQUENCE{ used by others to analyze ASN.1 properties and validate other algorithm AlgorithmIdentifier, implementations. subjectPublicKey BIT STRING } I. INTRODUCTION A. Background AlgorithmIdentifier ::= SEQUENCE{ algorithm OBJECT IDENTIFIER The ASN.1 (Abstract Syntax Notation One) [1] joint stan- } dard of the International Telecommunication Union (ITU- T) and the International Organization for Standardization Name ::= SEQUENCEOF SETOF SEQUENCE{ type OBJECT IDENTIFIER, (ISO/IEC) provides an essential interface description lan- value ANY DEFINEDBY type guage for defining data structures for serialization and de- } serialization in cross-platform data exchange. ASN.1 is vitally relied upon by core aspects of the Internet infrastructure and END Internet applications, such as telephony, enterprise comput- ing, utilities, finance, military, security, digitally-controlled in- A typical ASN.1 stack consists of a compiler which parses frastructure, transportation, medical systems, and commercial ASN.1 syntax definitions, as shown in the Listing 1, and cloud computing. produces either a source code of a specialized protocol en- Using ASN.1 language, one can define data structures that coder/decoder for this data or a run-time data for a parametric use ASN.1 primitive types, such as INTEGER, BOOLEAN, protocol encoder/decoder. OBJECT IDENTIFIER, and constructed types, such as SE- B. Motivation QUENCE (OF), SET (OF), and CHOICE (OF). An exam- ple ASN.1 module that describes an X.509-like public key These days, embedded and user computing devices imple- certificate is shown in Listing 1 (revised for brevity). Such ment increasingly vast numbers of essential functions and certificates, for example, are used by every browser to access applications, many of which exchange data using ASN.1. The HTTPS web sites. The unabridged version of the original ASN.1 standard is large and complex: it currently comprises ASN.1 definition for the X.509 standard takes about 1,000 twelve sub-standards spanning 862 pages supplemented by lines of ASN.1. additional pages of corrigenda. This opens a door for many potential software bugs and malicious exploits. As a result, Listing 1: ASN.1 example of X.509 certificates the interconnected communicating systems are becoming less X509 DEFINITIONS ::= BEGIN stable and less reliable, posing greater risks and potential dangers. Disruption of the ASN.1 based communications could Certificate ::= SEQUENCE{ threaten the functioning of the entire critical infrastructure our tbsCertificate TBSCertificate, society relies upon. signatureAlgorithm AlgorithmIdentifier, signature BIT STRING The Computer Vulnerabilities and Exposures (CVE) } database [2] lists critical ASN.1-related bugs that are found each year in the existing systems. Noteworthy exposures have already been discovered [3] that clearly illuminate potential ASN.1Standard vast risk and exposure. We analyzed the last four years of ASN.1-related issues reported in the CVE database1. Among the vulnerabilities studied are CVEs for various software High-levelSpec Ocaml,Haskell and hardware products and vendors, including Apple, axTLS, Extraction Botan, Bounty Castle, librcrypto++, libtasn, LibTomCrypt, Linux Kernel, MatrixSSL, Mozilla NSS (Firefox), Objective QuickChick ExecutableSpec RoundtripProperty, StandardCompliance Systems, OpenSSL, PolarSSL, RSA BSAFE, Samba, Samsung, Snapdragon, strongSwan, and Wireshark. Out of 52 problems Memorysafety, VST Spec analyzed, 39 are related to memory safety, 6 related to Heap&StackBounds stack and heap bounds checking, and 3 are related to issues Hoare&Separationlogics caused by applications accepting poorly formed ASN.1 input. Proving just following six formal properties can prevent 49 C.AST out of 52 vulnerabilities, which is more than 90% of reported Clightgen vulnerabilities: C 1) Absence of read memory access violations (reading from memory locations outside of a permitted range). Fig. 1: Verification Architecture 2) Absence of write memory access violations (writing to memory locations outside of a permitted range). 3) Strict standard compliance (detecting not well-formed integers and lists of bytes. We prove that the E.spec encodes input) and decodes bytes in conformance with the high-level speci- 4) Guaranteed parser program termination fication. Moreover, we prove the roundtrip property for each 5) Guaranteed bounds on stack size encoder/decoder pair. 6) Guaranteed bounds on heap size From E.spec we can extract a fully functional encoder/de- coder program in languages supported by the Coq extraction C. Our approach mechanism (e.g. OCaml or Haskell) [10]. Such a possibility To date, the relevant systems and methods are either (a) is shown in the box on the right in Figure 1, although we automatically tested but not formally verified, (b) use veri- do not plan to pursue it yet. However it could be explored fication approaches which rely on automatic extraction from in the future, for example, in case we need to generate an executable specifications (for example involving network stack ASN.1 stack for special platforms where OCaml code opens synthesis [4], optimizing compilers [5], cryptographic libraries some additional opportunities for parallelization, optimization, [6], and encoder/decoders [7]), or (c) apply a form of formal or integration. One example of such platforms could be verification which only proves partial correctness properties MirageOS [11], which is an OCaml-based unikernel. (partial verification of NAT stack proving that only parts of The box at the left, marked QuickChick, represents another DPDK are specification compliant [8], partial verification of possibility we might not pursue immediately. It uses random- Linux kernel TCP implementation with 55% line coverage and ized property-based automated testing based on an executable 92% protocol coverage [9]). Consequently, (a) and (c) do not specification to further verify its correctness. This work could provide sufficient correctness guarantees, while (b) is often be done using QuickChick [12] in Coq. It could also be used impractical due to poor performance and compatibility limita- to generate a test-suite for the extracted code. tions. In contrast, we pursue a far deeper and comprehensive The next level is VST specification (VST.spec). VST stands verification approach to performance and portability and seek for Verified Software Toolchain [13], a tool that formalizes to prove actual industrial-level C-code implementation. separation logic in Coq using operational C semantics from As shown in Figure 1, the project begins with ITU-T CompCert. It provides uniform syntax for stating pre- and standard document in the form of human-readable text. We postconditions of imperative programs execution, as well as manually convert it into formal specification (H.spec). This is tactics that automatize machine arithmetic and separation logic high-level specification (in Coq) which describes the corre- proofs. VST.spec states that the C program terminates and spondence between data types and packet octets data layout. returns the machine representation of the value mandated by This specification is one of the outputs of this project and has E.spec and that it satisfies the memory specification consisting a value of its own. of pre- and post-conditions written in separation logic. Cor- The next level of refinement is executable specification respondence to the memory specification guarantees memory (E.spec). Also written in Coq, it declares “encoder” and safety. Further, we can add post-conditions about heap and “decoder” for each type as a pair of pure functions and stack bounds. basically abstracts the encoding/decoding algorithm used in At the bottom of Figure 1 is a box labeled “C” which the C function and operates on abstract types such as Coq represents the existing C code of the ASN1C compiler. Using an automated conversion provided by the clightgen tool 1See Appendix B for more details. within the CompCert C compiler [5], we convert this to 2 Abstract Syntax Trees (AST) (labeled “C.AST” in Figure 1) Although providing guarantees of correctness, this tech- rendered from a subset of C-language, called Clight [14], nique has major disadvantages. First of all, our definitions, which is recognized by Coq. More specifically, CompCert being written in pure Coq, have only one connection to the real converts C “concrete syntax” to “abstract” Clight syntax. The world - through automatic code extraction. This immediately resulting Clight program is just a reification of the original

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us