This is great! The WebAssembly Core Specification is actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers. If anyone is looking for a slightly more accessible way to learn WebAssembly, you might enjoy WebAssembly from the Ground Up: https://wasmgroundup.com (Disclaimer: I'm one of the authors)
I know one of WebAssembly's biggest features by design is security / "sandbox". But I've always gotten confused with... it is secure because by default it can't do much. I don't quite understand how to view WebAssembly. You write in one language, it compiles things like basic math (nothing with network or filesystem) to another and it runs in an interpreter. I feel like I have a severe lack/misunderstanding. There's…
I Wrote a WebAssembly VM in C
41–50 of 104 posts
Re: I Wrote a WebAssembly VM in C
#42Earlier quoted context omitted.
> Wasmer > Installed-Size: 266 MB What the hell
Indeed, we need to improve further the base binary size! Most of the size comes from the LLVM backend, which is a bit heavy. Wasmer ships many backends by default, and if you were to use Wasmer headless that would be just a bit less than a Mb. If you want, you can always customize the build with only the backends that you are interested in using. Note: I've seen some builds of LLVM under 5-10Mb, but those require hea…
Re: I Wrote a WebAssembly VM in C
#43Earlier quoted context omitted.
I know one of WebAssembly's biggest features by design is security / "sandbox". But I've always gotten confused with... it is secure because by default it can't do much. I don't quite understand how to view WebAssembly. You write in one language, it compiles things like basic math (nothing with network or filesystem) to another and it runs in an interpreter. I feel like I have a severe lack/misunderstanding. There's…
Speaking of WebAssembly security, is it vulnerable to Spectre/CPU style attacks like those in JavaScript? (WASM without imported JS functions)
Re: I Wrote a WebAssembly VM in C
#44Earlier quoted context omitted.
I think the biggest advantage of wasm in terms of security is that it doesn't accept machine language written in the target machine, only in this artificial machine language. This means that it cannot encode arbitrary code that could be executed by the host machine. Everything it runs has necessarily to go through the wasm interpreter.
That's quite interesting. This is way outside of my wheelhouse - has this kind of approach been tried in other security contexts before? What would you even call that, virtualization?
Re: I Wrote a WebAssembly VM in C
#45This is great! The WebAssembly Core Specification is actually quite readable, although some of the language can be a bit intimidating if you're not used to reading programming language papers. If anyone is looking for a slightly more accessible way to learn WebAssembly, you might enjoy WebAssembly from the Ground Up: https://wasmgroundup.com (Disclaimer: I'm one of the authors)
I know one of WebAssembly's biggest features by design is security / "sandbox". But I've always gotten confused with... it is secure because by default it can't do much. I don't quite understand how to view WebAssembly. You write in one language, it compiles things like basic math (nothing with network or filesystem) to another and it runs in an interpreter. I feel like I have a severe lack/misunderstanding. There's…
Yes. That’s a super accurate description. You’re not confused.
> I don't quite understand how to view WebAssembly. You write in one language, it compiles things like basic math (nothing with network or filesystem) to another and it runs in an interpreter.
Almost. Wasm is cheap to JIT compile and the resulting code is usually super efficient. Sometimes parity with native execution.
> I feel like I have a severe lack/misunderstanding. There's a ton of hype for years, lots of investment... but it isn't like any case where you want to add Lua to an app you can add WebAssembly/vice versa?
It’s definitely a case where the investment:utility ratio is high. ;-)
Here’s the trade off between embedding Lua and embedding Wasm:
- Both have the problem that they are only as secure as the API you expose to the guest program. If you expose `rm -rf /` to either Lua or Wasm, you’ll have a bad time. And it’s surprisingly difficult to convince yourself that you didn’t accidentally do that. Security is hard.
- Wasm is faster than Lua.
- Lua is a language for humans, no need for another language and compiler. That makes Lua a more natural choice for embedded scripting.
- Lua is object oriented, garbage collected, and has a very principled story for how that gets exposed to the host in a safe way. Wasm source languages are usually not GC’d. That means that if you want to expose object oriented API to the guest program, then it’ll feel more natural to do that with Lua.
- The wasm security model is dead simple and doesn’t (necessarily) rely on anything like GC, making it easier to convince yourself that the wasm implementation is free of security vulnerabilities. If you want a sandboxed execution environment then Wasm is better for that reason.
Re: I Wrote a WebAssembly VM in C
#46Earlier quoted context omitted.
> anything involving memory [..] needs safety checks that becomes multi-instruction Not necessarily; on AMD64 you can do memory accesses in a single instruction relatively easily by using the CPU's paging machinery for safety checks plus some clever use of address space. > branches could mostly be direct _unless_ the runtime has any kind of metering (it should) to stop eternal loops Even with metering the branches wo…
Metering also doesn't require a branch if you implement it with page faults. See "Implicit suspend checks" in https://android-developers.googleblog.com/2023/11/the-secret...
Re: I Wrote a WebAssembly VM in C
#47This is an interesting approach, great work! For anyone that wants to check where the meat is at, is mostly in this file: https://github.com/irrio/semblance/blob/main/src/wrun.c Thinking out loud, I think it would have been a great idea to conform with the Wasm-C-API ( https://github.com/WebAssembly/wasm-c-api ) as a standard interface for the project (which most of the Wasm runtimes: Wasmer, V8, wasmi, etc. have ado…
Um, the author is clearly familiar enough with Wasm, but probably knows enough to know to avoid a company that tried to trademark WebAssembly. > understandable concerns about the fact we, Wasmer, a VC-backed corporation, attempted to trademark the name of a non-profit organization, specifically WebAssembly Acknowledgement of wrongdoing.
Re: I Wrote a WebAssembly VM in C
#48Earlier quoted context omitted.
Um, the author is clearly familiar enough with Wasm, but probably knows enough to know to avoid a company that tried to trademark WebAssembly. > understandable concerns about the fact we, Wasmer, a VC-backed corporation, attempted to trademark the name of a non-profit organization, specifically WebAssembly Acknowledgement of wrongdoing.
I hadn't heard about this - terrible.
https://wasmer.io/posts/wasmer-and-trademarks-extended
I don't think this is as much of a smoking gun as it is made out to be.
Re: I Wrote a WebAssembly VM in C
#49--edit--
Oh, and I also was going to suggest using a library like libffi to make calls into C so you can do multiple arguments and whatnot.
Re: I Wrote a WebAssembly VM in C
#50Earlier quoted context omitted.
I know one of WebAssembly's biggest features by design is security / "sandbox". But I've always gotten confused with... it is secure because by default it can't do much. I don't quite understand how to view WebAssembly. You write in one language, it compiles things like basic math (nothing with network or filesystem) to another and it runs in an interpreter. I feel like I have a severe lack/misunderstanding. There's…
Speaking of WebAssembly security, is it vulnerable to Spectre/CPU style attacks like those in JavaScript? (WASM without imported JS functions)