Skip to content

Explain security #205

Closed
Closed

Description

@jfbastien

WebAssembly's security model aims at protecting users from buggy or malicious .wasm files. This doesn't help developers write secure application! Our design should make that distinction clear, explain how WebAssembly implements that security, and what tools WebAssembly expect to be available to help developers create secure applications (this relies on offering the right primitives in WebAssembly).

This is mostly an issue for myself to add this in the design.

Activity

  1. self-assigned this
    on Jun 19, 2015
  2. added this to the MVP milestone on Jun 19, 2015
  3. MattPD commented on Jun 19, 2015

    @MattPD

    Hi!

    I have a question: Would it make sense to elaborate on the following in this context:

    "Other than that, programs which invoke undefined behavior at the source language level may be compiled into WebAssembly programs which do anything else, including corrupting the contents of the application heap, calling APIs with arbitrary parameters, hanging, trapping, or consuming arbitrary amounts of resources (within the limits)."
    https://github.com/WebAssembly/design/blob/master/CAndC++.md#undefined-and-implementation-defined-behavior

    What I'm thinking of is providing context / references which may be (perhaps) of use for the web developers coming from non-native backgrounds -- by providing examples and further discussion.

    For instance, CERT's MSC14-C. Do not introduce unnecessary platform dependencies lists four different kinds of Nonportable Behavior (Unspecified Behavior, Undefined Behavior, Locale-specific Behavior, Implementation-defined Behavior) with examples. MSC15-CPP. Do not depend on undefined behavior links to vulnerability C compilers may silently discard some wraparound checks, which may be particularly noteworthy in this context (Robert Seacord discusses this in more detail in "Silent Elimination of Bounds Checks").

    More in-depth treatments:

    Other potentially relevant advice:

  4. jonathanKingston commented on Jun 19, 2015

    @jonathanKingston

    Would having a unique CSP header for controlling wasm files help? I feel like site owners might want to prevent subresources from loading wasm.

  5. lukewagner commented on Jun 19, 2015

    @lukewagner
    Member

    That's an interesting question. Definitely we should allow sites to disallow dynamic loading and evaluation of WebAssembly in the same cases they disallow eval and Function (this would just fall out of ES6 module integration and CSP checks on the Loader path). Past that, though, since WebAssembly will be capability-equivalent to JS, I wouldn't think distinguishing the two would be necessary.

  6. jfbastien commented on Jun 19, 2015

    @jfbastien
    MemberAuthor

    It's worth pointing at #53 for a discussion of some of the security concerns with dynamic linking.

  7. jonathanKingston commented on Jun 19, 2015

    @jonathanKingston

    @jfbastien yup CORS and SRI should be a available to developers where possible.

    @lukewagner I guess it depends on the low level access to resource that wasm will enable. As you say out of the box it is just JS. However it seems the overarching goal of wasm is the closest thing to the machines metal possible; a CSP directive to globally control would be a nice to have.
    Over time a more granular approach to the other features would be better too.

    The other immediate possibilities are utilising the permissions API for other low level access.

  8. lukewagner commented on Jun 19, 2015

    @lukewagner
    Member

    Well, close to the metal in a performance sense. From a security, permissions and sandboxing perspective, there is no discussion of having WebAssembly diverging from JS.

  9. jonathanKingston commented on Jun 19, 2015

    @jonathanKingston

    That wasn't the feeling I got from both the post-MVP and Brendan Eichs announcements but ok 👍

  10. lukewagner commented on Jun 21, 2015

    @lukewagner
    Member

    I think what you're referring to is that we've agreed that, post-MVP, WebAssembly semantics would be allowed to diverge from what could be efficiently polyfilled in JS. This divergence would be around computational features, not anything to do with security/permissions. That means that, while they couldn't be polyfilled efficiently, new features could be simulated by a WebAssembly interpreter written in JS (Emterpreter-style). It'd probably be good to add a note to this effect to bound what we mean by "diverge from JS".

  11. jonathanKingston commented on Jun 21, 2015

    @jonathanKingston

    Yup that would be a good enhancement to the document certainly, I might have read the document too fast but it didn't seem to make that clear.

    I think it was one of Eichs talks about adding more threading and memory features that made me think wasm would get new features. I suspect these are likely to be added to JavaScript too and be subject to the usual scrutiny of new features.

  12. lukewagner commented on Oct 29, 2015

    @lukewagner
    Member

    "No different from security POV than JS" is now in Web.md.

  13. jfbastien commented on Oct 29, 2015

    @jfbastien
    MemberAuthor

    I'd rather explain the distinction better. Referring to JS isn't very nice from a self-standing perspective, and I think we actually want to reduce the security surface area that JS has (say, cross-origin scripts and such).

    I'll get to this, now that I've given a talk about it at CppCon :-)

  14. 7 remaining items

  15. added a commit that references this issue on Jul 7, 2016
    8d2c284
  16. added a commit that references this issue on Jul 12, 2016
    62f3096
  17. buu700 commented on Jun 27, 2017

    @buu700

    @jfbastien, does everything you said about wasm timing guarantees still apply today?

    I see in the current docs that deterministic execution is a goal except in a small list of documented edge cases, which sounds potentially positive for constant time algorithms. However, webassembly.org/docs/security acknowledges that timing attacks are possible and lists some potential future mitigations, but it isn't clear whether the implication is meant to be that "your buggy C code won't be magically fixed... yet" or "side channel vulnerabilities may be introduced that wouldn't happen with a typical C compiler".

    Hard guarantees aside, it would be helpful at least to get a sense of where we stand between "constant time algorithms will 100% definitely get screwed" and "there's no obvious reason not to always expect timing characteristics comparable to clang's native binary output". To @dconnolly's point, some language specifically comparing this with asm.js would also be really useful — particularly taking into account both implementations like Firefox's that fully respect 'use asm' statements and those like Chrome's that play it a bit looser.

  18. jfbastien commented on Jun 27, 2017

    @jfbastien
    MemberAuthor

    @buu700 deterministic result for all opcodes doesn't imply that timing is guaranteed for any opcode. Clang doesn't guarantee constant-time execution either, and constant-time isn't all you need if you're writing infoleak-sensitive code.

    Right now, WebAssembly makes no attempt at guaranteeing anything with respect to infoleaks.

  19. buu700 commented on Jun 27, 2017

    @buu700

    Got it, thanks for clarifying the section on determinism @jfbastien.

    As far as timing / side channels (and ignoring guarantees or lack thereof), it sounds like there's nothing relevant in the spec about it at this time and no useful data yet about how the actual implementations compare to clang? What I was really getting at, after reading your earlier comment, is whether there's an inherent reason for wasm implementions to necessarily always be worse than gcc/clang in this area. You'd mentioned the level of abstraction as a concern, but it wasn't clear what you were using as a baseline comparison for "good enough" constant timing (native C, assembly, hardware, etc.).

    In other words, given the choice between running infoleak-sensitive code on clang and a hypothetical best / most mature / most infoleak-hardened possible implementation of today's WebAssembly spec, would the former still be obviously preferred based on your understanding?

  20. jfbastien commented on Jun 27, 2017

    @jfbastien
    MemberAuthor

    At this point in time, I would rely neither on clang nor WebAssembly for code which is infoleak-sensitive. The only way I currently know to actually get the guarantees I'd desire is by writing assembly which reading the manual for the specific CPU I'm targeting, and with close collaboration from the kernel. Knowing "x86" or "ARM 64" isn't even sufficient if you truly want to be timing independent.

    You can get some guarantees with some compilers / languages, but if one infoleak is all that's needed to defeat your code then "some" isn't enough of a guarantee.

  21. buu700 commented on Jun 27, 2017

    @buu700

    Perfect, thanks, I think that answers my question. Agreed on all points about general infoleak threat modeling; I just wanted to get an idea of whether wasm should be considered more leaky than any other (asm-free) C compile target, which it sounds like you're saying isn't necessarily the case?

  22. jfbastien commented on Jun 27, 2017

    @jfbastien
    MemberAuthor

    I don't think "more leaky" is a useful measure. The metric is "does it leak at all?" The answer for WebAssembly, clang, C++, and C, are "yes".

  23. buu700 commented on Jun 28, 2017

    @buu700

    Well, specifically, what I had in mind was algorithms designed to achieve certain side channel resistance properties with pure C implementations, such as the example of libsodium/NaCl linked by @dconnolly. It's certainly ideal if something will survive every possible attack scenario, but it's also useful to know the delta between two things (even if they both suck, by some measure of sucking), and in this case whether using WebAssembly instead of a Linux ABI as a target is likely to break the intended threat model of libsodium.

    The linked comment on the libsodium issue thread is very informative on how the library interacts with asm.js, but as a non-expert it's not obvious to me what that specific analysis would sound like rewritten for WebAssembly (aside from i64 support and browsers being more consistent in handling wasm than asm.js).

    But anyway, I understand what your original point was from a year ago now, and all I was really concerned about was whether you were making a stronger statement than you actually were (that wasm as a spec was known to introduce specific new side channel weaknesses not found in standard C/clang, as opposed to that neither is generally suitable for that purpose), so thanks for clarifying that.

  24. rossberg commented on Jun 28, 2017

    @rossberg
    Member
  25. jfbastien commented on Jun 28, 2017

    @jfbastien
    MemberAuthor

    I don't think "more leaky" is a useful measure.

    @jfbastien, quantitative security is a field concerned with measuring just
    that. The common metric is how many bits of information are revealed by a
    successful attack -- 1 bit vs 32 bits, say, makes a huge difference (and in
    practice almost every system has small potential leaks through side
    channels). Often such quantification is rather difficult, though.

    I am aware of this, and am thoroughly uninterested because a leak is a leak. If it matters for developers then it'll eventually bite us (the WebAssembly implementors). I don't think WebAssembly should try to tackle this problem any time soon given our other priorities, and that WebCrypto already exists as an effort (despite the shortcoming it may otherwise have, taking this problem on is better than where WebAssembly is at the moment). You can of course explore this at your leisure.

  26. rossberg commented on Jun 28, 2017

    @rossberg
    Member
  27. buu700 commented on Jun 28, 2017

    @buu700

    agreed that ... Wasm isn't more leaky than C

    Nice, thanks for explicitly confirming that! That's all I came here for: a general sense of what I should compare it to, not a guarantee of whether it "won't leak".

  28. kmiller68 commented on Jun 28, 2017

    @kmiller68
    Contributor

    @rossberg-chromium I don't think I'd agree with the idea that wasm isn't more leaky than C. In the end that depends on how each engine implements everything. For example, JavaScriptCore tiers up code and stops tiering up code when it runs out of executable memory. This is a leak that does not exist with C code. I would expect, as wasm engines get more advanced, wasm will be likely as leaky as something like the JVM. Ultimately, I don't the spec or implementors are likely to strive to accommodate preventing information leaks, especially not at the cost of performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions