by fefe23 · 4y ago · 0 comments
Investing in mitigations is not free. The time and effort it takes to develop them is not available for constructing bug-free code. And once you have them, there will be even less reason to construct bug-free code. After all the magic hardware-assisted mitigations will save us now.
We've been through this before multiple times now. Someone will find a way to exploit around your mitigation, and you will then double down and come up with the next mitigation that will also be circumvented eventually.
Personally I believe that "retrofitting" security can never work well. Security must be constructed, not retrofitted. Why is this example code using raw allocations? Construct secure code by using containers, not manual allocations. This has been the recommendation for years now.
I feel like this is a bit of a false dichotomy. Writing bug-free code is one approach to getting bug-free software. Attempting to detect UAF at run time is another approach. And there are many other options beyond those two (static analysis, sanitizers, testing, ...).
In theory, we need only the ability to write bug-free code. If we could do this reliably, repeatedly, in a reasonable amount of time and at a large scale (Chromium, in this case), then there would be no value in investing in any of these other approaches.
In practice, fixing every last bug in a large codebase can take a truly immense amount of time. And that is for a codebase that is not changing at all (including bug fixes!), which certainly does not describe Chromium or most large projects for that matter.
Given all that, it's entirely reasonable to think about how one can find the most bugs with the least amount of effort. And that's basically what this is--another form of automated bug detection. I really don't think it's intended as a substitute for correct code.
I'm not advocating for "fixing all the bugs". On the contrary. I argue that retrofitting security does not work.
I argued that we need to find a way to construct secure software, not to make existing insecure software more secure retroactively. We have tried writing shitty software first and then try to make it more secure for decades now. The track record is not good. We should try something else. Like constructing secure software from the start.
Perhaps the longer-term solution is to use languages that are memory safe by design, such as Rust, to avoid that class of bugs. But there will still be a huge deal of legacy C++ code to contend with in the meantime, so we do still need exploit mitigations.
Clearly you can't expect programmers to just write secure code. If that worked, we would have seen evidence for it working by now.
By construct I mean: follow a clear method or path, that is a) feasible to follow and b) will lead to bug-free code. Maybe not bug free in all respects but I posit it should be possible to construct code without memory safety issues (just look at Perl or Rust).
My point is: It should not be up to the programmer to "simply not make mistakes". The method should be clear and have little ambiguity, and it should be obvious to see if code actually follows it or not.
I can't be more concrete or specific than that because I think we still need to find that method. We should be working on it, though.
Any software with complex object ownership written in a language without GC has to balance between user-after-free (freeing an object too early) and memory leaks (keeping an object alive longer than needed). Maybe constructing secure code here would mean simplifying object ownership, but that doesn't seem practical for a beast such a modern browser with millions of lines of code.
MTE with the heap scanning sounds like a real solution for the user-after-free problem, not merely a mitigation. The trade-off is that the memory is not immediately freed, but the measured increase of only 1% is promising.
- you have some AST object and want to lower it in the compiler into an intermediate representation
- you want to add some interesting parts of the AST to your state while lowering and refer to them later in the lowering process
- This seems fine: the AST is first created, then you lower to the intermediate representation, then you can destroy the AST, so while you’re doing the lowering, the AST objects should all be alive and therefore ok to store references to in the lowerer-state
- However there is some mostly unnoticed code that is roughly desugaring some syntax by constructing temporary AST nodes
- So your addition may have your state including references to these temporary nodes
- And those temporary nodes are freed shortly after being created rather than after the lowering is all done
- Giving a quite subtle use-after-free.
Something like C++ Core Guidelines, which include your remarks, is what should be looked into.
Naturally Chrome follows Google's C++ guidelines, so.
Certainly the efforts are welcome in any context in regards to C++ security improvements in mitigations, and C as well.
Now, the guidelines aren't the best up to date in what concerns writing secure C++, as per security standards.