kohsuke / libpam4j

libpam4j
http://libpam4j.kohsuke.org/
MIT License
44 stars 47 forks source link

JVM crash during finalization #11

Closed joemeszaros closed 8 years ago

joemeszaros commented 9 years ago

I wan to use libpam4j in a production system therefore I started to play with it. I created my first program to test basic funcionality of libpam4j:

public class App 
{
    public static void main( String[] args) throws Exception
    {
        UnixUser u = new PAM("login").authenticate(args[0], args[1]);
        System.out.println("Groups : " + u.getGroups());
    }
}

After ~10 execution the program surprisingly terminated with segfault. The segfault occured in the finalizer thread of JVM after the list of groups was printed to standard output.

The error file can be found here.

Relevant section:

Stack: [0x6bfaf000,0x6c000000],  sp=0x6bffe0d0,  free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ld-linux.so.2+0x8ecf]  _dl_rtld_di_serinfo+0x3ff

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  java.lang.ClassLoader$NativeLibrary.find(Ljava/lang/String;)J+0
j  java.lang.ClassLoader.findNative(Ljava/lang/ClassLoader;Ljava/lang/String;)J+49
v  ~StubRoutines::call_stub
j  com.sun.jna.Native.free(J)V+0
j  com.sun.jna.Memory.free(J)V+1
j  com.sun.jna.Memory.dispose()V+4
j  com.sun.jna.Memory.finalize()V+1
v  ~StubRoutines::call_stub
j  java.lang.ref.Finalizer.invokeFinalizeMethod(Ljava/lang/Object;)V+0
j  java.lang.ref.Finalizer.runFinalizer()V+45
j  java.lang.ref.Finalizer.access$100(Ljava/lang/ref/Finalizer;)V+1
j  java.lang.ref.Finalizer$FinalizerThread.run()V+24
v  ~StubRoutines::call_stub

So it seems the problem occured during Memory object dispose, used in the UnixUser class.

The program was executed with maven and:

Let me know if I have bad version issue.

Unfortunately after 50 execution the program crashed again in the finalizer JVM thread. The second error file is here.

The stack is different but the context is the same (during PAM.dispose()):

j  com.sun.jna.NativeLibrary.getSymbolAddress(Ljava/lang/String;)J+24
j  com.sun.jna.Function.<init>(Lcom/sun/jna/NativeLibrary;Ljava/lang/String;ILjava/lang/String;)V+68
j  com.sun.jna.NativeLibrary.getFunction(Ljava/lang/String;ILjava/lang/String;)Lcom/sun/jna/Function;+59
j  com.sun.jna.NativeLibrary.getFunction(Ljava/lang/String;I)Lcom/sun/jna/Function;+7
j  com.sun.jna.NativeLibrary.getFunction(Ljava/lang/String;Ljava/lang/reflect/Method;)Lcom/sun/jna/Function;+109
j  com.sun.jna.Library$Handler.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;+203
j  com.sun.proxy.$Proxy16.pam_end(Lorg/jvnet/libpam/impl/PAMLibrary$pam_handle_t;I)I+23
j  org.jvnet.libpam.PAM.dispose()V+18
j  org.jvnet.libpam.PAM.finalize()V+5

Now, the test phase is aborted because it is not a stable component.

Did you encounter same issues during development?

I hope this helps : I found a JVM crash issue at JNA (https://github.com/twall/jna/issues/24)

If you need furhter details do not hesitate to write me.

twall commented 9 years ago

This should be fixed with JNA PR #378