RFR: JDK-8295865: Several issues with os::realloc [v2]
Thomas Stuefe
stuefe at openjdk.org
Wed Nov 2 14:41:50 UTC 2022
> There are several issues with os::realloc():
>
> 1) If realloc(3) fails, the original block will be left untouched. That is fine, and the caller may expect this and continue to use the old block, including handing it to os::free() later. But NMT has marked the original block as dead already, and subsequent os::free() or os::realloc() will trigger a false fatal block integrity error. Therefore, if realloc(3) fails, we need to revive the NMT header and re-account the original block before returning.
>
> 2) If handed in very large sizes, the size may overflow if the NMT header is added. The result would be that the VM reallocates to a much smaller buffer which would cause subsequent memory corruption if the caller were to use the buffer (same as JDK-8286519, but for realloc).
>
> 3) If os::realloc() enlarges a buffer, the newly added memory should be zapped with uinitBlockPad as we do for os::malloc(). Of course we only can do this if NMT is enabled, otherwise we won't know the original block size.
>
> ------------------------------
>
> The patch fixes all three issues and adds hopefully thorough enough regression gtests for them. Remember that these gtests will run, as part of the jtreg gtest runners, in all NMT modes.
>
> The largest diff hunk is inside os::realloc(). Note that I separated the two cases NMT=summary/detail and NMT=off, since it makes the coding easier to understand and we also run less code in the standard case of NMT==off.
Thomas Stuefe has updated the pull request incrementally with two additional commits since the last revision:
- add clarifying comment about ASSERT/EXPECT helpers
- if realloc(3) fails, revive the old header and re-account its size with NMT
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/10857/files
- new: https://git.openjdk.org/jdk/pull/10857/files/df5a6bc5..ad2094c7
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=10857&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=10857&range=00-01
Stats: 64 lines in 8 files changed: 60 ins; 1 del; 3 mod
Patch: https://git.openjdk.org/jdk/pull/10857.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/10857/head:pull/10857
PR: https://git.openjdk.org/jdk/pull/10857
More information about the hotspot-runtime-dev
mailing list