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

8333354: ubsan: frame.inline.hpp:91:25: and src/hotspot/share/runtime/frame.inline.hpp:88:29: runtime error: member call on null pointer of type 'const struct SmallRegisterMap' #20296

Closed
wants to merge 4 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Jul 23, 2024

When running with ubsan - enabled binaries, some tests trigger the following report :

src/hotspot/share/runtime/frame.inline.hpp:91:25: runtime error: member call on null pointer of type 'const struct SmallRegisterMap'
#0 0x7fc1df86071e in unsigned char* frame::oopmapreg_to_location(VMRegImpl*, SmallRegisterMap const*) const src/hotspot/share/runtime/frame.inline.hpp:91
#1 0x7fc1df86071e in void OopMapDo<OopClosure, DerivedOopClosure, IncludeAllValues>::iterate_oops_do(frame const*, SmallRegisterMap const*, ImmutableOopMap const*) src/hotspot/share/compiler/oopMap.inline.hpp:106
#2 0x7fc1df8611df in void OopMapDo<OopClosure, DerivedOopClosure, IncludeAllValues>::oops_do(frame const*, SmallRegisterMap const*, ImmutableOopMap const*) src/hotspot/share/compiler/oopMap.inline.hpp:157
#3 0x7fc1df8611df in FrameOopIterator::oops_do(OopClosure*) src/hotspot/share/oops/stackChunkOop.cpp:63
#4 0x7fc1dcfc8745 in BarrierSetStackChunk::encode_gc_mode(stackChunkOopDesc*, OopIterator*) src/hotspot/share/gc/shared/barrierSetStackChunk.cpp:85
#5 0x7fc1df854080 in bool TransformStackChunkClosure::do_frame<(ChunkFrames)0, SmallRegisterMap>(StackChunkFrameStream<(ChunkFrames)0> const&, SmallRegisterMap const*) src/hotspot/share/oops/stackChunkOop.cpp:319
#6 0x7fc1df854080 in void stackChunkOopDesc::iterate_stack<(ChunkFrames)0, TransformStackChunkClosure>(TransformStackChunkClosure*) src/hotspot/share/oops/stackChunkOop.inline.hpp:233
#7 0x7fc1df82f184 in void stackChunkOopDesc::iterate_stack(TransformStackChunkClosure*) src/hotspot/share/oops/stackChunkOop.inline.hpp:199

Seems in case of (at least) class SmallRegisterMap we miss handling nullptr .


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-8333354: ubsan: frame.inline.hpp:91:25: and src/hotspot/share/runtime/frame.inline.hpp:88:29: runtime error: member call on null pointer of type 'const struct SmallRegisterMap' (Bug - P4)

Reviewers

Contributors

  • Kim Barrett <kbarrett@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20296

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 23, 2024

👋 Welcome back mbaesken! 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 Jul 23, 2024

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

8333354: ubsan: frame.inline.hpp:91:25: and src/hotspot/share/runtime/frame.inline.hpp:88:29: runtime error: member call on null pointer of type 'const struct SmallRegisterMap'

Co-authored-by: Kim Barrett <kbarrett@openjdk.org>
Reviewed-by: rrich, clanger

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

  • bc7c255: 8337416: Fix -Wzero-as-null-pointer-constant warnings in misc. runtime code
  • 7e21d4c: 8337268: Redundant Math.ceil in StyleSheet.ListPainter#drawShape
  • ab27090: 8337225: Demote maxStack and maxLocals from CodeModel to CodeAttribute
  • bd36b6a: 8337285: Examine java.text.DecimalFormat API for api/implXxx tag usage
  • a86244f: 6381729: Javadoc for generic constructor doesn't document type parameter
  • c4e6255: 8332738: Debug agent can deadlock on callbackLock when using StackFrame.PopFrames
  • c23d37e: 8337300: java/lang/Process/WaitForDuration.java leaves child process behind
  • ee365d7: 8336342: Fix known X11 library locations in sysroot
  • cd52ad8: 8337267: [REDO] G1: Refactor G1RebuildRSAndScrubTask
  • 9124a94: 8337165: Test jdk/jfr/event/gc/stacktrace/TestG1YoungAllocationPendingStackTrace.java failed: IndexOutOfBoundsException: Index 64 out of bounds for length 64
  • ... and 56 more: https://git.openjdk.org/jdk/compare/4c7b3e7fc39a06e208ea1668095d055457549d63...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 changed the title JDK-8333354: ubsan: frame.inline.hpp:91:25: and src/hotspot/share/runtime/frame.inline.hpp:88:29: runtime error: member call on null pointer of type 'const struct SmallRegisterMap' 8333354: ubsan: frame.inline.hpp:91:25: and src/hotspot/share/runtime/frame.inline.hpp:88:29: runtime error: member call on null pointer of type 'const struct SmallRegisterMap' Jul 23, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 23, 2024
@openjdk
Copy link

openjdk bot commented Jul 23, 2024

@MBaesken 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 Jul 23, 2024
@mlbridge
Copy link

mlbridge bot commented Jul 23, 2024

Webrevs

@reinrich
Copy link
Member

Hi Matthias,

I think this is intended. No instances of SmallRegisterMap are ever created.

Instead SmallRegisterMap::instance is used:

  static constexpr SmallRegisterMap* instance = nullptr;

The type is the only information that is actually used.

I guess you could fix the undefined behavior by replacing all uses of SmallRegisterMap::instance with the address of a stack allocated temporary SmallRegisterMap().

@MBaesken
Copy link
Member Author

I think this is intended. No instances of SmallRegisterMap are ever created.
Probably it is better just to switch off ubsan for the method, if it's intended.

On the other hand for SmallRegisterMap in_cont returns always false (so we could at least avoid this reg_map->in_cont() call for SmallRegisterMap)
cpu/aarch64/smallRegisterMap_aarch64.inline.hpp:80: bool in_cont() const { return false; }
cpu/arm/smallRegisterMap_arm.inline.hpp:73: bool in_cont() const { return false; }
cpu/ppc/smallRegisterMap_ppc.inline.hpp:79: bool in_cont() const { return false; }
cpu/s390/smallRegisterMap_s390.inline.hpp:73: bool in_cont() const { return false; }
cpu/x86/smallRegisterMap_x86.inline.hpp:80: bool in_cont() const { return false; }
cpu/zero/smallRegisterMap_zero.inline.hpp:73: bool in_cont() const { return false; }
cpu/riscv/smallRegisterMap_riscv.inline.hpp:80: bool in_cont() const { return false; }

@MBaesken
Copy link
Member Author

MBaesken commented Jul 24, 2024

When using the ATTRIBUTE_NO_UBSAN for frame::oopmapreg_to_location , we unfortunately run into another similar looking issue
(e.g. when running jtreg test java/net/vthread/HttpALot.java)

/jdk/src/hotspot/share/runtime/stackChunkFrameStream.inline.hpp:286:46: runtime error: member call on null pointer of type 'const struct SmallRegisterMap'
#0 0x7febd955502d in void* StackChunkFrameStream<(ChunkFrames)1>::reg_to_loc(VMRegImpl*, SmallRegisterMap const*) const src/hotspot/share/runtime/stackChunkFrameStream.inline.hpp:286
#1 0x7febd955502d in void StackChunkFrameStream<(ChunkFrames)1>::iterate_oops<BarrierClosure<(stackChunkOopDesc::BarrierType)1, true>, SmallRegisterMap>(BarrierClosure<(stackChunkOopDesc::BarrierType)1, true>, SmallRegisterMap const) const src/hotspot/share/runtime/stackChunkFrameStream.inline.hpp:373
#2 0x7febd955502d in void stackChunkOopDesc::do_barriers0<(stackChunkOopDesc::BarrierType)1, (ChunkFrames)1, SmallRegisterMap>(StackChunkFrameStream<(ChunkFrames)1> const&, SmallRegisterMap const*) src/hotspot/share/oops/stackChunkOop.cpp:375
#3 0x7febd75a2121 in void stackChunkOopDesc::do_barriers<(stackChunkOopDesc::BarrierType)1, (ChunkFrames)1, SmallRegisterMap>(StackChunkFrameStream<(ChunkFrames)1> const&, SmallRegisterMap const*) src/hotspot/share/oops/stackChunkOop.inline.hpp:193
#4 0x7febd75a2121 in ThawBase::recurse_thaw_compiled_frame(frame const&, frame&, int, bool) src/hotspot/share/runtime/continuationFreezeThaw.cpp:2246
#5 0x7febd75a1f60 in bool ThawBase::recurse_thaw_java_frameContinuationHelper::CompiledFrame(frame&, int) src/hotspot/share/runtime/continuationFreezeThaw.cpp:2092
#6 0x7febd75a1f60 in ThawBase::recurse_thaw_compiled_frame(frame const&, frame&, int, bool) src/hotspot/share/runtime/continuationFreezeThaw.cpp:2249
#7 0x7febd75a6aca in ThawBase::thaw_slow(stackChunkOopDesc*, bool) src/hotspot/share/runtime/continuationFreezeThaw.cpp:2040
#8 0x7febd75aa156 in Thaw<Config<(oop_kind)0, G1BarrierSet> >::thaw(Continuation::thaw_kind) src/hotspot/share/runtime/continuationFreezeThaw.cpp:1825
#9 0x7febd75aa156 in thaw_internal<Config<(oop_kind)0, G1BarrierSet> > src/hotspot/share/runtime/continuationFreezeThaw.cpp:2450
#10 0x7febd75aa156 in Config<(oop_kind)0, G1BarrierSet>::thaw(JavaThread*, Continuation::thaw_kind) src/hotspot/share/runtime/continuationFreezeThaw.cpp:276
#11 0x7febd75aa156 in thaw<Config<(oop_kind)0, G1BarrierSet> > src/hotspot/share/runtime/continuationFreezeThaw.cpp:253
#12 0x7febbb89c526 ()

this time it is the map->location call through a nullptr

template <ChunkFrames frame_kind>
template <typename RegisterMapT>
inline void* StackChunkFrameStream<frame_kind>::reg_to_loc(VMReg reg, const RegisterMapT* map) const {
  assert(!is_done(), "");
  return reg->is_reg() ? (void*)map->location(reg, sp()) // see frame::update_map_with_saved_link(&map, link_addr);
                       : (void*)((address)unextended_sp() + (reg->reg2stack() * VMRegImpl::stack_slot_size));
}

But SmallRegisterMap::location is for some platforms even UnImplemented so how does this work cross platform ?

@reinrich
Copy link
Member

Continuations (-XX:+VMContinuations) haven't been ported to Arm32. SmallRegisterMap depends on it.

@kimbarrett
Copy link

I think this is intended. No instances of SmallRegisterMap are ever created.

Instead SmallRegisterMap::instance is used:

  static constexpr SmallRegisterMap* instance = nullptr;

The type is the only information that is actually used.

Being intentional doesn't make it any less invalid.

@kimbarrett
Copy link

Here's an untested change that I think will fix the problem.
https://github.com/openjdk/jdk/compare/master...kimbarrett:openjdk-jdk:smallregmap?expand=1

@MBaesken
Copy link
Member Author

Here's an untested change that I think will fix the problem. https://github.com/openjdk/jdk/compare/master...kimbarrett:openjdk-jdk:smallregmap?expand=1

Seems this works well, at least :tier1 tests on some platforms (x86_64, ppc64le) look okay to me.

@MBaesken
Copy link
Member Author

MBaesken commented Jul 25, 2024

Good additional news - the jdk :tier1 tests on linux x86_64 with ubsan - enabled binaries are after this fix almost clean,
only some shenandoah related tests still fail because of
https://bugs.openjdk.org/browse/JDK-8332697
8332697: ubsan: shenandoahSimpleBitMap.inline.hpp:68:23: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long int'

--------------------------------------------------
TEST: java/foreign/stackwalk/TestAsyncStackWalk.java#shenandoah
TEST RESULT: Failed. Unexpected exit from test [exit code: 1]
--------------------------------------------------
TEST: java/foreign/stackwalk/TestStackWalk.java#shenandoah
TEST RESULT: Failed. Unexpected exit from test [exit code: 1]
--------------------------------------------------
Test results: passed: 2,420; failed: 2

@MBaesken
Copy link
Member Author

Any comments on the change ?
Kim / Richard what you think ?

Copy link
Member

@reinrich reinrich left a comment

Choose a reason for hiding this comment

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

The change looks good to me.
Thanks, Richard.

@reinrich
Copy link
Member

I think you should add Kim as contributor (see here).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 29, 2024
@MBaesken
Copy link
Member Author

/contributor add kimbarrett

@openjdk
Copy link

openjdk bot commented Jul 29, 2024

@MBaesken kimbarrett was not found in the census.

Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address.

@MBaesken
Copy link
Member Author

I think you should add Kim as contributor (see here).

Makes sense, hope we find another second reviewer (guess as contributor, Kim cannot review) .

@MBaesken
Copy link
Member Author

/contributor add kbarrett

@openjdk
Copy link

openjdk bot commented Jul 29, 2024

@MBaesken
Contributor Kim Barrett <kbarrett@openjdk.org> successfully added.

Copy link

@kimbarrett kimbarrett left a comment

Choose a reason for hiding this comment

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

It's annoying that we have all these very similar platform-specific classes of
non-trivial size. It seems like it ought to be possible to refactor to reduce the
duplication. But it might not be worth the trouble, and certainly not as part of
this change.

The additions @MBaesken has made to my prototype look good to me.

Looks good except missing some copyright updates.

I think when incorporating something like my suggested changes, the PR author
can be considered to have reviewed them. The goal is to have some number of
people look over the code and approve all the pieces (an author and 2 reviewers).
At least, that's my recollection of some prior discussions of situations like this.
But I agree it can feel a little incestuous having 2 authors who are playing a
reviewer roll for the other's work, and especially when there's some back and
forth on it.

@kimbarrett
Copy link

I think when incorporating something like my suggested changes, the PR author can be considered to have reviewed them. The goal is to have some number of people look over the code and approve all the pieces (an author and 2 reviewers). At least, that's my recollection of some prior discussions of situations like this. But I agree it can feel a little incestuous having 2 authors who are playing a reviewer roll for the other's work, and especially when there's some back and forth on it.

I did some asking around about this, and it seems my old info is stale and we should usually have reviewers who are
distinct from any of the contributors.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

LGTM

@MBaesken
Copy link
Member Author

Thanks for the reviews !

/integrate

@openjdk
Copy link

openjdk bot commented Jul 30, 2024

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

  • 0325ab8: 8335610: DiagnosticFramework: CmdLine::is_executable() correction
  • 7ac5311: 8331126: [s390x] secondary_super_cache does not scale well
  • 156f0b4: 8337213: Shenandoah: Add verification for class mirrors
  • 9e6e0a8: 8336343: Add more known sysroot library locations for ALSA
  • bc7c255: 8337416: Fix -Wzero-as-null-pointer-constant warnings in misc. runtime code
  • 7e21d4c: 8337268: Redundant Math.ceil in StyleSheet.ListPainter#drawShape
  • ab27090: 8337225: Demote maxStack and maxLocals from CodeModel to CodeAttribute
  • bd36b6a: 8337285: Examine java.text.DecimalFormat API for api/implXxx tag usage
  • a86244f: 6381729: Javadoc for generic constructor doesn't document type parameter
  • c4e6255: 8332738: Debug agent can deadlock on callbackLock when using StackFrame.PopFrames
  • ... and 60 more: https://git.openjdk.org/jdk/compare/4c7b3e7fc39a06e208ea1668095d055457549d63...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 30, 2024

@MBaesken Pushed as commit 8162832.

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

Successfully merging this pull request may close these issues.

4 participants