Re:Low-Level Software Security for Compiler Developers
by rkagerer on Monday February 20, 2023 @08:46PM
(#34875447)
This is an interesting overview.
It mentions, regarding sanitizers (and presumably other safety tooling): "They are often too expensive to run in production mode, as they tend to increase execution time and memory usage."
I'm surprised we don't have better, performance-neutral hardware support for safety constructs like bounds checking.
Legacy x86 had a BOUND instruction but apparently it sucked and was so little used AMD didn't even bother to implement it... MPX exists but alas still has overheads in practice that can approach 50%... seems we can't match Lisp machines of decades ago that did it properly (in parallel) and for free [1].
Re:Low-Level Software Security for Compiler Developers
by cjbprime on Monday February 20, 2023 @10:48PM
(#34876250)
Bounds checking isn't the only type of memory unsafety detected by sanitizers: they can also detect things like use-after-free, undefined behavior, and so on.
Re:Low-Level Software Security for Compiler Developers
by wyldfire on Monday February 20, 2023 @11:17PM
(#34876509)
Once the data escapes the CPU via a load or store, it's hard to enforce something like a "type" in hardware. ALU instructions operating on what appears to be integers could easily have been operating unknowingly on virtual addresses. Even if you used the "integer add" instruction, there's no way for it to know that it didn't just index into a buffer using a virtual address as a base.
However there are cooperative ISA features -- between compiler and CPU -- these can be used to constrain untrusted attackers. See ARM PAC, e.g.
Re:Low-Level Software Security for Compiler Developers
by convolvatron on Tuesday February 21, 2023 @01:42PM
(#34884982)
the point is to put a guard when performing indirection, that checks a type bit in the register. setting this bit is a privileged operation. unprivileged address arithmetic can be performed if addresses also contain a bound.
but the whole point is that you just cant hand any integer to the hardware and ask it to fetch.
Re:Low-Level Software Security for Compiler Developers
by wyldfire on Monday February 20, 2023 @11:02PM
(#34876380)
ARM's MTE is often nicknamed "HWASAN" - it implements a lock-and-key metaphor. The memory allocations emitted by the compiler will get a "coloring" for the base pointed which can be matched with the specific region accessed by indexed loads and stores.
BTW this isn't just an experiment or research - some android developers have this enabled today and Android 14 beta has a user-configurable option to enable it.
Re:Low-Level Software Security for Compiler Developers
by wyldfire on Monday February 20, 2023 @11:20PM
(#34876541)
Yes, it's somewhat similar but much higher resolution. 16-byte "granules" instead of multi-KB/MB/GB pages. Also - instead of having the OS determine how to handle paging, the CPU can tell whether it should fail the load/store based on the color of the access and the color of the granule.
Re:Low-Level Software Security for Compiler Developers
by pjmlp on Tuesday February 21, 2023 @02:10AM
(#34877761)
Besides ARM in the sibling replies, Solaris on SPARC has been using ADI for a decade, iOS has PAC, CHERI is being worked on as Microsoft/ARM collaboration, and then there is ARM MTE on Azure Sphere as well.
Because we have come to the realisation that only "C Machines" can fix this issue, as even if Safe C would come tomorrow, the existing software wouldn't be rewritten anyway.
Re:Low-Level Software Security for Compiler Developers
by cjbprime on Monday February 20, 2023 @10:46PM
(#34876235)
This looks pretty great. If you prefer videos and examples you can walkthrough yourself, LiveOverflow's Youtube channel covers most of the sections here with more explanation:
It mentions, regarding sanitizers (and presumably other safety tooling): "They are often too expensive to run in production mode, as they tend to increase execution time and memory usage."
I'm surprised we don't have better, performance-neutral hardware support for safety constructs like bounds checking.
Legacy x86 had a BOUND instruction but apparently it sucked and was so little used AMD didn't even bother to implement it... MPX exists but alas still has overheads in practice that can approach 50%... seems we can't match Lisp machines of decades ago that did it properly (in parallel) and for free [1].
1: https://stackoverflow.com/questions/40752436/do-any-cpus-hav...
Modern languages have for value in arr, arr.forEach or equivalent. Such code makes it easier for compiler writers to make this optimization.
Swift even chose to remove for loops that step a variable (https://github.com/apple/swift-evolution/blob/main/proposals...), and I don’t think Rust has them, either.
I think that’s the right decision. In modern languages, classical for loops are a code smell.
And of course, golang goes the other way. https://go.dev/tour/flowcontrol/1:
Go has only one looping construct, the for loop.
The basic for loop has three components separated by semicolons:
- the init statement: executed before the first iteration
- the condition expression: evaluated before every iteration
- the post statement: executed at the end of every iteration
Those features were modern 40 years ago, even Visual Basic (pre-.NET) already had them.
However there are cooperative ISA features -- between compiler and CPU -- these can be used to constrain untrusted attackers. See ARM PAC, e.g.
but the whole point is that you just cant hand any integer to the hardware and ask it to fetch.
BTW this isn't just an experiment or research - some android developers have this enabled today and Android 14 beta has a user-configurable option to enable it.
https://docs.oracle.com/cd/E53394_01/html/E54815/gqajs.html
https://developer.apple.com/documentation/security/preparing...
https://msrc.microsoft.com/blog/2022/01/an_armful_of_cheris/
Because we have come to the realisation that only "C Machines" can fix this issue, as even if Safe C would come tomorrow, the existing software wouldn't be rewritten anyway.
https://youtube.com/@LiveOverflow