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

8320886: Unsafe_SetMemory0 is not guarded #16848

Closed
wants to merge 5 commits into from

Conversation

JornVernee
Copy link
Member

@JornVernee JornVernee commented Nov 28, 2023

See JBS issue.

Guard the memory access done in Unsafe_SetMemory0 to prevent a SIGBUS error from crashing the VM when a truncated memory mapped file is accessed.

Testing: local InternalErrorTest, Tier 1-5


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-8320886: Unsafe_SetMemory0 is not guarded (Bug - P2)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16848

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 28, 2023

👋 Welcome back jvernee! 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.

@franz1981
Copy link

@JornVernee please check what I have done for #16760

Maybe there is something we can pull in already on your PR here re it

@openjdk
Copy link

openjdk bot commented Nov 28, 2023

@JornVernee 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 Nov 28, 2023
@JornVernee
Copy link
Member Author

@franz1981 I can not interact with PRs that have the OCA label. Once you have signed the OCA, and it is verified (label is removed), I can take a look.

@franz1981
Copy link

franz1981 commented Nov 28, 2023

@JornVernee Fair point, in theory I work for Red Hair so it should be sorted out, let me ask @theRealAph about it

First contribution ever, so forgive the naive comment

@JornVernee
Copy link
Member Author

JornVernee commented Nov 28, 2023

@franz1981 No problem. I wasn't sure whether you worked for Red Hat or not. In that case, it should be enough to post a comment with /covered and then one of the community managers will create an entry for your github user name in the OCA database: https://oca.opensource.oracle.com/?ojr=contrib-list

I will stick to the policy of waiting until the OCA label is removed though :)

@theRealAph
Copy link
Contributor

@franz1981 I can not interact with PRs that have the OCA label. Once you have signed the OCA, and it is verified (label is removed), I can take a look.

I can tell you that @franz1981 is a Red Hat employee, and we have signed the OCA for everyone here.

@JornVernee JornVernee marked this pull request as ready for review November 28, 2023 18:55
@JornVernee
Copy link
Member Author

#16760 Looks more performance focused, so I think that should be addressed separately.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 28, 2023
@JornVernee
Copy link
Member Author

JornVernee commented Nov 28, 2023

I'm looking into the crash on mac

P.S. the issue seems to be some missing cases in Assembler::locate_operand, meaning the signal handler can not find the address of the next instruction. I think we can just add the missing cases.

@mlbridge
Copy link

mlbridge bot commented Nov 28, 2023

Webrevs

@dholmes-ora
Copy link
Member

@JornVernee is there some "new" usage of this method such that it needs guarding? I find it interesting that in the 3+ months that the fix for JDK-8191278 was developed and reviewed, the need to include SetMemory0 was never raised once. And that was over 4 years ago.

@JornVernee
Copy link
Member Author

@JornVernee is there some "new" usage of this method such that it needs guarding?

This function is now exposed (indirectly) through the new MemorySegment::fill API. There are some rare other uses of Unsafe.setMemory in the JDK, and some seem to be operating on user-supplied buffers, so this issue might have existed for longer already. For instance in GaloisCounterMode, but it's hard to tell for me where the ByteBuffer that this is operating on comes from.

I went through the original review thread starting here: https://mail.openjdk.org/pipermail/hotspot-dev/2019-February/037058.html but I don't see a reference to setMemory.

@@ -969,7 +970,7 @@ address Assembler::locate_operand(address inst, WhichOperand which) {
assert(which == call32_operand, "jcc has no disp32 or imm");
return ip;
default:
ShouldNotReachHere();
fatal("not handled: 0x0F%2X", 0xFF & *(ip-1));
Copy link
Member Author

Choose a reason for hiding this comment

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

I've improved the error reporting a bit here to print out the problematic instruction. I was only able to reproduce the crash through GHA.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Okay fix seems fine.

Thanks

@openjdk
Copy link

openjdk bot commented Dec 4, 2023

@JornVernee 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:

8320886: Unsafe_SetMemory0 is not guarded

Reviewed-by: dholmes, fparain

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 214 new commits pushed to the master branch:

  • b270f30: 8318629: G1: Refine code a bit in G1RemSetTrackingPolicy::update_at_allocate
  • 486594d: 8316657: Support whitebox testing in microbenchmarks
  • ce8399f: 8321582: yield .class not parsed correctly.
  • 3c6459e: 8321641: ClassFile ModuleAttribute.ModuleAttributeBuilder::moduleVersion spec contains a copy-paste error
  • 92fd490: 8321176: [Screencast] make a second attempt on screencast failure
  • d13302f: 8321387: SegmentAllocator:allocateFrom(AddressLayout, MemorySegment) does not throw stated UnsupportedOperationException
  • ce10844: 8319577: x86_64 AVX2 intrinsics for Arrays.sort methods (int, float arrays)
  • 5c12a18: 8320790: Update --release 22 symbol information for JDK 22 build 27
  • 7180088: 8321429: (fc) FileChannel.lock creates a FileKey containing two long index values, they could be stored as int values
  • 0c178be: 8321206: Make Locale related system properties StaticProperty
  • ... and 204 more: https://git.openjdk.org/jdk/compare/4bcda602668835c35e2ac6ff6702d15cd249bc2a...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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 4, 2023
@JornVernee
Copy link
Member Author

/label add hotspot-runtime

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

openjdk bot commented Dec 11, 2023

@JornVernee
The hotspot-runtime label was successfully added.

@JornVernee
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 11, 2023

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

  • b270f30: 8318629: G1: Refine code a bit in G1RemSetTrackingPolicy::update_at_allocate
  • 486594d: 8316657: Support whitebox testing in microbenchmarks
  • ce8399f: 8321582: yield .class not parsed correctly.
  • 3c6459e: 8321641: ClassFile ModuleAttribute.ModuleAttributeBuilder::moduleVersion spec contains a copy-paste error
  • 92fd490: 8321176: [Screencast] make a second attempt on screencast failure
  • d13302f: 8321387: SegmentAllocator:allocateFrom(AddressLayout, MemorySegment) does not throw stated UnsupportedOperationException
  • ce10844: 8319577: x86_64 AVX2 intrinsics for Arrays.sort methods (int, float arrays)
  • 5c12a18: 8320790: Update --release 22 symbol information for JDK 22 build 27
  • 7180088: 8321429: (fc) FileChannel.lock creates a FileKey containing two long index values, they could be stored as int values
  • 0c178be: 8321206: Make Locale related system properties StaticProperty
  • ... and 204 more: https://git.openjdk.org/jdk/compare/4bcda602668835c35e2ac6ff6702d15cd249bc2a...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 11, 2023

@JornVernee Pushed as commit ce4b257.

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

@JornVernee JornVernee deleted the GuardSetMemory branch December 11, 2023 19:14
@JornVernee
Copy link
Member Author

/backport jdk22

@openjdk
Copy link

openjdk bot commented Dec 11, 2023

@JornVernee the backport was successfully created on the branch backport-JornVernee-ce4b257f in my personal fork of openjdk/jdk22. To create a pull request with this backport targeting openjdk/jdk22:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit ce4b257f from the openjdk/jdk repository.

The commit being backported was authored by Jorn Vernee on 11 Dec 2023 and was reviewed by David Holmes and Frederic Parain.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22:

$ git fetch https://github.com/openjdk-bots/jdk22.git backport-JornVernee-ce4b257f:backport-JornVernee-ce4b257f
$ git checkout backport-JornVernee-ce4b257f
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22.git backport-JornVernee-ce4b257f

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

Successfully merging this pull request may close these issues.

5 participants