17 ms·
Unfortunately, it's the same old story. A fairly trivial buffer overflow programming error in C++ code in the kernel parsing untrusted data, exposed to remote a
by Animats 6y ago
Unfortunately, it's the same old story. A fairly trivial buffer overflow programming error in C++ code in the kernel parsing untrusted data, exposed to remote attackers. In fact, this entire exploit uses just a single memory corruption vulnerability to compromise the flagship iPhone 11 Pro device. With just this one issue I was able to defeat all the mitigations in order to remotely gain native code execution and kernel memory read and write.
Yes, same old buffer C/C++ overflow problem. We have mainstream alternatives now. C#. Go. Rust. It's time to move on.
- colesantiago 6y agoIMO this is huge. Thankfully, Apple is starting to hire Rust developers as well as AWS. The tide is changing, one day we will see some Rust code in iOS/macOS so that these issues are a thing of the past.
- zepto 6y agoIt seems unlikely that they’ll solve the problems in iOS with Rust. It seems much more likely that they will use Swift in some form.
- KMag 6y agoSwift seems an unlikely choice for incrementally replacing portions of kernel code.
- zepto 6y agoIn its current form perhaps this is true. However Chris Lattner and others have expressed the desire to have it be suitable for systems programming. There is reason to believe they will adapt it.
- KMag 6y agoHas Chris specifically mentioned OS kernel programming? As the Golang team have pointed out, there's lots of systems programming going on in userspace, which is what they refer to when they call Golang a systems programming language. That being said, ARC is probably easier to get to work well in-kernel vs. tracing garbage collection. There's a performance cost to all of those reference count updates, but at least the variance is extremely low.
- pjmlp 6y agoApple clearly states Swift is a systems programming language. > Swift is a successor to both the C and Objective-C languages. https://developer.apple.com/swift https://developer.apple.com/swift > Swift is intended as a replacement for C-based languages (C, C++, and Objective-C). https://swift.org/about/ https://swift.org/about/
- KMag 6y agoThere are systems languages and then there are systems languages. As the Golang team have pointed out, there's lots of systems programming going on outside of OS kernels. Neither of those links mention kernel development. Pervasive refcount updates (ARC) and a vtable-unfriendly dynamic dispatch mechanism inherited from Objective-C are fine for userspace, but most kernel code is very performance-sensitive.
- pjmlp 6y agoGo team only changed their message due to the pitch forks they were getting from the UNIX/C crowd. There are people that believe systems programming languages in an OS kernel is doable with some form of GC, and then there those that will never change their mind. https://www.f-secure.com/en/consulting/foundry/usb-armory https://www.f-secure.com/en/consulting/foundry/usb-armory https://blog.arduino.cc/2019/08/23/tinygo-on-arduino/ https://blog.arduino.cc/2019/08/23/tinygo-on-arduino/ https://gvisor.dev/ https://gvisor.dev/ https://github.com/mit-pdos/biscuit https://github.com/mit-pdos/biscuit https://github.com/ycoroneos/G.E.R.T https://github.com/ycoroneos/G.E.R.T By the way, NeXTSTEP drivers were written in Objective-C, and the new userspace framework, DriverKit, is an homage to the NeXTSTEP driver API. https://www.nextop.de/NeXTstep_3.3_Developer_Documentation/OperatingSystem/Part3_DriverKit/Concepts/1_Overview/Overview.htmld/index.html https://www.nextop.de/NeXTstep_3.3_Developer_Documentation/O...
- KMag 6y agoI'm familiar with Biscuit and Midori. The Biscuit paper estimates a 10% performance hit in syscall-intensive benchmarks due to using Golang vs. C. That being said, ARC may faire much better than a tracing GC, particularly in latency variance, throughput variance, and mean heap usage. Though, I think we're best off moving off of hypervisors and onto 4th generation microkernels with isolation similar to AIX LPARs / Solaris Containers. After all, a hypervisor is essentially a microkernel that's forced to use hardware traps/faults plus hardware emulation for its syscall interface (plus upcalls for performance, which use a calling convention much closer to traditional syscalls). There are stability, security, and performance advantages to throwing out all of that hardware emulation code, moving everything to upcalls, and getting rid of the second (guest OS) kernel running between the application and the hardware. If you push most of the system functionality out of kernel space, then rewriting some of the less performance-critical components in a language with ARC or tracing GC starts to make more sense.
- blub 6y agoBy the time we all retire in a few decades they'll be a thing of the past, probably. There's so much low-hanging fruit to pick in that code and switching to Rust is like saying that we should go to Mars to pick fruit instead.
- q3k 6y agoAs much as I like to bash security critical code written in memory-unsafe languages, I don't think that this is the crux of the problem here. To me it's that this extremely trivial bug (the heap overflow, let's ignore the rest for now) passed through code review, security review, security audits, fuzzing... Or that Apple didn't have these in place at all. Not sure which option is worse.
- vlovich123 6y agoSuch bugs are extremely difficult to prevent at scale. Even the most talented engineers make such mistakes and programming quality varies significantly even within top engineering teams which are usually comprised of people with different skill sets (+ junior engineers that need training). Safe languages are the only way forward to drastically reduce the problem. It can’t be guaranteed to be eliminated 100% obviously because there are still escape hatches available, but it will be significantly improved because you can limit the surface area where such bugs can live.
- SulfurHexaFluri 6y agoNot sure if this is common for everyone but I find whenever I get assigned for a review for a monster change, I spend over an hour just working out what the change does and if it seems like it will work. There is no way I could spot tiny potential security exploits in 3000 lines of changed code.
- Xenograph 6y agoSending 3,000+ LoC code reviews is not considered good engineering practice. In general it's important to keep code reviews small for the reasons you describe. If it's impossible to make incremental changes in smaller units, that's a sign of an unhealthy code base.
- HereBeBeasties 6y agoAlthough it is certainly challenging, you shouldn't spend only an hour reviewing a 3,000 LoC review, unless most of it is trivial refactoring, especially if that code is security-critical and handles untrusted input. That's only 1.2s per line of code. No chance you have good quality control with that amount of attention. If it's taken someone a whole fortnight to write it, you should expect to spend at least half a day reviewing it, IMO.
- Gibbon1 6y agoCould also fire everyone on the C/C++standards bodies and replace them with people willing to add arrays as a first class data type.
- Animats 6y agoI had that argument with the C standards people a decade ago. [1] Consensus was that it would work technically but not politically. The C++ people are too deep into templates to ever get out. The basic trick for backwards compatibility is that all arrays have sizes, but you get to specify the expression which represents the size and associate it with the array. So you don't need array descriptors and can keep many existing representations. Also, if you have slices, you rarely need pointer arithmetic. Slices are pointer arithmetic with sane semantics. I'm tired of seeing decade after decade of C/C++ buffer overflows. It speaks badly of software engineering as a profession. [1] http://www.animats.com/papers/languages/safearraysforc43.pdf http://www.animats.com/papers/languages/safearraysforc43.pdf
- Gibbon1 6y agoThe political aspect is why I suggest the solution is to just up and fire all those guys. More realistically Microsoft, Apple and Linus could just force the issue. Gets added to Visual C/C++, LLVM, and Gnu C as an extention. And then start polluting code bases and API's with it.
- saagarjha 6y agoI read this line: > Gets added to Visual C/C++, LLVM, and Gnu C as an extention. And had to do a double-take because I thought you were talking about gets(3)…
- pjmlp 6y agoMicrosoft is already kind of doing it, if you compile in debug mode, you get bounds checking in all STL types, and you can enable them in release builds as well. But yeah, it only works if you use those types. There are other divisions pushing for .NET and Rust systems code in Windows, but the political wars between WinDev and DevTools are quite well known, e.g. Longhorn (in .NET) vs WinRT (same thing just in COM).
- pfundstein 6y agoC#? You've got to be joking.
- snazz 6y agoC#, Go, and Java all go in the same category (roughly)—they wouldn't work for kernel code. Rust will be a valid replacement for C++ kernel code in the near future, I'm sure.
- deleted 6y ago[deleted]
- saagarjha 6y agoWriting the majority of a kernel in those languages is certainly possible.
- pfundstein 6y agoPossible, perhaps, but feasible? Microsoft certainly had a go at it with the likes of Midori and Singularity, but these were met with the same fate that will likely befall any managed code kernel. While it's an honorable pursuit with certain merit, to produce a fully featured OS in this way -- without serious concessions -- is just not feasible.
- pjmlp 6y agoThose projects died due to management politics from WinDev, nothing to do with capabilities. So much that many of the System C# features are now in .NET 5 and other ones will eventually land on .NET 6.
- yencabulator 6y agoHere's a POSIX kernel in Go, written explicitly to prove your point wrong: https://github.com/mit-pdos/biscuit https://github.com/mit-pdos/biscuit https://pdos.csail.mit.edu/projects/biscuit.html https://pdos.csail.mit.edu/projects/biscuit.html
- djeiasbsbo 6y agoYes, but what about these huge legacy codebases like the iOS kernel? I assume we will have to deal with this type of vulnerability for years to come...
- olliej 6y agoC# is GC'd so massive memory hit, and also not a language you can have in a kernel. Go: GC again, so no go. Rust: most sane of the examples you've given. Apple has already started migrating to Swift which is a memory safe language. However the real reasons Rust and Go aren't feasible is that they're both essentially all-or-nothing, and neither offers even the most basic semblance of ABI compatibility. Their only nod to ABI stability is "use FFI to C" which means your APIs remain unsafe, and doesn't work for non-C languages without all your system APIs having other languages layered on top. Swift at least lets you replace individual objc classes one at a time, and is ABI stable, but has no C++ interaction.
- gfxgirl 6y agoSwift is far more like C# than Rust in terms of memory management. Sure it uses ARC but arguably that makes it not suitable for kernel level stuff.
- olliej 6y agoxnu is refcounted, its also c++ which isn't swift friendly. XNU also has ABI stability requirements which rules out rust.
- deleted 6y ago[deleted]
- blub 6y agoThe code where the bug happens is legal C++, but it uses absolutely none of the memory safety improvements which were added to the language in the past... twenty years probably. It's basically C with classes. If they haven't kept up with the changes in their current language, what makes one think that they would "move on" to the alternatives, two of which aren't even alternatives? Before they switch to Rust it would be much faster and more efficient to use smart pointers, std::array, std::vector and stop using memcpy.
- saagarjha 6y agoNote that this code is shipping as a kernel extension, which uses Embedded C++, not standard C++. Notably, things like templates and exceptions are not available. It would be nice if they could work on this instead, but looking at the dyld and Security sources (which has no such limitations, as the run in userspace) I don't have much confidence.
- pjmlp 6y agoThey could still make use of bounds checking, like my own classes did back in the MS-DOS days, when C++ARM was pretty much the only thing available. Naturally when one writes C in C++ it doesn't help.