-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
JNA trying to read files in /proc - but I'm on macOS, not Linux #825
Comments
/proc/self/exe and the target of that symlink are analyzed to determine the platform on which JNA is run. This was introduced to support running JNA on linux arm-hardfloat and arm-softfloat (mapped to armel). The only way to reliably determine the correct platform is to analyze the java binary, that is running the application. Please check if you can relax the security manager restrictions. The security manager only works on the java level. If the code gets access the the JNA library and is able to load a interface for the C library, the files will be accessible via the C functions. As a potential fix I see the option to modify: --- a/src/com/sun/jna/Platform.java
+++ b/src/com/sun/jna/Platform.java
@@ -260,7 +260,10 @@
return ahfd.isArmSoftFloat();
} catch (IOException ex) {
// asume hardfloat
- Logger.getLogger(Platform.class.getName()).log(Level.FINE, null, ex);
+ Logger.getLogger(Platform.class.getName()).log(Level.FINE, "Failed to read '/proc/self/exe' or the target binary.", ex);
+ } catch (SecurityException ex) {
+ // asume hardfloat
+ Logger.getLogger(Platform.class.getName()).log(Level.FINE, "SecurityException while analysing '/proc/self/exe' or the target binary.", ex);
}
return false;
} |
That would work. The check could alternatively be delayed until you know you're running on ARM Linux, since the value it computes is only used in that situation. |
@trejkaz did you evaluate just relaxing the security manager rules? As said: The moment a call into JNA is possible, you can safely say all bets are off. |
I'm not sure we want to relax the rule for reading from /proc. It's a portability issue more than anything, and none of the platforms we run on is ARM so the reason JNA has to do the check is irrelevant to our application. If it could delay the check until after it knows that it's ARM Linux... Just catching the exception would be fine by me too, though. (I have wondered about the security risks of having JNA on the classpath too, actually... It would probably be fine if all the methods properly checked with the SecurityManager before running, but currently they don't. Our own code generally does before calling it, but an attacker obviously bother.) |
The ELFAnalyser analyses the java binary to determine, whether the hardfloat/softfloat flags are set. This causes issues if a security manager is in place and limits file accessibility. The JNA code base needs read access on the /proc/self/exe symlink and the referenced binary. This change reduces the cases where the executing binary is read. On platforms, that don't need it, the detection step is skipped. Close: java-native-access#825
The ELFAnalyser analyses the java binary to determine, whether the hardfloat/softfloat flags are set. This causes issues if a security manager is in place and limits file accessibility. The JNA code base needs read access on the /proc/self/exe symlink and the referenced binary. This change reduces the cases where the executing binary is read. On platforms, that don't need it, the detection step is skipped. Close: java-native-access#825
@trejkaz I merged the fix. I would have liked to see a more serious analysis and evaluation. |
We were on JNA 3.5.x and recently updated to 4.4.x.
Now we get the following error:
It seems like JNA should not be doing what looks like some kind of ELF-specific processing when I'm running on macOS.
The text was updated successfully, but these errors were encountered: