-
-
Notifications
You must be signed in to change notification settings - Fork 670
Compartmentalizing unsafe from managed code #709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looks that this change is less controversial than I initially thought, perhaps because it is backwards compatible anyway. On this basis, it seems that merging and delaying the overhead of doing an exemplary RFC is fine. Thoughts? |
Also I propose allow unsafe code without decorators for |
What it currently does is allowing unsafe code everywhere, except in user-provided code reached from the main entry file. Can't see the full picture yet where an embedder, like in blockchain, wants to seriously limit unsafe code. That might be done by either accepting contract code only and compiling it on a trusted machine, possibly requiring white listing external dependencies anyway (making per-module restrictions redundant), while allowing a user to provide a .wasm blob can never be safe in this sense anyway (making per-module restrictions unnecessary). Suggesting to wait with that until there's a concrete use case indicating where to go.
At this point it seems to me that
Not sure that I understand this correctly. The none/stub runtime is a complete runtime with managed headers and whatnot, just no sophisticated MM/GC. It should be pretty much interchangeable with the full/stub runtime and requires no extra unsafe work per-se.
I'd say that both the none + unsafe and none - unsafe scenarios are valid, so hardcoding none + unsafe seems wrong. Perhaps we should make configuration a bit more convenient by adding an |
Another option for the bottom concern might be to allow unsafe code by default, without even emitting warnings, so one must explicitly opt-in to unsafe restrictions via That's a relatively fundamental question related to what we talked about in the meta repo actually, because, depending on the outcome of future Wasm specs, we might either have to keep compartmentalizing the runtime or not. If we have to, emitting warnings makes a good guide, but if we don't have to, emitting warnings is not necessary. The fundamental part is whether we favor 1) giving access to low-level Wasm instructions or 2) providing a safe managed environment like that of other languages by default. |
Thinking about this a little more, it is likely that a user currently expects that they can just use |
Continuing the thread on the PR: #710 |
Closing this issue as part of 2020 vacuum because the |
With current master it is possible to mix unsafe and managed code at will, which can lead to all sorts of issues where unsafe code corrupts managed state. To account for this, it has been suggested to add a mechanism to either allow or disallow the mixing.
As ever so often, there are two perspectives to this.
Once WebAssembly GC lands it can be expected that if everything becomes a managed object, unsafe code will not be able to interfere with its internals, and if it is possible to model the entire runtime on top of safe WebAssembly features that'll make the restrictions unnecessary.
At this point, though, with the runtime living in linear memory alongside user code, there'll be use cases where an engine wants to restrict a user in a way that he cannot accidentally break it. It can also be expected that the runtime will stick around even if WebAssembly GC lands, to support environments that don't provide GC.
Hence I suggest to add a new compiler flag
--allow-unsafe
that is equivalent to the current behavior, a new compiler flag--disallow-unsafe
that disallows the use of anything potentially unsafe in user code and a new default that acts like--allow-unsafe
but emits warnings on unsafe code, essentially hinting a user into either using the--allow-unsafe
or the--disallow-unsafe
flag.Standard library code would not have this restriction since it cannot implement anything without resorting to unsafe code. One detail here is that, currently, the only files being considered as stdlib files are the top-level files in lib directories, so I suggest to make the top-level files essentially contagious, so that every file imported from a stdlib file becomes a stdlib file as well.
For an implementer, allowing unsafe code in lib files means that, under the
--disallow-unsafe
condition, it is still possible to add unsafe code as library files using the--lib
option, for example to more efficiently implement custom collections etc.Open questions:
As of the respective meta issue, this should probably become our first RFC.
The text was updated successfully, but these errors were encountered: