News for hackers. Stuff that matters.
Re:The Bytecode Alliance: Building a secure, composable futu... by azakai on Tuesday November 12, 2019 @12:28PM (#21515969)
In my opinion this is a fascinating approach, and it may end up transforming our industry.

But the main question I've had is how big the overhead is, specifically since modules don't share their wasm Memory. That means data will be constantly copied between them. Compared to regular static or even dynamic linking, that may be a noticeable slowdown.

Re:The Bytecode Alliance: Building a secure, composable futu... by JoshTriplett on Tuesday November 12, 2019 @12:33PM (#21516025)
> specifically since modules don't share their wasm Memory. That means data will be constantly copied between them.

We're working on that. We want to make it possible for modules to share memory in a controlled way, without giving access to their entire address space.

Re:The Bytecode Alliance: Building a secure, composable futu... by BubRoss on Tuesday November 12, 2019 @02:49PM (#21517419)
Shared memory can certainly do this. Even separate processes can use shared memory to communicate lock free using atomics.

Other than that, I wonder if nested page tables that are normally used for virtualization can be used to separate address spaces within a process.

Re:The Bytecode Alliance: Building a secure, composable futu... by azakai on Tuesday November 12, 2019 @01:20PM (#21516530)
Interesting! Is that written up somewhere public?
Re:The Bytecode Alliance: Building a secure, composable futu... by JoshTriplett on Tuesday November 12, 2019 @01:21PM (#21516559)
Some of it; see https://hacks.mozilla.org/2019/08/webassembly-interface-type... for the starting point that this will be based on.
Re:The Bytecode Alliance: Building a secure, composable futu... by azakai on Tuesday November 12, 2019 @01:38PM (#21516728)
Oh, where? I don't think I see anything about controlled memory sharing there, but I guess I missed it. Which section is it in?
Re:The Bytecode Alliance: Building a secure, composable futu... by JoshTriplett on Tuesday November 12, 2019 @01:47PM (#21516835)
It isn't yet, that work is still in progress. WIT is just the starting point that this would be based on.

(Sorry for the lack of more concrete information, documentation is still in progress.)

Re:The Bytecode Alliance: Building a secure, composable futu... by azakai on Tuesday November 12, 2019 @01:50PM (#21516875)
I see, thanks. Curious to learn more when it is public.
Re:The Bytecode Alliance: Building a secure, composable futu... by Arnavion on Tuesday November 12, 2019 @01:06PM (#21516413)
>specifically since modules don't share their wasm Memory. That means data will be constantly copied between them.

It is possible today to have modules import memory from the host, which means the host can provide the same imported memory to multiple modules. Then modules can pass pointers to each other without needing any memcpys.

It does require the modules to not tread on each other though, such as by requiring them to have distinct static offsets (poor man's linking), or by requiring them to be PIC / compiled with relocation info so that they can be relinked by the host loader.

It doesn't seem to me from reading TFA that this is going away, merely that there are planning to add alternatives to make it more fine-grained.

Re:The Bytecode Alliance: Building a secure, composable futu... by azakai on Tuesday November 12, 2019 @01:21PM (#21516550)
It is possible to share memory in wasm today, yes (we use that to optimize wasm/JS interaction, and wasm/wasm dynamic linking) - and that won't go away, it's a core feature of wasm, you're right. But the specific approach in this article disallows that.

The article does mention a possible future extension of multiple wasm modules in a single nanoprocess (the section with "allowing native-style dynamic linking"), and JoshTriplett mentions in another comment some future ideas of sharing parts of memory but not all. Those things will compromise the strict initial requirement of no shared memory, and improve performance.

Those are the interesting questions for me - is not sharing memory too much overhead, and if it is, is there a way to relax that which preserves enough security with enough performance.

Re:The Bytecode Alliance: Building a secure, composable futu... by luke_wagner on Tuesday November 12, 2019 @01:41PM (#21516764)
To the question of "how would dynamic linking work in the future", as already stated in the article, a nanoprocess doesn't need to correspond 1:1 to a wasm module/instance. Rather, N wasm instances can share a single wasm memory to collectively represent a single nanoprocess. From an external point of view, whether a nanoprocess is implemented as 1 or N instances wouldn't be visible -- it's an impl detail -- and the memory is (still) encapsulated by the nanoprocess. Thus, there is a two-level hierarchy of: a graph of shared-nothing-linked nanoprocesses each containing a graph of shared-everything wasm instances.

There's still a lot more details to figure out, of course, but that's true for wasm dynamic (shared-everything) linking in general.

Re:The Bytecode Alliance: Building a secure, composable futu... by SkyMarshal on Tuesday November 12, 2019 @12:32PM (#21516008)
I’d rather start with something provably secure and slower, and then optimize its performance and features over future iterations and versions.

Starting with speed and trying patch in security doesn’t seem to make things actually secure.

Re:The Bytecode Alliance: Building a secure, composable futu... by AnIdiotOnTheNet on Tuesday November 12, 2019 @01:16PM (#21516505)
Last I checked WebAssembly still didn't have a way of actually freeing memory it has allocated either.
Re:The Bytecode Alliance: Building a secure, composable futu... by thrax on Tuesday November 12, 2019 @01:38PM (#21516729)
You give it a heap. It doesn't allocate memory. It may allocate within its own heap, using whatever allocator/gc strategy it inherits from it's host language.
Re:The Bytecode Alliance: Building a secure, composable futu... by kllrnohj on Tuesday November 12, 2019 @02:29PM (#21517247)
Which means it can't free. But that's also not accurate, anyway, there's a brk() method to grow the heap. Which is such a bad starting point for a new runtime.
Re:The Bytecode Alliance: Building a secure, composable futu... by saagarjha on Tuesday November 12, 2019 @06:27PM (#21519394)
Would it be impossible to implement mmap and sbrk in the runtime?
Re:The Bytecode Alliance: Building a secure, composable futu... by kllrnohj on Tuesday November 12, 2019 @06:48PM (#21519525)
mmap is arguably the only thing it should have had in the first place. brk/sbrk is fairly dead.
Re:The Bytecode Alliance: Building a secure, composable futu... by saagarjha on Wednesday November 13, 2019 @04:47AM (#21522471)

  $ strace /bin/ls 2>&1 | grep brk
  brk(NULL)                               = 0x55fb032b3000
  brk(NULL)                               = 0x55fb032b3000
  brk(0x55fb032d4000)                     = 0x55fb032d4000
Re:The Bytecode Alliance: Building a secure, composable futu... by wahern on Wednesday November 13, 2019 @11:50PM (#21532881)

  $ ktrace /bin/ls >/dev/null
  $ kdump | grep brk | wc -l     
         0
  $ kdump | grep mmap | wc -l
       130
glibc, musl, and jemalloc got the memo, they just couldn't be bothered to stop using brk by default. They're all capable of using mmap exclusively, however, because whether or not brk is actually dead, there's long been consensus that mmap is the better abstraction on balance, particularly given the benefit of ASLR. So there's little reason to support brk instead of mmap for compatibility. Presumably it was chosen for the convenience of WebAssembly implementations--contiguous, flat memory is a great simplifier of VM, JIT, and even traditional AoT architectures.
Re:The Bytecode Alliance: Building a secure, composable futu... by AnIdiotOnTheNet on Tuesday November 12, 2019 @04:21PM (#21518303)
Right, and while you can grow the heap you can't give any of it back, so you can't really dynamically contract your memory without restarting the process.
Re:The Bytecode Alliance: Building a secure, composable futu... by TomMarius on Tuesday November 12, 2019 @01:38PM (#21516732)
I thought that was the host's work. You import a function that does it. If we're talking about shared objects. Your own module's memory is managed by you (or your language's runtime)