-
-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
JVM default library path includes system folders #103493
Comments
If you are curious for the JNR call that loads the C library: https://github.com/jnr/jnr-netdb/blob/master/src/main/java/jnr/netdb/NativeServicesDB.java#L78 LibServices lib;
if (os.equals(WINDOWS)) {
Map<LibraryOption, Object> options = new HashMap<LibraryOption, Object>();
options.put(LibraryOption.CallingConvention, CallingConvention.STDCALL);
lib = Library.loadLibrary(LibServices.class, options, "Ws2_32");
} else {
String[] libnames = os.equals(SOLARIS)
? new String[] { "socket", "nsl", "c" }
: new String[] { "c" };
if (os.equals(LINUX)) {
lib = Library.loadLibrary(LinuxLibServices.class, libnames);
} else {
lib = Library.loadLibrary(LibServices.class, libnames);
}
} |
OVERRIDE_LIBPATH is not sufficient, because it still hardcodes SYS_EXT_DIR/lib, which is somewhere in
|
@roberth I'm hoping (haven't tested) that with an empty OVERRIDE_LIBPATH the DT_RUNPATH at least will be searched for. |
@fzakaria I don't have a lot of experience with that either, but I do implement RubberDuck and I'm happy to review Nix+Java ecosystem stuff. |
Tagging @volth who seems to do a lot of JVM Java work as well. |
This patch fixes NixOS#103493 for JDK8 only. I'm upstreaming only for JDK8 to get quorum on the approach and then adding the patches to the remaining versions. Improved JDK8 patch Improved JDK8 patch
Reopening: more versions to be done |
I marked this as stale due to inactivity. → More info |
|
why does openjdk 17 not have a mr? |
@m911t Do you have a specific problem? With the example above I could not reproduce the jvm crash. |
@asbachb sorry, i thought i was hitting this bug, but turns out that the bug i hit is different |
@roberth Is there a way to reproduce this issue for openjdk17? Otherwise I'd propose to close the issue. |
Afaict, it has not been written yet.
You may not have the "right" libraries in
I don't think we need a reproducer. We know that the unpatched behavior is bad, and it is highly unlikely that upstream's behavior changes, because the rest of the world depends on it. @fzakaria did you have a specific reason not to patch OpenJDK 17? Could you patch it? |
That patch does not seem to be too complicated. I could prepare it, but I'd feel better if I had some use case to test if the patch is working. |
I mostly just forgot about it sadly.
😔
Some other stuff picked up and it kind of fell by the wayside sorry about
that.
…On Thu, Jul 28, 2022, 2:19 AM Benjamin Asbach ***@***.***> wrote:
That patch does not seem to be too complicated. I could prepare it, but
I'd feel better if I had some use case to test if the patch is working.
—
Reply to this email directly, view it on GitHub
<#103493 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAETXDWQHL3KUTADJAS2WCTVWJGDTANCNFSM4TSNVH5A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Closing since it looks like the last bit of this was fixed by #183760. Happy to reopen if I'm mistaken. |
Describe the bug
I encountered this bug when trying to use JNR that does FFI.
The particular call in general was the equivalent dlopen on the libc library and resolving to the system one which would cause a SIGSEGV.
Digging into the source some more, you discover that Java sets a default value for java.library.path if it's not explicitly set.
https://github.com/openjdk/jdk/blob/50357d136a775872999055bef61057b884d80693/src/hotspot/os/linux/os_linux.cpp#L413
Adding system libraries (i.e. /usr/lib) breaks/invalidates the hermetic invariant needed by Nix.
These library paths are also searched first before those set in the DT_RUNPATH of the ELF header as documented.
I suggest the OVERRIDE_LIBPATH is either set to empty string maybe or even the contents of the ELF RUNPATH header itself.
To Reproduce
I was using JRuby which makes it easy to reproduce by using a gem which ultimately calls the JNR FFI.
(The following reproduction results in the SIGSEGGV)
Expected behavior
Expected behavior is for the FFI call to work! This can be resolved by setting java.library.path to the correct lib.
NOTE: I could not merely set LD_LIBRARY_PATH because that would apply to everything in my nix-shell.
Furthermore, wrapping java is somewhat tedious,
JAVA_TOOL_OPTIONS
seemed pragmatic for now.Notify maintainers
@doronbehar @roberth @manveru
Metadata
Maintainer information:
All JDK derivations
The text was updated successfully, but these errors were encountered: