RFR: 8369393: NMT: poison the canaries of malloc header under ASAN build [v2]

Johan Sjölen jsjolen at openjdk.org
Wed Oct 8 12:13:21 UTC 2025


On Wed, 8 Oct 2025 11:35:42 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:
> 
>   include sort

src/hotspot/share/nmt/mallocHeader.hpp line 142:

> 140:       footer_address()[0] = (uint8_t)(v >> 8); footer_address()[1] = (uint8_t)v;
> 141:     }
> 142:   #endif

I'd prefer the following. Then we keep the simple definitions separate and as small as previously.

```c++
#if INCLUDE_ASAN
  // Insert your defs here.
#else
  uint8_t* footer_address() const   { return ((address)this) + sizeof(MallocHeader) + _size; }
  uint16_t get_footer() const       { return build_footer(footer_address()[0], footer_address()[1]); }
  void set_footer(uint16_t v)       { footer_address()[0] = (uint8_t)(v >> 8); footer_address()[1] = (uint8_t)v; }
#endif

src/hotspot/share/nmt/mallocHeader.hpp line 191:

> 189:     inline bool is_poisoned() const { return false; }
> 190:     inline void set_poisoned(bool poison) { }
> 191:   #endif

Please do the same type of separation that I suggested above.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27685#discussion_r2413634910
PR Review Comment: https://git.openjdk.org/jdk/pull/27685#discussion_r2413642636


More information about the hotspot-runtime-dev mailing list