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

8308748: JNU_GetStringPlatformChars may write to String's internal memory array #14117

Closed
wants to merge 1 commit into from

Conversation

rudihorn
Copy link
Contributor

@rudihorn rudihorn commented May 24, 2023

This change prevents the contents of the internal string array from being copied back when releasing it.


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-8308748: JNU_GetStringPlatformChars may write to String's internal memory array

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14117

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper bridgekeeper bot added the oca Needs verification of OCA signatory status label May 24, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented May 24, 2023

Hi @rudihorn, welcome to this OpenJDK project and thanks for contributing!

We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing /signed in a comment in this pull request.

If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user rudihorn" as summary for the issue.

If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing /covered in a comment in this pull request.

@openjdk
Copy link

openjdk bot commented May 24, 2023

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

  • core-libs

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 core-libs core-libs-dev@openjdk.org label May 24, 2023
@rudihorn rudihorn changed the title 8308748: Use JNI_ABORT to release string bytes 8308748: JNU_GetStringPlatformChars may write to String's internal memory array May 24, 2023
@rudihorn
Copy link
Contributor Author

/covered

@bridgekeeper bridgekeeper bot added the oca-verify Needs verification of OCA signatory status label May 24, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented May 24, 2023

Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated!

@bridgekeeper bridgekeeper bot removed oca Needs verification of OCA signatory status oca-verify Needs verification of OCA signatory status labels May 26, 2023
@openjdk openjdk bot added the rfr Pull request is ready for review label May 26, 2023
@mlbridge
Copy link

mlbridge bot commented May 26, 2023

Webrevs

@Michael-Mc-Mahon
Copy link
Member

There was an unrelated change to these functions recently. You might want to rebase this PR with the latest version.

@rudihorn
Copy link
Contributor Author

There was an unrelated change to these functions recently. You might want to rebase this PR with the latest version.

Done

@openjdk
Copy link

openjdk bot commented May 26, 2023

@rudihorn Please do not rebase or force-push to an active PR as it invalidates existing review comments. Note for future reference, the bots always squash all changes into a single commit automatically as part of the integration. See OpenJDK Developers’ Guide for more information.

@AlanBateman
Copy link
Contributor

This looks okay. Have you checked the other usages of ReleasePrimitiveArrayCritical (e.g. libzip) see if they need the copy back when releasing?

@dholmes-ora
Copy link
Member

This looks okay. Have you checked the other usages of ReleasePrimitiveArrayCritical (e.g. libzip) see if they need the copy back when releasing?

I can immediately see code in Java_java_util_zip_Inflater_inflateBytesBytes that needs the same fix in relation to the input array. Even if there is no issue with read-only memory when writing back an unchanged array, we should avoid unnecessary copying.

That said I'm not sure it is up to this issue/PR to take responsibility for policing all uses of ReleasePrimitiveArrayCritical in the JDK libraries.

@rudihorn
Copy link
Contributor Author

rudihorn commented May 31, 2023

I have not checked other uses, but they are probably not as critical yet given the special status and frequent use of strings. I can possibly revisit this issue in the future in a further issue / PR if I find time at some stage.

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.

This change looks good to me.

Please await a core-libs review before integration though.

Thanks.

@openjdk
Copy link

openjdk bot commented May 31, 2023

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

8308748: JNU_GetStringPlatformChars may write to String's internal memory array

Reviewed-by: dholmes, rriggs, alanb

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

  • 01455a0: 8304878: ConcurrentModificationException in javadoc tool
  • 7d25bf7: 8309419: RISC-V: Relax register constraint for AddReductionVF & AddReductionVD nodes
  • 5146a58: 8309418: RISC-V: Make use of vl1r.v & vfabs.v pseudo-instructions where appropriate
  • 41bf2ad: 8308875: java/awt/Toolkit/GetScreenInsetsCustomGC/GetScreenInsetsCustomGC.java failed with 'Cannot invoke "sun.awt.X11GraphicsDevice.getInsets()" because "device" is null'
  • a7a0913: 8309346: Extend hs_err logging for all VM operations deriving from VM_GC_Operation
  • 3b85f84: 8309340: Provide sctpHandleSocketErrorWithMessage
  • 2e9eff5: 8309406: Change jdk.trackAllThreads to default to true
  • 6d155a4: 8308167: SequencedMap::firstEntry throws NPE when first entry has null key or value
  • 4b15349: 8304438: jcmd JVMTI.agent_load should obey EnableDynamicAgentLoading
  • b3c9d67: 8309136: [JVMCI] add -XX:+UseGraalJIT flag
  • ... and 120 more: https://git.openjdk.org/jdk/compare/a92363461dbe67d8736a6b0c3cbe1c3ad7aa28ae...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 (@dholmes-ora, @RogerRiggs, @AlanBateman) 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 31, 2023
Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

Looks good for core-libs.

@AlanBateman
Copy link
Contributor

I have not checked other uses, but they are probably not as critical yet given the special status and frequent use of strings. I can possibly revisit this issue in the future in a further issue / PR if I find time at some stage.

Okay, we should create an issue in JBS to follow-up on that, as there may be other opportunities to avoid the copy back.

@rudihorn
Copy link
Contributor Author

rudihorn commented Jun 6, 2023

/integrate

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

openjdk bot commented Jun 6, 2023

@rudihorn
Your change (at version 6bfd6a4) is now ready to be sponsored by a Committer.

@AlanBateman
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Jun 6, 2023

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

  • 01455a0: 8304878: ConcurrentModificationException in javadoc tool
  • 7d25bf7: 8309419: RISC-V: Relax register constraint for AddReductionVF & AddReductionVD nodes
  • 5146a58: 8309418: RISC-V: Make use of vl1r.v & vfabs.v pseudo-instructions where appropriate
  • 41bf2ad: 8308875: java/awt/Toolkit/GetScreenInsetsCustomGC/GetScreenInsetsCustomGC.java failed with 'Cannot invoke "sun.awt.X11GraphicsDevice.getInsets()" because "device" is null'
  • a7a0913: 8309346: Extend hs_err logging for all VM operations deriving from VM_GC_Operation
  • 3b85f84: 8309340: Provide sctpHandleSocketErrorWithMessage
  • 2e9eff5: 8309406: Change jdk.trackAllThreads to default to true
  • 6d155a4: 8308167: SequencedMap::firstEntry throws NPE when first entry has null key or value
  • 4b15349: 8304438: jcmd JVMTI.agent_load should obey EnableDynamicAgentLoading
  • b3c9d67: 8309136: [JVMCI] add -XX:+UseGraalJIT flag
  • ... and 120 more: https://git.openjdk.org/jdk/compare/a92363461dbe67d8736a6b0c3cbe1c3ad7aa28ae...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 6, 2023
@openjdk openjdk bot closed this Jun 6, 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 Jun 6, 2023
@openjdk
Copy link

openjdk bot commented Jun 6, 2023

@AlanBateman @rudihorn Pushed as commit 8f0839b.

💡 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
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
5 participants