176 points · by steveklabnik · 5y ago · 125 comments
> Our kernel, Zircon, is not in Rust. Not yet anyway. But it is in a nice, lean subset of C++ which I consider a vast improvement over C.
A few thoughts on this.
1. Why is it that Chrome hasn't had more Rust adoption? It's so obvious - Chrome constantly has to make the tradeoff of security vs performance with regards to things like parsing in sandboxed code. There's so much potential - Firefox started with the obvious place, encoding and decoding, which are too dangerous for C/C++ but too performance sensitive for OOP.
Feels like it's gotta be organizational, and somehow Fuschia has managed to break off from the part of Google that's still clutching to C++.
2. I'd be interested in hearing more about the design of Fuschia. Rust in userland is cool, or kernel modules too, but a memory unsafe kernel is an unfortunate thing. Even just the teaser of "not yet at least" is changing my view on the OS (I find the idea of another memory unsafe kernel/userland more depressing than exciting, even if there are neat things like capabilities).
3. Also curious to hear about their experience with a strict subset of C++. Again, looking at Chrome, we now see common ITW exploits - and Chrome is perhaps the single most fuzzed piece of software in the world, and leverages many modern C++ techniques (or the Google equivalent of them).
As for the rest, verified execution seems interesting - is this like what iOS does, where it's basically impossible to RWX (except with an escape hatch for JITs, but behind a permission boundary)?
TBH if Google pivots Fuschia to do something interesting like bottom-up memory safety with novel isolation mechanisms, I'll bite. Until then, I'll wallow in this awful pit we continue to dig ourselves into.
[1] https://chromium.googlesource.com/chromium/src/+/refs/heads/...
See also the recent posts from the V8 team, ex. https://v8.dev/blog/high-performance-cpp-gc
Proof's in the pudding. ITW exploits are there.
Mostly likely because Chrome started in C++ (WebKit) and so there is millions of lines of existing C++. Fuchsia, being new, didn't have that legacy.
Note: they're looking into it
https://www.chromium.org/Home/chromium-security/memory-safet...
[0] https://fuchsia.dev/fuchsia-src/concepts/kernel/zx_and_lk [1] https://github.com/littlekernel/lk [2] https://github.com/littlekernel/lk/commit/1d0df6996457273367...
Fuchsia development has been ongoing for quite long as well but most of the code base is from more recent times. When they first announced Fuchsia, they did not talk about Rust at all. But obviously they managed to attract some Rust developers since then and perhaps made a conscious choice to not use C++ for new development and try to contain what they had already as much as they could where it was already there.
It's one of those high level technology choices that kind of became an obvious one a few years ago. If your goal is to develop fast and secure software, Rust seems the preferable language. Google has the track record to prove that C & C++ are inherently risky since despite decades of trying to prevent issues, they regularly have to deal with them still. Including in new code. I imagine somebody at a high level just drew a line in the sand and put a stop to most new C++ development on Fuchsia. Do it right the first time. Or something like that.
> In conclusion. Too early, lack of experts, rapid evolution pains. It was stacking risk on top of an already risky project.
Rust was extremely immature and too early to be used in an OS at the time. It just hit 1.0. By then, Fuchsia already wrote its kernel Magenta (now Zircon) in C++.
In short, it did not make sense to write the OS kernel in Rust from both a technical and business standpoint at the time.
If someone with more knowledge on C and Rust compilers and security, I would be interested in their opinion on this.
I think to some extent this used to be true, and to some extent still is.
Rust didn't always have MIRI support which points out if you try to do some unsound thing. Maybe 4 years ago you would have been the first person to use a specific niche static analyzer that builds on LLVM with Rust, so there would have been bugs inevitably. Same goes for wanting to analyze both the C and Rust that call each other. So static analyzer support has improved I think.
Also, C is better understood while in Rust it's less obvious how things need to look like. With better understood I don't mean by the developers who write the code, but from a language specification point of view. E.g. views have evolved on how accessible uninitialized memory should be in unsafe Rust, so MaybeUninit has been added. It's only two years old at this point.
Also there is the issue of safe interfaces between languages. In the days before cxx, if you had a "safe" cpp smart pointer, moving it to Rust and back would have involved possibly more unsafety than operating on that smart pointer yourself.
There has also been the long standing issue of unwinding at FFI boundaries.
If you have a codebase with 5 thousand lines of cpp and now replace 1 thousand lines with a Rust component of 500 lines, it might still be a better idea to just keep the old solution and give it a thorough review. It's different I think if you have a codebase with 5 million lines of cpp though and replace one component of 50k lines that has a clean interface but is an extreme source of vulnerabilities. It's a question of how dangerous "surface" is between the two languages.
Does all of this mean you shouldn't invest into Rust? Absolutely no. If it's a 5k lines codebase, you can rewrite it completely. If it's a 5 million lines codebase, I'm sure you'll find a security bug ridden component that is well isolated that you can replace.
It's unclear what they're trying to say, but a charitable interpretation would be that C code assumes unsafety, therefor mitigations are in place. But it's actually the opposite situation - rustc is generally quite aggressive about turning mitigations on, and adopts them very quickly.
It's a Google project, and I wouldn't be surprised if it eventually makes its way into Chrome.
[1] https://bugs.chromium.org/p/skia/issues/detail?id=8235 [2] https://github.com/flutter/flutter/issues/23838
Basically to rewrite one DOM feature in rust would have a high likelihood of requiring rewriting the entire DOM implementation in rust, which would also require rearchitecting. While doing that other people would be wanting to continue working, but they don't have a rust build to work on so they have to continue in c++, thus sadness and conflicts. The other solution is to implement features in rust, and use a c++ wrapper to interface with that rust implementation, but now you've lost the memory safety advantages of rust (most of which are lifetime related, not bounds checking), and the C++ interface itself could be exciting as it could end up having to marshal other types.
It also applies, partially to COM/UWP, with the "small" difference that to this day, Borland/Codegear/Embarcadero tooling, is ages ahead of the notepad like experience for the IDL files.
Sometimes I wish the WinDev team would spend some time with IPC implementations on other platforms to understand what they are missing, regarding their Stockholm syndrome in COM tooling.
With Fuchsia there is yet another example to learn from.
There are OSes that use the language for safety and have a single process but having to use memory safe languages is a pretty big limitation! Plus I would imagine it is easier to prove process security than language security.
https://en.wikipedia.org/wiki/Singularity_(operating_system)
https://github.com/lastweek/source-singularity/tree/master/b...
Microsoft and Oracle have removed CAS and JAAS from CLR/JVM respectively as they have failed to provided the software isolated model that was expected from them.
Rust is only memory-safe and only as long as you stay away from unsafe code. It is not magic pixie dust.
1. https://github.com/paulbartrum/jurassic
2. https://en.wikipedia.org/wiki/Singularity_(operating_system)
> Ideally everything would just be in a single process.
Processes are an amazing boundary, probably the most powerful abstraction in existence.
> Why are new systems exposing the ability to dereference raw pointers to user programs?
This shouldn't be possible today - SMAP/SMEP are standard now.
> obsoleting the need for hardware isolation
I think if the last 3 years (sidechannel frenzy) has taught us anything, it's that software-isolation is extremely difficult. Even hardare isolation is difficult.
Any real example where this makes sense on an internet-connected device?
Rust programmers use unsafe escape hatches all the time BTW.
I wonder why they stuck with Salsa20 instead of ChaCha20. The latter has got better performance characteristics and is by now more popular, having found its way e.g. into TLSv1.3.
https://fuchsia.googlesource.com/fuchsia/+/8b2bb8a5d1a0/zirc...
Android has an absolutely shit audio stack. iOS simply destroys Android on this front.
Fixing that requires that you architect the entire kernel around making sure that you can service the audio stack in real-time with low latency.
The fact that I haven't seen even the slightest mention of this makes me worry that the Fuchsia folks haven't really learned any lessons from Android and are simply repeating the same mistakes.
Granted, the NDK is anything but friendly, but the option already exists for the last couple of Android versions.
From https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/d...
> This document proposes a mechanism for running unmodified Linux programs on Fuchsia. The programs are run in a userspace process whose system interface is compatible with the Linux ABI. Rather than using the Linux kernel to implement this interface, we will implement the interface in a Fuchsia userspace program, called starnix. Largely, starnix will serve as a compatibility layer, translating requests from the Linux client program to the appropriate Fuchsia subsystem.
So they will be able to run unmodified Linux binaries which should allow for a smooth transition from Android/Linux.
I'm not even sure that they'll rebrand Android at that point, as kernel for users is invisible. My guess is they'll just replace Linux with Fuchsia.
Remember there are Android APKs containing native Linux banaries (made with Android's NDK) that you should be able to run. That is the whole main point of Fuchsia' starnix. I think this is even mentioned on starnix's RFC.
Both. If CastOS (which is Linux-based) for the Google Nest Hub was already replaced via an update, it is completely obvious that Fuchsia is not only here to stay, but will definitely replace Android AND ChromeOS.
I think Unix has had its day and its quite refreshing to see a new OS that is designed for security and is actually optimised for modern hardware and CPU architectures from the start.
Downvoters: So Google did NOT just replace the Linux-based CastOS on the latest Google Nest Hub update with Fuchsia and it is still an 'experiment' that some were still hoping for? [0] Are you prepared to present evidence against my answer to the parent's question?
There is no need to be scared of change, especially when Google inevitably replaces Android and ChromeOS with Fuchsia.
[0] https://github.com/termux/termux-packages/wiki/Termux-and-An...
Fuchsia might be used more widely that we know inside Google.
I recall a early goal of fuchsia was to be able to build fuchsia with fuchsia, I wonder when the workstation build will be up to that stage.
fx list-boards arm64 as370 chromebook-x64 * qemu-arm64 qemu-x64 toulouse vim2 vim3 vs680 x64 x64-reduced-perf-variation
fx list-products bringup core terminal workstation
I think the main reason is so they can provide a stable driver ABI so that it becomes possible to update Android.
They're probably also frustrated with Linux's security (hence this post) and having to maintain out of tree patches (e.g. Binder).
PS 4 uses an open source OS, how much have you seen of it?
And of course, there would be some very legit reasons not to use GPL - like embedding ZFS into the kernel. Which would be no license issue for Fuchsia.