4 ms·
Zig is not memory safe.
by laerus 3y ago
Zig is not memory safe.
- dragonelite 3y agoIs it memory safe enough and if it helps mitigating other kinds of errors without being in the way. It will find its place in the programming world. I think what zig really needs is something like the rust Axum ecosystem for web backend development. I would never be able to make a zig case at work without those sort of frameworks. People would say why zig without web related packages when you also have GOlang.
- pjmlp 3y agoA recipe for CVE waiting to happen, plugging a memory-safe-enough into the Internet, for someone to take advantage of a UAF that wasn't tested.
- flohofwoe 3y agoThe browser's WASM runtime is already a safe sandbox. There's really not much point in 'double sandboxing' both on the language and runtime level.
- pjmlp 3y agoIf that is the only place Zig is ever going to be used, then no worries, I guess. WebAssembly sandboxes apparently are going to sort out all security issues in modern computing.
- cygx 3y agoIn order to be useful, a sandboxed program needs to communicate with the environment (the equivalent of system calls). If you can corrupt internal state, you can control the arguments to those calls, which may have security implications. For example, if you corrupt a program that's allowed to use web sockets, you'll be able to port scan the user's local network.
- flohofwoe 3y agoIf that actually works in a browser wasm environment then it's also possible from Javascript, which is a memory safe language (eg either the sandbox works or it doesn't, that also includes the external APIs).
- cygx 3y agoSure. Under that perspective, it's basically a new vector for XSS attacks.
- IshKebab 3y agoYou can still have memory safety bugs in WASM. The difference is that they can only do memory unsafe things within the sandbox. That's better than nothing but still not as good as actual memory safety.
- flohofwoe 3y agoFrom a security pov it doesn't make a difference though, the sandbox needs to be able to safely contain untrusted code, no matter if the code is riddled with memory bugs or not.
- IshKebab 3y agoHow do you figure? Imagine a server component that runs in wasm (pretty common). Memory safety bugs could easily lead to information leaks and privilege bypass entirely within the wasm sandbox.
- flohofwoe 3y agoThe important part is within the wasm sandbox. Don't run multiple components in the same WASM instance because they can't be properly isolated from each other. That's why traditional operating systems have processes that can't access each others memory. WASM instances don't have this sort of "internal isolation", anything running in the same instance can access all memory in that instance, memory safe language or not. Again, language-level safety doesn't matter here. It makes a lot of sense to write the sandbox itself in Rust, but it must not matter whether code running inside the sandbox is written in Rust. If that would be required, the sandbox has already failed.
- cygx 3y agoAgain, language-level safety doesn't matter here It very well can: For example, let's assume you have a graphics editor running in the browser that stores files in the cloud. If it uses a vulnerable C library to decode image data, an attacker might be able to play havoc with your files despite the sandbox never technically having been breached. This can be mitigated by either using a safe language, or having the decoder run in an isolated wasm instance. Either way, you have to design your application with these considerations in mind and can't just take arbitrary, potentially vulnerable applications, compile them to wasm and be done with it.
- angra_mainyu 3y ago> Is it memory safe enough I'd say for the vast majority of use cases, it is. Pluggable allocators + good test coverage make it trivial to catch a lot of the more common memory issues and exhaustive switches are quite robust (though it can be tricky when the branches vary according to the target platform). Also, it is far easier to code in an exploratory, iterative fashion in Zig than it is in Rust. Overall, I think with Zig and Go you can cover a lot of programming use cases. In fact, I find Go to be pretty damn fast out-of-the-box and in a lot of real world scenarios can match Zig/Rust (production builds). All three have room for fine tuning (at the expense of readability), though of course the ceiling is much higher in Zig and Rust. Not to mention, Rust won't protect you from logic issues, you can definitely do the wrong thing correctly.
- logicchains 3y agoFor some of the biggest C++ use cases, video games and HFT, this absolutely doesn't matter.