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

8267130: Memory Overflow in Disassembler::load_library #4020

Closed

Conversation

Wanghuang-Huawei
Copy link

@Wanghuang-Huawei Wanghuang-Huawei commented May 14, 2021

  • reproduce:
    put your libjvm.so in a long enough path, such like
/home/aaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/jdk/lib/server/libjvm.so
  • reason: we strcpy hsdis_library_name into buf without checking the length.
    if (jvm_offset >= 0) {
     // 1. <home>/lib/<vm>/libhsdis-<arch>.so
     strcpy(&buf[jvm_offset], hsdis_library_name);
     strcat(&buf[jvm_offset], os::dll_file_extension());
     if (Verbose) st->print_cr("Trying to load: %s", buf);
     _library = os::dll_load(buf, ebuf, sizeof ebuf);
     if (_library == NULL && lib_offset >= 0) {
       // 2. <home>/lib/<vm>/hsdis-<arch>.so
       strcpy(&buf[lib_offset], hsdis_library_name);
       strcat(&buf[lib_offset], os::dll_file_extension());
       if (Verbose) st->print_cr("Trying to load: %s", buf);
       _library = os::dll_load(buf, ebuf, sizeof ebuf);
     }
     if (_library == NULL && lib_offset > 0) {
       // 3. <home>/lib/hsdis-<arch>.so
       buf[lib_offset - 1] = '\0';
       const char* p = strrchr(buf, *os::file_separator());
       if (p != NULL) {
         lib_offset = p - buf + 1;
         strcpy(&buf[lib_offset], hsdis_library_name);
         strcat(&buf[lib_offset], os::dll_file_extension());
         if (Verbose) st->print_cr("Trying to load: %s", buf);
         _library = os::dll_load(buf, ebuf, sizeof ebuf);
       }
     }
    }

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8267130: Memory Overflow in Disassembler::load_library

Reviewers

Contributors

  • Wang Huang <whuang@openjdk.org>
  • Miao Zhuojun <mouzhuojun@huawei.com>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4020/head:pull/4020
$ git checkout pull/4020

Update a local copy of the PR:
$ git checkout pull/4020
$ git pull https://git.openjdk.java.net/jdk pull/4020/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4020

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4020.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 14, 2021

👋 Welcome back whuang! 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 14, 2021
@openjdk
Copy link

openjdk bot commented May 14, 2021

@Wanghuang-Huawei The following label will be automatically applied to this pull request:

  • hotspot-compiler

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-compiler hotspot-compiler-dev@openjdk.org label May 14, 2021
@mlbridge
Copy link

mlbridge bot commented May 14, 2021

Webrevs

@Wanghuang-Huawei
Copy link
Author

/contributor add Wang Huang whuang@openjdk.org
/contributor add Miao Zhuojunmouzhuojun@huawei.com

@openjdk
Copy link

openjdk bot commented May 14, 2021

@Wanghuang-Huawei
Contributor Wang Huang <whuang@openjdk.org> successfully added.

@openjdk
Copy link

openjdk bot commented May 14, 2021

@Wanghuang-Huawei
Contributor Miao Zhuojun <mouzhuojun@huawei.com> successfully added.

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Hi @Wanghuang-Huawei ,

Long term this coding may benefit by using stringStream, which takes care of truncating (or dynamically allocating) memory as well as string appending.

But for this fix, I think this is mostly fine. See inline remarks.

Cheers, Thomas

// 2. <home>/lib/<vm>/hsdis-<arch>.so
strcpy(&buf[lib_offset], hsdis_library_name);
strcat(&buf[lib_offset], os::dll_file_extension());
if (jvm_offset + strlen(hsdis_library_name) + strlen(os::dll_file_extension()) < JVM_MAXPATHLEN) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need space for the terminating zero here?

Copy link
Author

Choose a reason for hiding this comment

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

We use < here. If we use <=, we should consider terminating zero ;-)

Copy link

@neliasso neliasso left a comment

Choose a reason for hiding this comment

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

Just noting (not requiring you to fix in this CR). The error printing should be converted to use unified logging.

Approved.

@openjdk
Copy link

openjdk bot commented May 18, 2021

@Wanghuang-Huawei 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:

8267130: Memory Overflow in Disassembler::load_library

Co-authored-by: Wang Huang <whuang@openjdk.org>
Co-authored-by: Miao  Zhuojun <mouzhuojun@huawei.com>
Reviewed-by: neliasso, mli

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

  • 9d305b9: 8252372: Check if cloning is required to move loads out of loops in PhaseIdealLoop::split_if_with_blocks_post()
  • 0394416: 8267468: Rename refill waster counters in ThreadLocalAllocBuffer
  • b33b8bc: 8267750: Incomplete fix for JDK-8267683
  • ac36b7d: 8267452: Delegate forEachRemaining in Spliterators.iterator()
  • d0d2ddc: 8267651: runtime/handshake/HandshakeTimeoutTest.java times out when dumping core
  • a98e476: 8267311: vmTestbase/gc/gctests/StringInternGC/StringInternGC.java eventually OOMEs
  • 5aa45f2: 8267403: tools/jpackage/share/FileAssociationsTest.java#id0 failed with "Error: Bundler "Mac PKG Package" (pkg) failed to produce a package"
  • c20ca42: 8267691: Change table to obsolete CriticalJNINatives in JDK 18, not 17
  • e751b7b: 8267683: rfc7301Grease8F value not displayed correctly in SSLParameters javadoc
  • 0b77359: 8224243: Add implSpec's to AccessibleObject and seal Executable
  • ... and 233 more: https://git.openjdk.java.net/jdk/compare/04fad70437a43c0f38fd53414b8eace2eac93509...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 (@tstuefe, @neliasso, @Hamlin-Li) 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 18, 2021
@Wanghuang-Huawei
Copy link
Author

/integrate

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

openjdk bot commented May 26, 2021

@Wanghuang-Huawei
Your change (at version 2abd0b0) is now ready to be sponsored by a Committer.

@Hamlin-Li
Copy link

/approve

@openjdk
Copy link

openjdk bot commented May 26, 2021

@Hamlin-Li Unknown command approve - for a list of valid commands use /help.

Copy link

@Hamlin-Li Hamlin-Li 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.
/sponser

@Hamlin-Li
Copy link

/sponsor

@openjdk openjdk bot closed this May 26, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 26, 2021
@openjdk
Copy link

openjdk bot commented May 26, 2021

@Hamlin-Li @Wanghuang-Huawei Since your change was applied there have been 243 commits pushed to the master branch:

  • 9d305b9: 8252372: Check if cloning is required to move loads out of loops in PhaseIdealLoop::split_if_with_blocks_post()
  • 0394416: 8267468: Rename refill waster counters in ThreadLocalAllocBuffer
  • b33b8bc: 8267750: Incomplete fix for JDK-8267683
  • ac36b7d: 8267452: Delegate forEachRemaining in Spliterators.iterator()
  • d0d2ddc: 8267651: runtime/handshake/HandshakeTimeoutTest.java times out when dumping core
  • a98e476: 8267311: vmTestbase/gc/gctests/StringInternGC/StringInternGC.java eventually OOMEs
  • 5aa45f2: 8267403: tools/jpackage/share/FileAssociationsTest.java#id0 failed with "Error: Bundler "Mac PKG Package" (pkg) failed to produce a package"
  • c20ca42: 8267691: Change table to obsolete CriticalJNINatives in JDK 18, not 17
  • e751b7b: 8267683: rfc7301Grease8F value not displayed correctly in SSLParameters javadoc
  • 0b77359: 8224243: Add implSpec's to AccessibleObject and seal Executable
  • ... and 233 more: https://git.openjdk.java.net/jdk/compare/04fad70437a43c0f38fd53414b8eace2eac93509...master

Your commit was automatically rebased without conflicts.

Pushed as commit 083416d.

💡 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-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants