6 ms·
Address Sanitizer Internals
- xtqctz 2y agoThis is great! I found these videos helpful, too: https://youtu.be/Tl1uZ7FBwFQ https://youtu.be/Tl1uZ7FBwFQ Does anyone know of a good explanation of HWAddress Sanitizer internals?
- barco 2y agoThere are multiple versions of HWAsan. One for ARMv8 with Top-Byte-Ignore: you can use the top byte of memory addresses to store a tag. When you allocate memory you return the "tagged" pointer and internally store "this region has this tag". When you dereference a pointer, you check that the tag matches what you expect in your internal data structure. With memory tagging extensions you can do something similar but the checks are performed by the processor.
- yosefk 2y agoOne thing this explains is why ASan has false negatives. It's a great tool, but the typical comment that it fully mitigates memory safety issues is just not true (even assuming your tests actually trigger the memory safety bugs, which unlike eg code coverage there's no knowing if you achieved or not)
- searealist 2y agoI've never seen anyone claim that.
- yosefk 2y agoIt comes up a lot in HN C++-related comment threads, for starters
- searealist 2y agoI've never seen anyone claim that asan fully mitigates memory safety issues in C++. Perhaps you could link to one?
- skobes 2y agoI've never seen that particular claim either, but I did previously believe that asan would reliably detect an out-of-bounds write if and when it occurs. So I learned something new from the OP (that this type of false negative is possible).
- searealist 2y agoYeah, I'm just responding to the guy who is probably the most internet-famous C++ hater in the world. I guess he likes to make up stuff too. The article is good.
- yosefk 2y agoadrian_b's comments in this thread are the kind of thing I referred to (my point wasn't that ASan specifically is presented as a panacea but rather various sanitizers in general.)
- searealist 2y agoAdrian's comments are nuanced and truthful. He said gcc offers an out-of-bounds sanitizer and listed some limitations. He does not say it makes C++ memory safe.
- nneonneo 2y agoThere’s nothing remotely nuanced nor truthful about this comment: https://news.ycombinator.com/item?id=40696242 https://news.ycombinator.com/item?id=40696242 He’s saying that with a compiler flag you can get the same kind of safety as in Ada or Rust. Later downthread he clarifies to say that you only get this safety if you stop using pointers, which he considers “trivial” to do. This is the same guy who commented a few months back saying the following: “All decent C compilers have compilation options so that at run-time any undefined actions, including integer overflow and out-of-bounds accesses, will be trapped.” There is, put simply, no flag that will trap on “any undefined actions”, period. That’s not what sanitizers are capable of. That’s the kind of overhyped comment that isn’t helpful when trying to understand what sanitizers are actually useful for.
- nneonneo 2y agoSome examples from 1 minute with Algolia: https://news.ycombinator.com/item?id=37479651 https://news.ycombinator.com/item?id=37479651 “All decent C compilers have compilation options so that at run-time any undefined actions, including integer overflow and out-of-bounds accesses, will be trapped.” “Despite the hype, by default Rust is not safer than C compiled with the right options, because the default for Rust releases is also to omit many run-time checks.” https://news.ycombinator.com/item?id=25922430 https://news.ycombinator.com/item?id=25922430 Upthread someone asks for a “-safe” flag which makes C a safe language. The reply is “It's called AddressSanitizer. You enable it with the compiler flag -fsanitize=address.” Several replies ensue pointing out how wrong this is.
- kccqzy 2y agoWho sanitizes the sanitizer? One of the most hilarious bugs I've previously seen is when someone found a memory out-of-bound access inside the run time support library of Asan.
- ThouYS 2y agosanitizers are a constant source of pain
- kimixa 2y agoAnd just like pain, they show you where the (likely) problem is. If you didn't have pain you'd still get the same damage to the body, you just wouldn't be aware.
- shric 2y ago"For this article, you’ll need the following knowledge: Basic C understanding (Memory, Stack, Heap, Syscall)." Obviously, since C doesn't prescribe any kind of heap, stack or syscall behavior (or if they even exist), I assume the author meant something like "Basic understanding of how C is often implemented on certain operating systems and hardware".
- mike_hock 2y agoYes, because asan only makes sense in the context of specific (kinds of) implementations.