Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8302218: CHeapBitMap::free frees with incorrect size #14079

Closed
wants to merge 1 commit into from

Conversation

quadhier
Copy link
Contributor

@quadhier quadhier commented May 22, 2023

This patch should fix JDK-8302218.

In destructor of CHeapBitMap, it invokes free() to free allocated memory:

CHeapBitMap::~CHeapBitMap() {
free(map(), size());
}

free()'s argument should be size in words, according to:

void CHeapBitMap::free(bm_word_t* map, idx_t size_in_words) const {
ArrayAllocator<bm_word_t>::free(map, size_in_words);
}

But the destructor pass the argument of size() (which returns _size). It is "size in bits" according to

private:
bm_word_t* _map; // First word in bitmap
idx_t _size; // Size of bitmap (in bits)

Instead, it should use the return value of size_in_words() to invoke free().

Once ArrayAllocatorMallocLimit option is set, munmap() may be used by free(), which does use the size argument and this may cause crash.

I have tested this patch for tier 1-3 on x86-64 linux.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8302218: CHeapBitMap::free frees with incorrect size

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14079/head:pull/14079
$ git checkout pull/14079

Update a local copy of the PR:
$ git checkout pull/14079
$ git pull https://git.openjdk.org/jdk.git pull/14079/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14079

View PR using the GUI difftool:
$ git pr show -t 14079

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14079.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 22, 2023

👋 Welcome back quadhier! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 22, 2023
@openjdk
Copy link

openjdk bot commented May 22, 2023

@quadhier The following label will be automatically applied to this pull request:

  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label May 22, 2023
@mlbridge
Copy link

mlbridge bot commented May 22, 2023

Webrevs

@quadhier
Copy link
Contributor Author

/label remove hotspot
/label add hotspot-runtime

@openjdk openjdk bot removed the hotspot hotspot-dev@openjdk.org label May 22, 2023
@openjdk
Copy link

openjdk bot commented May 22, 2023

@quadhier
The hotspot label was successfully removed.

@openjdk openjdk bot added the hotspot-runtime hotspot-runtime-dev@openjdk.org label May 22, 2023
@openjdk
Copy link

openjdk bot commented May 22, 2023

@quadhier
The hotspot-runtime label was successfully added.

Copy link
Member

@xmas92 xmas92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks good.

Wonder if there is any value in adding a test which lowers ArrayAllocatorMallocLimit to verify that this is working, and that the bug is not reintroduced.

@quadhier
Copy link
Contributor Author

Thanks for your review @xmas92.

Wonder if there is any value in adding a test which lowers ArrayAllocatorMallocLimit to verify that this is working, and that the bug is not reintroduced.

IMHO, exploiting this bug to crack VM is a little bit hard. This bug may cause crash because:

  1. size_in_bits is larger than size_in_words, which causes munmap to unmap more memory regions that what is wanted
  2. and following execution may accidentally touch the unmapped regions (this could be hard to trigger)

I think this is a bug that may cause crashes unexpectedly someday and need to be fixed.

@openjdk
Copy link

openjdk bot commented May 22, 2023

⚠️ @quadhier the full name on your profile does not match the author name in this pull requests' HEAD commit. If this pull request gets integrated then the author name from this pull requests' HEAD commit will be used for the resulting commit. If you wish to push a new commit with a different author name, then please run the following commands in a local repository of your personal fork:

$ git checkout fix-8302218
$ git commit --author='Preferred Full Name <you@example.com>' --allow-empty -m 'Update full name'
$ git push

@openjdk
Copy link

openjdk bot commented May 22, 2023

@quadhier This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8302218: CHeapBitMap::free frees with incorrect size

Reviewed-by: aboldtch, iklam, tschatzl

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 11 new commits pushed to the master branch:

  • 3f4cfbd: 8307190: Refactor ref_at methods in Constant Pool
  • 491bdea: 8308458: Windows build failure with disassembler.cpp(792): warning C4267: '=': conversion from 'size_t' to 'int'
  • b58980b: 8308034: Some CDS tests need to use @requires vm.flagless
  • 29b8d3d: 8307573: Implementation of JEP 449: Deprecate the Windows 32-bit x86 Port for Removal
  • 5fc9b57: 8308276: Change layout API to work with bytes, not bits
  • 91aeb5d: 8287834: Add SymbolLookup::or method
  • 4f88437: 8307908: [ppc] Add failing RTM tests to ProblemList until 8307907 is fixed.
  • dc30e68: 8308407: libjvm library not reproducibly comparable between vendors
  • 18e2446: 8301381: Verify DTLS 1.0 cannot be negotiated
  • b3cb82b: 8307311: Timeouts on one macOS 12.6.1 host of two Swing JTableHeader tests
  • ... and 1 more: https://git.openjdk.org/jdk/compare/05e99db466e7ef5c26f089db772a21cb2ca62e93...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@xmas92, @iklam, @tschatzl) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 22, 2023
@iklam
Copy link
Member

iklam commented May 22, 2023

@quadhier Do you actually use ArrayAllocatorMallocLimit in production? According to comments when this flag was added, it was intended for Solaris only, and the flag has remained an experimental option for the past 10 years.

I have filed https://bugs.openjdk.org/browse/JDK-8308575 for removing this flag.

@quadhier
Copy link
Contributor Author

I have filed https://bugs.openjdk.org/browse/JDK-8308575 for removing this flag.

Great, maybe I could also help with it. I don't use this flag in production myself.

@quadhier
Copy link
Contributor Author

Thank you all for your nice reviews! @iklam @xmas92 @tschatzl

@quadhier
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label May 22, 2023
@openjdk
Copy link

openjdk bot commented May 22, 2023

@quadhier
Your change (at version bb9a90b) is now ready to be sponsored by a Committer.

@quadhier
Copy link
Contributor Author

quadhier commented May 22, 2023

Hi, @iklam could you please sponsor this change? Thanks in advance!

@iklam
Copy link
Member

iklam commented May 22, 2023

I have filed https://bugs.openjdk.org/browse/JDK-8308575 for removing this flag.

Great, maybe I could also help with it. I don't use this flag in production myself.

Actually there's already a bug filed for the same issue. See https://bugs.openjdk.org/browse/JDK-8299915 and #11931

@iklam
Copy link
Member

iklam commented May 22, 2023

/sponsor

@openjdk
Copy link

openjdk bot commented May 22, 2023

Going to push as commit f99ad11.
Since your change was applied there have been 12 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 22, 2023
@openjdk openjdk bot closed this May 22, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels May 22, 2023
@openjdk
Copy link

openjdk bot commented May 22, 2023

@iklam @quadhier Pushed as commit f99ad11.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated
4 participants