RFR: 8369393: NMT: poison the canaries of malloc header under ASAN build [v14]
Johan Sjölen
jsjolen at openjdk.org
Thu Oct 16 11:12:09 UTC 2025
On Thu, 16 Oct 2025 09:31:41 GMT, Afshin Zafari <azafari at openjdk.org> wrote:
>> NMT can detect malloc'd memory corruption using canary tests at header and footer of every memory region. This can only be done at free time of the memory where NNT checks the canaries and report error if they are not as expected.
>> In this PR, the canary parts also are poisoned using ASAN API to get notified whenever a read/write op is done. on the canary parts. `_size` member of the malloc header is also poisoned, since it is used for finding the footer address.
>
> Afshin Zafari has updated the pull request incrementally with one additional commit since the last revision:
>
> AHP -> sanitizers/address.hpp
Hi Afshin, please have a look at this change set: https://github.com/jdksjolen/jdk/commit/3688d28b52eda05a39c4c1881932db85b09ce168
- I use `aph` instead of `_temp`, this is the typical naming style in Hotspot for RAII-objects which are solely for temporarily altering state.
- I use Class template argument deduction (CTAD) to not have to specify the types. Unfortunately, we can't do this for the static method calls
- I remove the `using` types. we might want to have that back in, but it should be used consistently over all of the code. The original use case (setting them to void when ASAN isn't present) is no longer valid, so I removed them.
- I separated out the poisoning method into both `poison` and `unpoison` variants instead of using a boolean, and I also mention `asan` in the name. This is to be extra clear that this is code is only relevant for asan, and also avoids having the user understand a boolean. I also made it private, as it's only used internally now
- I made the input args to the helper `const T*`, as we never plan to actually touch the memory. This is consistent with the ASAN API function prototype: `void __asan_poison_memory_region(void const volatile *addr, size_t size);`
Please consider taking this as a patch, it should apply cleanly to commit [c644a84](https://github.com/openjdk/jdk/pull/27685/commits/c644a84a4377d984c66bf9168f8cb4c115a8e13d)
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27685#issuecomment-3410347790
More information about the hotspot-runtime-dev
mailing list