TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

WebAssembly doesn’t make unsafe languages safe

161 pointsby paraboulover 6 years ago

15 comments

pcwaltonover 6 years ago
The general point that this article makes is true--C and C++ are still unsafe, even if you execute them in a VM--but there are some very important caveats to note:<p>* ROP should be impossible in Web Assembly, because the call stack is a separate stack, inaccessible from the heap and effectively invisible to the program.<p>* For the same reason, classic buffer overflow attacks involving attacker-supplied machine code are impossible. In addition, Web Assembly bytecode is never mapped into the heap, so attackers cannot inject shellcode via the usual methods.<p>* Mmap functionality is proposed for the future [1], which would allow for the implementation of guard pages. (Guard pages are fairly weak defenses anyway...)<p>I&#x27;m sure that it&#x27;s <i>possible</i> to attack a Web Assembly program&#x27;s control flow by overwriting vtables and function pointers and taking advantage of the resulting type confusion. But it&#x27;s significantly more difficult than it is in native code.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;WebAssembly&#x2F;design&#x2F;blob&#x2F;master&#x2F;FutureFeatures.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;WebAssembly&#x2F;design&#x2F;blob&#x2F;master&#x2F;FutureFeat...</a>
评论 #18529274 未加载
评论 #18530054 未加载
archgoonover 6 years ago
Making unsafe languages safe is not a design goal of WebAssembly. The author seems to believe that WebAssembly should provide many things that are the responsibility of the operating system and standard c library.<p>I do not believe that is a good way of thinking about webassembly. It shouldn&#x27;t be thought of as an operating system target (like Windows, Linux, or Mac); it should be thought of as an architecture target (like Arm vs x86). What the author wants is an operating system and runtime, which you can write for (and standardize on) web assembly and then load your program into it.
评论 #18529280 未加载
评论 #18528627 未加载
评论 #18530422 未加载
danShumwayover 6 years ago
&gt; <i>Technically, this can be implemented already. However, for successful adoption, a standard interface has to be defined.</i><p>This is literally the opposite of how the web works. The web is based on the Extensible Web Manifesto[0], where <i>first</i> we come to a consensus and see widespread adoption, and <i>then</i> we make a standard that reflects that consensus.<p>&gt; <i>We have a fantastic and highly secure execution environment from a host perspective. But from the guest perspective, that very same environment looks like MS-DOS, where memory is a giant playground with no rules.</i><p>Well, yeah. Add me to the list of people who are just kind of confused about why fixing C&#x27;s problems is the responsibility of the browser, and why people thought that it was ever a priority for WASM. WASM is a VM-like isolation chamber for low-level code. It&#x27;s not designed to make your code safe, it&#x27;s designed to protect the host environment from unsafe code.<p>I&#x27;ve seen multiple people make the argument that manually laying out memory in WASM is a design flaw rather than one of the biggest points of the entire implementation. Manually laying out memory with close to zero restrictions or paradigms or safeguards is the thing that makes WASM good.<p>I feel like I missed something, I don&#x27;t know where people got this idea that WASM was trying to be a higher level tool. It&#x27;s an extremely low-level language-agnostic compile target for both safe and <i>unsafe</i> languages, and languages that care about safety should add their own safeguards as they see fit.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;extensibleweb&#x2F;manifesto" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;extensibleweb&#x2F;manifesto</a>
ncmncmover 6 years ago
It is worse than the title says: a key tool for trapping corrupted process state, null pointer segfault, is turned off in WebAssembly targets.<p>The second most common source of process corruption, integer overflow, usually ignored in native targets because direct memory corruption is so much worse, is also adopted into WebAssembly wholesale.<p>This is all overwhelmingly worse than in the native case, because we make some effort to run only trustworthy native code, but browsers actively solicit unknown code from known-hostile sources--most particularly, web ads.<p>The existence of safe-ish languages doesn&#x27;t help, because there is no incentive to deploy them in user-hostile code fragments.
评论 #18530778 未加载
评论 #18539769 未加载
nickcwover 6 years ago
I&#x27;m not sure the NULL pointer access being allowed point is valid.<p>The C standard allows for the NULL pointer to be numerically any value, not just 0, and on some architectures in isn&#x27;t 0. So I would hope C compilers targeting wasm would just use a different value for the NULL pointer, eg 0x8000000000000000 not 0.<p>Whether they actually do or not I don&#x27;t know, but it isn&#x27;t an architectural failing of wasm.
评论 #18529211 未加载
评论 #18528878 未加载
评论 #18529407 未加载
评论 #18528850 未加载
评论 #18529970 未加载
评论 #18528876 未加载
azakaiover 6 years ago
&gt; there would be clear benefits in also delegating basic dynamic memory management to the host.<p>It would be quite hard to spec malloc&#x2F;free into the Web platform, because of the necessary detail: the behavior of that malloc&#x2F;free pair would need to be identical (same pointers returned from malloc) in all browsers, for every possible sequence of allocations and deallocations. GC is actually easier to spec since so much of the underlying details are unobservable.<p>It&#x27;s not impossible in theory, but it seems like it would mandate all browsers use the exact same allocator implementation (say, dlmalloc version x.y.z). In addition, this would not allow optimization over time, again, unlike GC.<p>In the non-browser case, server-side implementations may not need to worry about specs, so more options may be open there.
评论 #18529400 未加载
jillesvangurpover 6 years ago
C is unsafe because it comes with no memory protections. In an environment like a typical operating system (depending on the OS of course), there&#x27;s a chance it will escape its sandbox. This risk does not exist in wasm. You can write the most atrociously misguided C ever and run it in wasm and know for sure that it will never do anything worse than corrupt its own program state.<p>You get similar benefits by using a decent OS and&#x2F;or by putting the untrustworthy code in e.g. a docker container. It&#x27;s still code that can&#x27;t be trusted but at least you are setting some hard boundaries that have no easy&#x2F;known ways of being bypassed.<p>However, it would still be bad if the program gets compromised. If, say, you are handling some credit card details and are using some C code to do that and it gets compromised, all of the interesting stuff (i.e. the credit card details) would be inside those boundaries. This is why using C to do that is not a great idea.<p>This is a concept that is often misunderstood by people: most of the interesting stuff (from a hacker point of view) happens inside the sandbox. This is where you access and handle sensitive data and access protected resources (e.g. a third party website). Many attacks use relatively low tech mechanisms such as script injection, man in the middle attacks, social engineering, etc.<p>Wasm indeed does nothing to protect against that. If you are handling user input in any way, that is potentially a way for hackers to inject code in your sandbox. If that sandbox has access to or control over anything interesting, that just got compromised. If you are using a language that is notorious for its decades long history of input validation mechanisms getting compromised (cough C cough), that means you can&#x27;t trust input validation to function properly even inside a wasm container.<p>This is exactly how many browser attacks work. They don&#x27;t install viruses on your machine or whatever but they simply trick you into revealing your credentials, visiting some evil website, or entering your credit card. A bit of injected javascript or a redirect is all that this takes. Any injected code never leaves the sandbox; it doesn&#x27;t have to.
评论 #18532742 未加载
cyberbulletsover 6 years ago
There is also another blog post (link to white paper inside) that talks about different memory safety issues with WebAssembly if using a memory-unsafe language: <a href="https:&#x2F;&#x2F;www.forcepoint.com&#x2F;blog&#x2F;security-labs&#x2F;new-whitepaper-memory-safety-old-vulnerabilities-become-new-webassembly" rel="nofollow">https:&#x2F;&#x2F;www.forcepoint.com&#x2F;blog&#x2F;security-labs&#x2F;new-whitepaper...</a>
kbumsikover 6 years ago
&gt; First, hosts have no visibility on how memory is being managed within a guest. Want to diagnose memory leaks? Good luck with that.<p>Is that really true? I think we can implement a memory allocator done by hosts. By using &quot;import&quot; feature of WASM, a guest could implement a memory allocator that imports functions from the host that ask the host to look through the gest&#x27;s memory directly (it is possible in JS code) and then allocate one. Maybe it will be slower but it is certainly possible that hosts can know what is happening to the memory in this way.
pier25over 6 years ago
I love the idea of WebAssembly in the browser, but what&#x27;s the point of using it as an universal module language everywhere else?<p>We can already run most popular languages pretty much anywhere, and I imagine at better performance than WebAssembly, no?
评论 #18530700 未加载
abecedariusover 6 years ago
&gt; Memory is represented as a single linear block<p>iirc you can have multiple instances or modules, each with its own private linear memory, and they can be set up to call each other&#x27;s exported functions. It&#x27;s just that current compilers don&#x27;t use that encapsulation when compiling a single program. Am I wrong about this?<p>(I haven&#x27;t used WebAssembly, only read about it some time ago. But here&#x27;s a link in support: <a href="https:&#x2F;&#x2F;groups.google.com&#x2F;forum&#x2F;#!topic&#x2F;e-lang&#x2F;3A6zYWF6u5E" rel="nofollow">https:&#x2F;&#x2F;groups.google.com&#x2F;forum&#x2F;#!topic&#x2F;e-lang&#x2F;3A6zYWF6u5E</a> &quot;Multiple module instances only share an address space if they explicitly export&#x2F;import a linear memory, which is just another kind of module-level definition. A module can define its own linear memory and not export it, in which case nobody else can access it.&quot;)
评论 #18529951 未加载
dmitrygrover 6 years ago
this is complete nonsense. A normal c program running on a modern operating system has the mmu control what memory it can access. So, Web assembly&#x27;s &quot;just a block of memory&quot; is no better - it is the same.
评论 #18528614 未加载
评论 #18528860 未加载
devitover 6 years ago
NULL pointing to valid memory seems like a serious flaw that can and should be easily fixed.
评论 #18529542 未加载
kiriakasisover 6 years ago
&gt; While escaping the sandbox itself may be difficult to achieve, application security doesn’t benefit from the mitigations commonly found in traditional environments.<p>I feel this the most important point regarding use server-side.
kiriakasisover 6 years ago
There is a yet in the original title.