Skip to content

Conversation

@bsdkurt
Copy link
Contributor

@bsdkurt bsdkurt commented Nov 14, 2025

…rGenerator::generate_native_entry

I believe there's a incorrect pointer deference in TemplateInterpreterGenerator::generate_native_entry() in this part of the code:

// get native function entry point in r10
  {
    Label L;
    __ ldr(r10, Address(rmethod, Method::native_function_offset()));
    ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
    __ lea(rscratch2, unsatisfied);
    __ ldr(rscratch2, rscratch2);
    __ cmp(r10, rscratch2);
    __ br(Assembler::NE, L);
    __ call_VM(noreg,
               CAST_FROM_FN_PTR(address,
                                InterpreterRuntime::prepare_native_call),
               rmethod);
    __ get_method(rmethod);
    __ ldr(r10, Address(rmethod, Method::native_function_offset()));
    __ bind(L);
  }

If I understand this correctly, the entry point for unsatisfied link error is loaded into rscratch2. The next instruction, ldr(rscratch2, rscratch2), dereferences that pointer and reads from the text segment the initial instructions at the entry point into rscratch2. It then compares the native method entry point in r10 with the initial instructions loaded into rscratch2 which will never match. I believe the intent here was to compare the native method entry point with the unsatisfied link error entry point and the ldr(rscratch2, rscratch2) instruction should be removed.

This was found on OpenBSD/aarch64. OpenBSD has a security feature where the text segments are marked execute only and do not allow reads independent of execution. the ldr(rscratch2, rscratch2) instruction causes a segfault because it is reading the text segment. While this bug was found on OpenBSD I believe it applies to all OS on aaarch64.

This change removes the errant aarch64 hotspot assembly instruction that was reading from libjvm.so .text segment.

Updated comment with markdown for code.


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-8371918: aarch64: Incorrect pointer dereference in TemplateInterpreterGenerator::generate_native_entry (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28327

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

Using diff file

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

Using Webrev

Link to Webrev Comment

…rGenerator::generate_native_entry

Remove errant aarch64 hotspot assembly instruction that was reading
from libjvm.so .text segment.
@bridgekeeper
Copy link

bridgekeeper bot commented Nov 14, 2025

👋 Welcome back kurt! 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
Copy link

openjdk bot commented Nov 14, 2025

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

8371918: aarch64: Incorrect pointer dereference in TemplateInterpreterGenerator::generate_native_entry

Reviewed-by: aph, shade

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

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 (@theRealAph, @shipilev) 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 changed the title 8371918: aarch64: Incorrect pointer dereference in TemplateInterprete… 8371918: aarch64: Incorrect pointer dereference in TemplateInterpreterGenerator::generate_native_entry Nov 14, 2025
@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Nov 14, 2025
@openjdk
Copy link

openjdk bot commented Nov 14, 2025

@bsdkurt 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 rfr Pull request is ready for review label Nov 14, 2025
@bsdkurt
Copy link
Contributor Author

bsdkurt commented Nov 14, 2025

Here is a gdb session on OpenBSD/aarch64 without this patch showing the SEGFAULT where the ldr(rscratch2, rscratch2) instruction is attempting to load the initial instructions (paciasp) for throw_unsatisfied_link_error into x9:

Core was generated by `javac'.
Program terminated with signal SIGABRT, Aborted.
#0  thrkill () at /tmp/-:3

warning: 3	/tmp/-: No such file or directory
[Current thread is 1 (process 121574)]
(gdb) bt
#0  thrkill () at /tmp/-:3
#1  0x000000190c19873c in _libc_abort () at /usr/src/lib/libc/stdlib/abort.c:51
#2  0x00000019249f1470 [PAC] in os::abort (dump_core=true, siginfo=<optimized out>, context=<optimized out>) at /home/truk/jdk/jdk/src/hotspot/os/posix/os_posix.cpp:2226
#3  0x0000001924f43660 [PAC] in VMError::report_and_die (id=id@entry=11, message=<optimized out>, message@entry=0x1911d160d0 "", detail_fmt=<optimized out>, detail_args=..., 
    thread=<optimized out>, pc=0x19c269d9b8 ")\001@\371_\001\t\353A\004", siginfo=0x1911d16648, context=0x1911d16528, filename=0x0, lineno=0, size=0)
    at /home/truk/jdk/jdk/src/hotspot/share/utilities/vmError.cpp:1992
#4  0x0000001924f42df0 [PAC] in VMError::report_and_die (thread=0x1931a44800, sig=0, sig@entry=11, pc=0x0, siginfo=0x65, context=0x31, detail_fmt=0x0)
    at /home/truk/jdk/jdk/src/hotspot/share/utilities/vmError.cpp:1631
#5  0x0000001924f43d50 [PAC] in VMError::report_and_die (thread=<optimized out>, sig=11, pc=<optimized out>, siginfo=<optimized out>, context=<optimized out>)
    at /home/truk/jdk/jdk/src/hotspot/share/utilities/vmError.cpp:1651
#6  0x0000001924d0e098 [PAC] in JVM_handle_bsd_signal (sig=11, info=0x1911d16648, ucVoid=0x1911d16528, abort_if_unrecognized=1)
    at /home/truk/jdk/jdk/src/hotspot/os/posix/signals_posix.cpp:652
#7  <signal handler called>
#8  0x00000019c269d9b8 in ?? ()
#9  0x00000019c269ae70 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
(gdb) frame 8
#8  0x00000019c269d9b8 in ?? ()
(gdb) x/i $pc
=> 0x19c269d9b8:	ldr	x9, [x9]
(gdb) x/i $x9
   0x1924b3fc08 <throw_unsatisfied_link_error(JNIEnv*, ...)>:	paciasp
(gdb) x/x $x9
0x1924b3fc08 <throw_unsatisfied_link_error(JNIEnv*, ...)>:	0xd503233f
(gdb) x/i $x10
   0x192aaad88c <Java_java_lang_System_registerNatives>:	bti	c

@mlbridge
Copy link

mlbridge bot commented Nov 14, 2025

Webrevs

@dean-long
Copy link
Member

It looks like RISCV is broken in the same way.

@dean-long
Copy link
Member

According to InterpreterRuntime::prepare_native_call(), if there is a signal handler, which is checked first, then there should be a native function. So I wonder if we can remove the check for the native function from all CPU ports.

Copy link
Contributor

@theRealAph theRealAph left a comment

Choose a reason for hiding this comment

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

Ah yes, I see.

The mistake was mine: I thought __ cmpptr(rax, unsatisfied.addr(), rscratch1) meant
__ cmpptr(rax, unsatisfied, rscratch1). In other words, I missed the significance of .addr().

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 16, 2025
@RealFYang
Copy link
Member

It looks like RISCV is broken in the same way.

Fired new JBS for RISC-V: https://bugs.openjdk.org/browse/JDK-8371966

@bsdkurt
Copy link
Contributor Author

bsdkurt commented Nov 17, 2025

@theRealAph Thank you for the review.

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Nov 17, 2025
@openjdk
Copy link

openjdk bot commented Nov 17, 2025

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

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

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

Looks reasonable.

@shipilev
Copy link
Member

I did also wonder how it is not breaking now with uninitialized native entries. But I see we are doing this init as part of signature handler resolution:

// get signature handler
{
Label L;
__ ldr(t, Address(rmethod, Method::signature_handler_offset()));
__ cbnz(t, L);
__ call_VM(noreg,
CAST_FROM_FN_PTR(address,
InterpreterRuntime::prepare_native_call),
rmethod);
__ ldr(t, Address(rmethod, Method::signature_handler_offset()));
__ bind(L);
}
-- before we hit this block. So, as @dean-long says, maybe we do not need this native method entry check at all. But this fix is fine to unbreak BSD/AArch64 alone.

@shipilev
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Nov 19, 2025

Going to push as commit ae4d9c2.
Since your change was applied there have been 70 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 Nov 19, 2025
@openjdk openjdk bot closed this Nov 19, 2025
@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 Nov 19, 2025
@openjdk
Copy link

openjdk bot commented Nov 19, 2025

@shipilev @bsdkurt Pushed as commit ae4d9c2.

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

@bsdkurt
Copy link
Contributor Author

bsdkurt commented Nov 19, 2025

@shipilev Thank you for the review and sponsor. I was wondering why this issue had not been discovered previously. It does appear that the check against unsatisfied link may be unnecessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants