Constant-Time Webassembly

Constant-Time Webassembly

Constant-Time WebAssembly John Renner, Sunjay Cauligi, and Deian Stefan UC San Diego Abstract crypto libraries do not provide constant-time guarantees and, As ever more applications are designed to run inside browsers unfortunately, are still at the mercy of the JavaScript GC [6]. and other JavaScript runtime systems, there is an increasing We argue that high-level runtime systems (e.g., Chrome or need for cryptographic primitives that can be used client-side. Electron) should make it possible for developers to express Unfortunately, implementing cryptographic primitives se- and securely execute computations on secret data. In par- curely in high-level languages is extremely difficult—runtime ticular, developers should be able to declare which data are system components such as garbage collectors and just-in- sensitive and implement cryptographic algorithms without time compilers can trivially introduce timing leaks in seem- worrying about the underlying runtime system introducing ingly secure code. We argue that runtime system designs covert timing channels or optimizing away security-critical should be rethought with such applications—applications code (e.g., secret-memory erasing code) [8]. that demand strong guarantees for the executed code—in Retrofitting JavaScript runtimes to ensure that the high- mind. As a concrete step towards this goal, we propose level semantics of secure computations are preserved when changes to the recent WebAssembly language and runtime executed is, at best, a daunting task. Luckily, most browsers system, supported by modern browsers. Our Constant-Time have added support for WebAssembly (wasm)—a strongly- WebAssembly enables developers to implement crypto algo- typed, low-level machine language [4, 9]. By extending this rithms whose security guarantees will be preserved through still-evolving language with data security types [15], and by compiler optimizations and execution in the browser. retrofitting the still-simple wasm compilers and execution engines to respect these types, we can provide a means for 1 Introduction developers to write secure cryptographic computations in the context of high-level runtime systems. Modern application development has largely migrated to To this end, we outline three extensions to wasm: First, JavaScript and the Web platform. Even desktop applications we extend the wasm language and type system to add sup- (e.g., Spotify, Slack, Visual Studio Code) are now simply Java- port for secret integer values and memory spaces. Second, Script and HTML bundled with a browser-rendering engine.1 we extend the wasm validator, which ensures that wasm While this affords many benefits, secure applications that code is well-formed, to additionally ensure that code does demand encryption (e.g., Signal, Cryptocat, Keybase) are not leak secrets via data or control flow. Finally, we modify notoriously difficult to implement. the wasm execution environment to ensure that these high- Writing secure cryptographic code in low-level languages level security guarantees are preserved during execution, like C, where developers have total control over program even in the presence of low-level compiler optimizations. execution, is challenging; writing secure code in a language We call this modified language and runtime Constant-Time like JavaScript is even more so. To ensure that code handling WebAssembly (ct-wasm). secrets runs in constant time or that secrets are securely erased, C developers often introduce semantic gaps to “trick” the compiler into producing secure code [7, 8]. JavaScript 2 Constant-Time WebAssembly developers must additionally trick the runtime system—in The lack of language support for expressing data sensitivity particular, the just-in-time compiler (JIT) and garbage col- has been a key contributor to many vulnerabilities in crypto lector (GC) of JavaScript engines—to not introduce time vari- implementations. By not distinguishing secret data from abilities or retain secrets that should otherwise be erased. public data, languages have made it easy for developers to Unsurprisingly, no existing JavaScript crypto library—from accidentally and repeatedly leak sensitive data [5, 10, 12, SJCL [16] to libsignal [13]—even attempts to tackle these 14]. Even worse, they have made it easy for compilers to challenges. In many cases, this may not even be possible introduce low-level vulnerabilities (e.g., timing attacks), for at the JavaScript layer—e.g., we cannot prevent a copying code that is deemed secure at the high-level [7, 8, 18]. GC from making additional copies of (secret) data in Java- We propose to make data security explicit at the language- Script alone. Implementing JavaScript APIs in C++ is not level precisely to avoid the pitfalls of existing approaches. In necessarily better either—e.g., WebCrypto [17] and Node.js’s particular, we propose to extend the wasm language to allow 1https://electron.atom.io/ developers to declare the sensitivity of values and memories using labeled types. For example, values of type i32'secret PriSC’18, January 13, 2018, Los Angeles, CA, USA or i64'secret are considered secret in ct-wasm; values of 1 PriSC’18, January 13, 2018, Los Angeles, CA, USA John Renner, Sunjay Cauligi, and Deian Stefan (memory $pub 10) ; public linear memory (10 pages) Optimization Safe? (memory $sec 10 secret) ; secret linear memory (10 pages) ... Constant folding Yes (i32.load $pub 3) ; load $pub[3], i32'public value Dead store elimination May remove writes (i32.load $sec 5) ; load $sec[5], i32'secret value Common subexpression No (remove writes) elimination Figure 1. Memories can be declared secret (like $sec) or Global value numbering No (remove writes) public (like $pub); reads from these memories receive their Strength reduction No (emit unsafe instructions) respective labeled types. Figure 2. Safety of different wasm optimization passes. type i32 or i64, on the other hand, are public.2 Similarly, memory regions declared secret, as shown in Figure 1, are considered secret whereas memories lacking such a secret timing channels. In wasm, and thus ct-wasm, developers qualifier are considered public. specify the types of their imports. By further specifying the To prevent developers from writing wasm code that would secrecy of arguments or return values of imported functions, leak secret data, we extend the wasm type checker to enforce for example, developers can ensure—via the ct-wasm label- several information flow control (IFC) typing rules [7, 15]. type checker—that such code cannot leak the secret data. More concretely, we modify the wasm validation pass to: (1) The demand for IFC labels at a low-level has the additional track secret-labeled data at the instruction-level, assigning role of carrying security-relevant information to wasm com- labels to values in a standard flow-insensitive fashion15 [ ]; pilers and execution environments. Without this information, (2) disallow branches on secret values; and (3) prevent us- an optimization pass may introduce vulnerabilities. Indeed, ing secret values where public values are expected (e.g., most of the optimizations used in Chromium’s V8 wasm public-memory write instructions or public function-call ar- implementation, shown in Figure 2, are unsafe. For example, guments). By conservatively and explicitly extending wasm common subexpression elimination (CSE) and global value with secret-typed memories3 and instructions—essentially numbering (GVN) may remove writes to secret memories blessing language primitives that run in constant-time—we that deliberately exist to scrub sensitive information. Simi- ensure that ct-wasm remains safe as wasm is extended with larly, a strength reduction pass may introduce branches on new, potentially dangerous, features (e.g., threads and garbage secret values or emit variable-time instructions that compute collection): by default, ct-wasm instructions will only com- on secret operands. pute on public data and thus cannot leak sensitive data. The ct-wasm execution environment leverages labels to Though these rules are very conservative, we do not en- prevent such pitfalls when optimizing code. For example, vision crypto implementations to be written directly in ct- the V8 engine can disable all optimizations or introduce wasm; instead, we believe ct-wasm to be a good compila- whole new optimization pipelines for computations that tion target for high-level crypto-oriented programming lan- handle secret data. Though secure, this approach gives guages, such as HACL* [19] and FaCT [7]. These languages up on performance. Hence, we instead propose to slightly already produce low-level code that follow an IFC discipline modify existing optimization passes to preserve the security that is (at least) as restricting as ct-wasm’s. FaCT, for exam- guarantees expected at the language-level. Specifically, we ple, disallows writing secret data to public buffers. Similarly, propose to modify optimizations such as CSE, GVN, and it ensures that there are no branches on secrets by transform- strength reduction to inspect labels and: (1) leave instruc- ing such branches to constant-time arithmetic operations [7], tions that write to secret memories intact, (2) avoid emitting like most constant-time crypto libraries (e.g., libsodium [1], branch instructions on secret values, and (3) avoid emitting OpenSSL [3], and mbedTLS [2]). variable-time instructions when secret values are used as By enforcing IFC at the low-level, high-level languages operands. While these three modifications are necessary

View Full Text

Details

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