News for hackers. Stuff that matters.
Re:WebAssembly’s post-MVP future by kllrnohj on Monday October 22, 2018 @03:55PM (#18277831)
WebASM really only makes sense in the context of embedding untrusted code, which outside of the browser is a concern that largely doesn't exist.

Otherwise you are severely crippling yourself for no real gain. You're going to lag the hardware features by years if not decades, you're not going to get arch-specific optimizations as readily, and you're going to have huge startup costs. You're also stuck with sandbox restrictions that you've self-imposed, making it harder to do things that would have otherwise been trivial or needs to be re-invented.

You could maybe squint and claim you need a portable IR, but given there's only really 2 ISAs in widespread use (x86 & ARM) does that _really_ matter? Similarly you could claim cross-OS support, but again as there's only _really_ 2 OS's for each target (Windows/Linux for server, Android/iOS for mobile) does that _really_ matter? Critically does it matter to such a degree that you'd rather severely cripple your own app to get it instead of just compiling it 2, 3, or 4 times?

Re:WebAssembly’s post-MVP future by raphlinus on Monday October 22, 2018 @07:50PM (#18279635)
I agree that WASM is only really interested for embedding untrusted code, but am not sure that the browser is the only place where you need that. A good example is Cloudflare's workers, which they talked about at the last SF Rust Meetup.

Once you get a _good_ solution to embedding untrusted code, you might find it turns out to be pretty useful.

Re:WebAssembly’s post-MVP future by kllrnohj on Monday October 22, 2018 @08:02PM (#18279695)
Do you really need embedded code for things like Cloudflare's workers, though? It doesn't seem like it does, seems like each worker can just be its own process using normal process isolation mechanisms. Switching to embedded untrusted code for things like that would actually make a lot of stuff a lot harder - scheduling, resource monitoring, etc... would all need to be re-invented from scratch. Is it really useful to re-invent the kernel in userspace to use a bunch of embedded webasm contexts instead of just a bunch of processes?
Re:WebAssembly’s post-MVP future by kentonv on Monday October 22, 2018 @08:19PM (#18279791)
Hi. Cloudflare Workers tech lead here.

No, process isolation does not work for us, because it does not scale well enough.

The point of Cloudflare Workers is to distribute your code across Cloudflare's entire edge network -- 154 locations and growing -- so that you can respond to requests at the closest location to your end user. We want to put every customer's code in every location, rather than forcing you to choose a handful. Meanwhile, obviously, not every one of our locations is a mega-datacenter.

This means we need a way to support extremely large numbers of tenants per machine, with relatively low traffic per tenant (because each tenant's traffic is spread out over the world). We need this to be efficient.

This means, we need low memory overhead (to support many tenants per machine), very fast cold-start time (since cold starts are a lot more common in a decentralized scenario), and low overhead to switch between workers (because we're mixing traffic from all our customers everywhere).

Using embedded V8 isolates within a single process gives us 10x-1000x better performance on all these metrics than if we gave a whole process to each customer.

Relatedly, here's a talk I gave at Heavybit about the neat things you can do when you have fine-grained server compute: https://www.youtube.com/watch?v=YZSvJNBZsxg

Re:WebAssembly’s post-MVP future by jeremyjh on Monday October 22, 2018 @09:21PM (#18280061)
V8's developer guide doesn't recommend running untrusted code in a shared process with "sensitive" data. How do you know if your different customers data is sensitive?

https://v8.dev/docs/untrusted-code-mitigations#sandbox-untru...

Re:WebAssembly’s post-MVP future by kentonv on Monday October 22, 2018 @09:44PM (#18280156)
This is a relatively new recommendation on V8's part specifically in response to Spectre-type vulnerabilities.

We've spent a lot of time thinking about and building mitigations for speculative side channel attacks. For example, early on in the project -- before anyone even knew about Spectre -- we made the decision that `Date.now()` would not advance during code execution, only when waiting for I/O. So, a tight loop that calls `Date.now()` repeatedly will keep getting the same value returned. We did this to mitigate timing side channels -- again, even though we didn't know about Spectre yet at the time.

Chrome has indeed stated that they believe process isolation is the only mitigation that will work for them. However, this statement is rather specific to the browser environment. The DOM API is gigantic, and it contains many different sources of non-determinism, including several explicit timers as well as concurrent operations (e.g. layout, rendering, etc.). Side channel attacks are necessarily dependent on non-determinism; a fully-deterministic environment essentially by definition has no covert side channels. But, there's no way Chrome can get there.

The Cloudflare Workers environment is very different. The only kinds of I/O available to a worker are HTTP in, HTTP out, `Date.now()`, and `crypto.getRandomValues()`. Everything else is perfectly deterministic.

So, for us, the problem is much narrower. We need to make sure those four inputs cannot effectively be leveraged into a side channel attack. This is still by no means trivial, but unlike in the browser, it's feasible. `getRandomValues()` is not useful to an attacker because it is completely non-deterministic. `Date.now()` we've already locked down as mentioned above. HTTP in/out can potentially be leveraged to provide external timers -- but the network is extremely noisy. A practical attack would require a lot of time in order to average out the noise -- enough time that we can do a bunch of higher-level things to detect and disrupt possible attacks. It helps that Workers are stateless, so we can reset a worker at any time and move it around, which makes attacks harder.

NetSpectre demonstrated that even physical network separation does not necessarily protect you against Spectre attacks. There's simply no such thing as a system that's perfectly secure against Spectre, process isolation or not. All we can do -- aside from going full BSG and giving up on networks altogether -- is make attacks harder to the point of infeasibility. Luckily, we have lots of tools in our toolbox for making Spectre attacks infeasible in the case of Cloudflare Workers.

Re:WebAssembly’s post-MVP future by chrisweekly on Tuesday October 23, 2018 @09:08AM (#18283018)
1. Thanks for your multiple well-informed, articulate comments.

2. "BSG"?

Re:WebAssembly’s post-MVP future by steveklabnik on Tuesday October 23, 2018 @09:45AM (#18283297)
I think your parent is referring to Battlestar Galactica; it had no computer networks, and therefore was not able to be effectively attacked by the Cylons.
Re:WebAssembly’s post-MVP future by kentonv on Tuesday October 23, 2018 @12:02PM (#18284549)
Yep. :)

The Battlestar Galactica was the only ship in the fleet that hadn't networked its computers, because the captain was paranoid. When the Cylons (AI) attacked, they instantly hacked all the other ships, but the Galactica stayed under human control and got away.

It's fiction, but I'm honestly really impressed with this bit of writing. It's both an entirely plausible and almost realistic strategy, and it gives the writers an excuse for the crew members to interact rather than let the computer do everything. Whereas on Star Trek one wonders why they bother with a bridge crew -- the captain might as well be punching everything into a computer directly rather than inefficiently giving orders to humans.

Re:WebAssembly’s post-MVP future by mwcampbell on Tuesday October 23, 2018 @08:57PM (#18288818)
Do you see the complexity of V*'s multi-tiered JIT compiler as a security risk? Maybe a simple JS interpreter plus a simple AOT WebAssembly-to-x64 compiler would be safer.
Re:WebAssembly’s post-MVP future by kentonv on Thursday October 25, 2018 @06:34PM (#18305191)
Complexity is a risk, but we also care deeply about performance and startup time in much the same ways Chrome does. So we need that JIT.

I'm comforted by the fact that if there's a breakout in V8, Chrome is a much juicier target than we are -- and has an incredibly strong security team that will jump on the issue. I think we would be overall less secure using a lesser-known JS implementation.

Re:WebAssembly’s post-MVP future by mwcampbell on Thursday October 25, 2018 @09:04PM (#18305981)
Actually, I think Cloudflare is a juicier target, due to a combination of two things:

1. No process isolation 2. Data from lots of users on any given node

Am I missing something?

Re:WebAssembly’s post-MVP future by kentonv on Saturday October 27, 2018 @02:17PM (#18316941)
While I don't mean to deny the risk, which we take very seriously, I do think there's a number of reasons Chrome remains a much more interesting target:

* While process isolation makes Chrome somewhat less interesting than it used to be, keep in mind that process isolation is being rolled out as a defense to arbitrary-read attacks (like spectre), not arbitrary-code-execution attacks. Executed code can potentially talk to the rest of Chrome and perform actions that a web site is not intended to be allowed to. (At least in the past, this included the ability to read all the user's cookies, though it's possible they've improved on that, I don't know.)

* Cloudflare has potentially multiple tenants in a node, but the attacker has no control over who they are. There's no particularly good way to target a specific end user nor a specific web site.

* V8 vulnerabilities are likely to be memory safety issues, which are difficult to leverage into an attack without an understanding of the process's memory space, which is hard to get without having access to the source code or a compiled binary. The attacker would be flying blind and would almost certainly just segfault or be caught by our layer 2 sandbox (which blocks almost all syscalls), which incidentally would immediately alert us to their activity. (I don't particularly like this as a defense, since I like open source -- but frankly, it is a pretty big barrier.)

* The attacker would be burning their zero-day by uploading it to Cloudflare. We block eval() and the like, such that the only way to run code on our edge is by uploading it through our deployment APIs, which keep a copy.

* Last I checked, Chrome still does not use site isolation on mobile, because the overhead is too high.

Re:WebAssembly’s post-MVP future by pjmlp on Monday October 22, 2018 @06:19PM (#18279065)
That is how IBM i, IBM z, Unisys ClearPath work, how a large majority of Android and Windows apps, some iOS ones (mostly watchOS actually), Garmin devices, SIM cards, Blue Ray, Ricoh copiers, ...

If anything the industry is increasingly adopting bytecode as distribution format, kind of returning to the early 60/70's designs with microcoded CPUs just with another approach to the final execution.

Re:WebAssembly’s post-MVP future by int_19h on Monday October 22, 2018 @10:12PM (#18280250)
For the vast majority of code that runs on either desktop or mobile, the latest and greatest hardware features don't matter, and neither do arch-specific optimizations. Startup costs are trivially solved by an OS-level precompilation and caching mechanism. And we already have sandboxes for apps, even on the desktops (both macOS and Windows store apps). Besides, why can't WebAssembly have a different, less limiting sandbox outside of the web?

The real benefit is having a portable bytecode that 1) can accommodate any language out there without constraining their object and memory model, and 2) is guaranteed to be compiled to native code by an optimizing compiler when deployed. Add some basic APIs, and we could have a situation that has heretofore has been enjoyed pretty much only by x86 - the ability to compile code, and run it 30 years later as is.

Re:WebAssembly’s post-MVP future by cm2187 on Tuesday October 23, 2018 @03:47AM (#18281503)
In what language can you just “compile 4 times” to target android, iOS, windows, linux, macos and any future platform?
Re:WebAssembly’s post-MVP future by kllrnohj on Tuesday October 23, 2018 @01:50PM (#18285658)
Literally all of them? Since you scope creaped to add macos to the list even though it doesn't exist in the server or mobile space you'll need to increase that to 5 compiles instead of 4, though.

But C, C++, Rust, Go, D, etc... all support compilation to those platforms. This is a really common thing to do.

Re:WebAssembly’s post-MVP future by chrisweekly on Tuesday October 23, 2018 @09:11AM (#18283032)
JavaScript.
Re:WebAssembly’s post-MVP future by tannhaeuser on Monday October 22, 2018 @07:48PM (#18279623)
In addition, WASM lacks bindings to the browser environment (or any API for that matter), as its original pitch was improving performance-critical code paths in browser apps; but like you said, it won't be able to reach native ARM ISA speeds nevertheless. At most, in a couple years, it could hope to do what JavaScript has been doing for over a decade. But the browser rendering model and WebGL will just be the same. And then you still have an upstream battle and hope Apple and Google will open their mobile platform APIs to WASM apps, and agree to a common standard which I don't see happening. I can't understand for the life of me what people are projecting into WASM. A new bytecode format for code delivered over the network doesn't solve any problem we're having that isn't solved much better using a native platform API/ABI.
Re:WebAssembly’s post-MVP future by fbender on Tuesday October 23, 2018 @02:24AM (#18281139)
I think nobody is saying WASM is better than a „native platform API/ABI“ at solving all problems. It‘s simply a (potentially) viable alternative for scenarios that are way more common than everyone thought at first. And in some situations, it‘s the only solution (e.g. you won‘t get native APIs on the Web).