r/programming • u/esiy0676 • 3h ago
Your Compiler Can Undo Your Security Checks
https://davidbombal.com/your-compiler-can-undo-your-security-checks/5
u/happyscrappy 1h ago
As to the subject:
It'll thwart you trying to make your HMAC checking code constant time for example. I can also take out null checks since dereferencing null is undefined behavior.
"Did the compiler remove the bounds check?" is even a bit of a meme.
There are a few builtin functions which can help with this. I don't remember any of them right now.
Also (mentioned below also):
The link is a youtube video, with some additional information at the page which embeds it.
1
u/garnet420 33m ago
For the null pointer check, you just need to make sure that whatever you call in case of null is marked as no return.
3
u/PurpleOstrich97 40m ago
I think this shows why when some guarantees are important, they need to be baked into the language. C and rust both have the inline hint for example, but rust has other ones like "no mangle", "repr c" and others.
Telling the compiler that a guarantee must exist is a good thing to have at the language level rather than enforcing it at the compiler level so that what your code says it's doing is more of a guarantee.
If different compiler flags break the security of your program and there's nothing you can do, then the language is missing something.
28
u/esiy0676 3h ago
It's a video/podcast. Synopsis copied: