r/programming • • 4d ago

Java4Shell is a reason to use Java

https://mccue.dev/pages/11-18-26-java4shell
44 Upvotes

49 comments sorted by

View all comments

59

u/gredr 4d ago edited 4d ago

That's a lot of words to say --enable-native-access is a good security feature. OP isn't really wrong. Without it, you're vulnerable to MS07-052: Code execution leads to code execution.

Interesting that the JVM doesn't frame --enable-native-access as a security feature at all; it's an integrity feature. If you're running a malicious (or vulnerable) dependency, blocking native access isn't going to save you. See also: Java4Shell's namesake, Log4Shell.

41

u/koflerdavid 4d ago

Interesting that the JVM doesn't frame --enable-native-access as a security feature at all; it's an integrity feature.

Java has given up on achieving in-process security. Sandboxing is very hard to get right; as we have seen it is already hard enough to ensure memory safety. Thus, restricting 3rd party libraries from using FFI is not about security, but about ensuring that operations is aware that dependencies are doing something that might make code not run as initially intended by the developers, might dork up the JVM, or cause issues that are out of control of the JVM.

19

u/gredr 4d ago

.NET gave it up for the same reason.

10

u/bowbahdoe 4d ago

I think both --enable-native-access and --module-path are integrity features, but integrity features are security features. Here the issue is that native code mucks with the JVM's memory. Thats an issue for integrity that also lets people do RCE (allegedly).

The module system stuff is similar. Code in a library can't accidentally mess with the threading model since java.lang.Thread hides that stuff in the java.base module. Putting user code in modules also limits the scope of what a badly written library can do to that code.

Network and File System level security is mostly left up to Docker/OS controls though.

13

u/svick 3d ago

You really shouldn't treat non-security features as security features.

If a bug is found in a security feature, the usual approach is:

  • We need to fix this ASAP.
  • We try hard to prevent anyone from knowing anything about it before it's fixed.
  • We make sure it's fixed in all supported versions.

If a bug is found in a non-security feature, the more usual approach is:

  • We'll get to it when we'll get to it.
  • Everything about the bug is public.
  • It's only going to be fixed in the version that comes out in many months.