RFR: JDK-8298908: Instrument Metaspace for ASan [v13]

Justin King jcking at openjdk.org
Thu Jan 19 17:20:57 UTC 2023


> 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 15 additional commits since the last revision:

 - Merge branch 'master' into jdk-8298908
 - Update sanitizers/address.h based on review
   
   Signed-off-by: Justin King <jcking at google.com>
 - Use macros from <sanitizer/asan_interface.h> when available and update justification
   
   Signed-off-by: Justin King <jcking at google.com>
 - Update Metaspace-related tests to unpoison memory as required
   
   Signed-off-by: Justin King <jcking at google.com>
 - Update Metaspace-related tests to unpoison memory as required
   
   Signed-off-by: Justin King <jcking at google.com>
 - Fix leading comment whitespace
   
   Signed-off-by: Justin King <jcking at google.com>
 - Address review feedback
   
   Signed-off-by: Justin King <jcking at google.com>
 - Use -fno-common as suggested by ASan docs
   
   Signed-off-by: Justin King <jcking at google.com>
 - Handle chunk enlarging
   
   Signed-off-by: Justin King <jcking at google.com>
 - Remove unused include
   
   Signed-off-by: Justin King <jcking at google.com>
 - ... and 5 more: https://git.openjdk.org/jdk/compare/085e7740...5fc8412b

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/11702/files
  - new: https://git.openjdk.org/jdk/pull/11702/files/e3b9bb09..5fc8412b

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=11702&range=12
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=11702&range=11-12

  Stats: 24667 lines in 1403 files changed: 14301 ins; 3609 del; 6757 mod
  Patch: https://git.openjdk.org/jdk/pull/11702.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11702/head:pull/11702

PR: https://git.openjdk.org/jdk/pull/11702


More information about the hotspot-runtime-dev mailing list