A Verified Protocol Buffer Compiler

A Verified Protocol Buffer Compiler

A Verified Protocol Buffer Compiler Qianchuan Ye Benjamin Delaware Purdue University Purdue University USA USA [email protected] [email protected] Abstract 1 Introduction The code responsible for serializing and deserializing un- Serialization is the process of encoding structured data into trusted external data is a vital component of any software a binary representation according to a standardized format, that communicates with the outside world, as any bugs in usually in order to communicate with some external client these components can compromise the entire system. This is or for persistent storage. In the case of distributed systems, particularly true for verified systems which rely on trusted serialized data is used to exchange messages, perform remote code to process external data, as any defects in the parsing procedure calls, and orchestrate synchronization. Failure to code can invalidate any formal proofs about the system. One produce or correctly interpret encoded data can result in way to reduce the trusted code base of these systems is to lost or corrupted data, potentially placing the system into an use interface generators like Protocol Buffer and ASN.1 to inconsistent state. Given their importance, serializers and de- generate serializers and deserializers from data descriptors. serializers are particularly ripe targets for formal verification. Of course, these generators are not immune to bugs. This is especially true when serialization and deserialization In this work, we formally verify a compiler for a realistic code is included in the trusted code of a formally verified subset of the popular Protocol Buffer serialization format system, as bugs in those components can compromise the using the Coq proof assistant, proving once and for all the assurance case for the entire system [13]. correctness of every generated serializer and deserializer. There are no shortage of standardized serialization for- One of the challenges we had to overcome was the extreme mats in the wild, including protocol-specific formats like flexibility of the Protocol Buffer format: the same source TCP/IP and DNS [21, 23, 24], language-specific marshaling data can be encoded in an infinite number of ways, and the libraries [14, 20], human readable formats like JSON [6] and deserializer must faithfully recover the original source value XML [7], and interface generators like ASN.1 [12] and Pro- from each. We have validated our verified system using the tocol Buffers30 [ ]. Interface generators are particularly pop- official conformance tests. ular for application developers [16], because they offer a general-purpose, language-independent solution to serializa- CCS Concepts • Theory of computation → Program tion, while producing a more compact encoding than human verification; • Software and its engineering → Software readable formats. These systems provide a domain-specific verification; Source code generation; language in which users can describe their application’s data types, as well as a compiler for building a library of data type Keywords Serialization, Program verification, Coq definitions, methods to manipulate those data types, and ACM Reference Format: serializer and deserializers in a desired target language. Del- Qianchuan Ye and Benjamin Delaware. 2019. A Verified Protocol egating the generation of this library to a compiler removes Buffer Compiler. In Proceedings of the 8th ACM SIGPLAN Interna- the possibility of user-introduced bugs in serialization and tional Conference on Certified Programs and Proofs (CPP ’19), January deserialization code, but these compilers may themselves 14–15, 2019, Cascais, Portugal. ACM, New York, NY, USA, 12 pages. have bugs. Numerous security vulnerabilities have been re- https://doi.org/10.1145/3293880.3294105 ported for various ASN.1 compilers in MITRE’s Common Vulnerability Enumeration (CVE) [1–3]. Thus, removing the generated serializers and deserializers from the trusted code Permission to make digital or hard copies of all or part of this work for base is an important piece of building high-assurance sys- 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 tems that rely on interface generators. this notice and the full citation on the first page. Copyrights for components In this paper, we do just that, verifying a Protocol Buffer of this work owned by others than ACM must be honored. Abstracting with compiler once and for all. This proof is parameterized over credit is permitted. To copy otherwise, or republish, to post on servers or to the data schema, such that we can derive functional correct- redistribute to lists, requires prior specific permission and/or a fee. Request ness proofs for the serializer and deserializer generated for permissions from [email protected]. an arbitrary data description. One of the challenges here is CPP ’19, January 14–15, 2019, Cascais, Portugal © 2019 Association for Computing Machinery. that the Protocol Buffer standard was designed with flex- ACM ISBN 978-1-4503-6222-1/19/01...$15.00 ibility, not verification, in mind. It imposes all the typical https://doi.org/10.1145/3293880.3294105 CPP ’19, January 14–15, 2019, Cascais, Portugal Qianchuan Ye and Benjamin Delaware challenges of verifying handwritten serializer and deseri- ~Timestamp⟧ is the Coq type of messages denoted by the alizer functions and more. Firstly, both the signature and descriptor Timestamp; Section 3 provides the complete de- the implementations of the generated functions are highly tails of this denotation function. We can use Coq’s extraction dependent on the supplied data description. Secondly, the mechanism to extract executable OCaml implementations format is highly flexible, such that the same structured data of encode_timestamp and decode_timestamp. value can be encoded into many different binary strings; a We have proven soundness theorems for encode_message correct deserializer must be able to recover this value from and decode_message too, which can be instantiated with a each of these. To overcome these challenges, we have made concrete message descriptor: the following contributions: Theorem encode_timestamp_correct B • We have formalized a practical subset of version 3 of encode_message_correct Timestamp. the Protocol Buffer standard in Coq [28], capturing its Theorem decode_timestamp_correct B dependent data representations and its flexible encod- decode_message_correct Timestamp. ing strategy. The statements of these soundness theorems are given in • We have implemented serializer and deserializer gen- Section 4. These theorems can be used to prove end-to-end erators, and proved them functionally correct with correctness of a larger verified system that makes use of respect to the standard. these implementations. • We have evaluated our implementation by extracting The rest of the paper proceeds as follows: we begin by OCaml implementations of a serializer and deserializer highlighting the flexibility of the Protocol Buffer format be- for the reference example in Protocol Buffer’s official fore giving its complete specification. We then discuss the repository [17]. In addition, we have used the official generation of and soundness proofs for serializers and dese- conformance tests to validate that our formalization rializers in Section 4. In Section 5, we evaluate our system faithfully captures Protocol Buffer’s informal specifi- by implementing a reference example, which we validate cation. using the official conformance test. Section 6 presents related Our system is available in an accompanying code supple- work before a discussion of future work in Section 7, which ment. is followed by the conclusion. Key to our approach is a decomposition of the specification of the format into two separate layers which progressively 2 An Introduction to Protocol Buffers relate a structured data value to its possible encodings. We We begin with a brief introduction to Protocol Buffers, in then construct serializers and deserializers by composing to- order to give readers an intuition of the format. To define gether verified implementations for each of the intermediate the shape of a Protocol Buffer message, a user provides a layers, so that we are able to decompose the “end-to-end” message descriptor in a “.proto” file that is fed to a Protocol correctness proof into proofs of correctness for each of the Buffer compiler. The message descriptor for the timestamp layers. This allows us to cleanly separate the representation example from Section 1 is as follows: of multiple encodings of a value from the specification of message Timestamp { the bit-level representation of the encoded data, as Section 3 int64 seconds = 1; will discuss in more detail. int32 nanos = 2; In order to concretize our discussion, we begin with an } example of how our system can be used to derive serializ- In this example, the first line specifies the name of the ers and deserializers from a data description. In Protocol data type: Timestamp. Inside the curly brackets, each line Buffers, this description is typically called a message descrip- defines a field of this data type, which consists of the type, the tor, and the structured values it describes are called messages. name and the tag of this field. The next section will discuss Consider the following simple descriptor for a timestamp the types of fields in more detail. Names of fields areonly message: used by the users to access or update these fields

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 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