Skip to content

JVM crash: org.lwjgl.system.MemoryUtil reaches after the end of the object #491

@shipilev

Description

@shipilev

Happens in current Git tip with fastdebug OpenJDK binaries. I use my own builds below, but this can be reproduced with self-built OpenJDK binaries too.

$ curl https://builds.shipilev.net/openjdk-jdk/openjdk-jdk-latest-linux-x86_64-fastdebug.tar.xz | tar xJf -
$ export JAVA_HOME=`pwd`/jdk
$ export PATH=$JAVA_HOME/bin:$PATH
$ java -version
openjdk version "14-testing" 2020-03-17
OpenJDK Runtime Environment (fastdebug build 14-testing+0-builds.shipilev.net-openjdk-jdk-b959-20190807-jdk-1332)
OpenJDK 64-Bit Server VM (fastdebug build 14-testing+0-builds.shipilev.net-openjdk-jdk-b959-20190807-jdk-1332, mixed mode, sharing)
$ ant

...
tests:
    [Tests] [LWJGL] Version: 3.2.3 SNAPSHOT
    [Tests] [LWJGL] 	 OS: Linux v4.15.0-52-generic
    [Tests] [LWJGL] 	JRE: 14-testing amd64
    [Tests] [LWJGL] 	JVM: OpenJDK 64-Bit Server VM v14-testing+0-builds.shipilev.net-openjdk-jdk-b959-20190807-jdk-1332 by Aleksey Shipilev
    [Tests] # To suppress the following error report, specify this argument
    [Tests] # after -XX: or in .hotspotrc:  SuppressErrorAt=/unsafe.cpp:119
    [Tests] #
    [Tests] # A fatal error has been detected by the Java Runtime Environment:
    [Tests] #
    [Tests] #  Internal Error (/home/buildbot/worker/jdkX-linux/build/src/hotspot/share/prims/unsafe.cpp:119), pid=9818, tid=9821
    [Tests] #  assert(byte_offset < p_size) failed: Unsafe access: offset 56 > object's size 56
    [Tests] #
    [Tests] # JRE version: OpenJDK Runtime Environment (14.0) (fastdebug build 14-testing+0-builds.shipilev.net-openjdk-jdk-b959-20190807-jdk-1332)
    [Tests] # Java VM: OpenJDK 64-Bit Server VM (fastdebug 14-testing+0-builds.shipilev.net-openjdk-jdk-b959-20190807-jdk-1332, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64)
    [Tests] # Problematic frame:
    [Tests] # V  [libjvm.so+0x18482d4]  assert_field_offset_sane(oop, long)+0xe4

The top of the stack is:

Stack: [0x00007fa8c3a22000,0x00007fa8c3a63000],  sp=0x00007fa8c3a5ed60,  free space=243k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x18482d4]  assert_field_offset_sane(oop, long)+0xe4
V  [libjvm.so+0x1852483]  Unsafe_GetInt+0xf3
J 552  jdk.internal.misc.Unsafe.getInt(Ljava/lang/Object;J)I java.base@14-testing (0 bytes) @ 0x00007fa8ab700b18 [0x00007fa8ab7009c0+0x0000000000000158]
j  sun.misc.Unsafe.getInt(Ljava/lang/Object;J)I+5 jdk.unsupported@14-testing
j  org.lwjgl.system.MemoryUtil.getParentOffset(ILjava/nio/Buffer;Ljava/util/function/Function;)J+50
j  org.lwjgl.system.MemoryUtil.<clinit>()V+220
v  ~StubRoutines::call_stub

So I think org.lwjgl.system.MemoryUtil.getParentOffset reaches to something after the end of the object. This is incorrect and caught by JVM assert. It could have crashed the JVM without the assert, especially in release builds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions