On Tue, 10 Jan 2023 17:27:33 GMT, Justin King <jck...@openjdk.org> wrote:
>> This change instruments Metaspace for ASan. Metaspace allocates memory using >> `mmap`/`munmap` which ASan is not aware of. Fortunately ASan supports >> applications [manually poisoning/unpoisoning >> memory](https://github.com/google/sanitizers/wiki/AddressSanitizerManualPoisoning). >> ASan is able to detect poisoned memory, similar to `use-after-free`, and >> will raise an error similarly called `use-after-poison`. This provides and >> extra layer of defense and confidence. >> >> The header `sanitizers/address.h` defines macros for poisoning/unpoisoning >> memory regions. These macros can be used regardless of build mode. When ASan >> is not available, they are implemented using a NOOP approach which still >> compiles the arguments but does so such that they will be stripped out by >> the compiler due to being unreachable. This helps with maintenance. >> >> This also has the added benefit of making >> [LSan](https://bugs.openjdk.org/browse/JDK-8298445) more accurate and >> deterministic, as LSan will not look for pointers to malloc memory in >> poisoned memory regions. >> >> IMO the benefit of doing this greatly outweighs the cost. > > Justin King has updated the pull request incrementally with one additional > commit since the last revision: > > Use macros from <sanitizer/asan_interface.h> when available and update > justification > > Signed-off-by: Justin King <jck...@google.com> src/hotspot/share/sanitizers/address.h line 45: > 43: #else > 44: #define NO_SANITIZE_ADDRESS > 45: #endif The `NO_SANITIZE_ADDRESS` macro doesn't seem to be used by this patch. src/hotspot/share/sanitizers/address.h line 53: > 51: // <sanitizer/asan_interface.h>. When ASan is not available this macro is > a NOOP which preserves the > 52: // arguments, ensuring they still compile, but ensures they are stripped > due to being unreachable. > 53: // This helps ensure developers do not accidently break ASan builds. Maybe the "When ASan is available ... do not accidently break ASan builds." parts can be combined for the two macros to avoid duplication? ------------- PR: https://git.openjdk.org/jdk/pull/11702