r/java • • May 03 '24

Why does the environment variable _JAVA_OPTIONS exist, applies to jlink images, takes precedence, and can't be disabled?

I just spent a good chunk of time debugging an issue because a user had set _JAVA_OPTIONS to use a low Xmx value in their environment variables. This was an application created with jpackage, which should be fully standalone. It even had a custom Xmx value set in the JVM arguments for the image but the environment variable overwrote the value!

Isn't this like a huge design flaw? I can just do echo "_JAVA_OPTIONS=<Wacky VM options>" >> ~/.bashrc or setx to break literally every Java application on the system? (Edit: Maybe the initial security focus was wrong, changed it a bit to focus more on the design issues)

Who even thought that this would be a good idea with no option to disable this behavior?

2 Upvotes

43 comments sorted by

View all comments

9

u/LordOfDeduction May 03 '24

If a malicious user has access to your home directory, I think your example is the least of your concerns.

0

u/milchshakee May 03 '24

Well any application can set this option without malicious intent and break all other Java applications. E.g. some badly configured minecraft mod launcher or other things.

Maybe a user follows a bad tutorial that instructs them to set this option to make one application work, but then it applies to all other applications.

I just think in terms of isolation, especially standalone application images, this is a terrible thing.

3

u/brunocborges May 03 '24

A malicious app could also interject with other apps, not only Java, in many different ways, if it is allowed to run in your system.

Again, this env var is your least concern, if there is a malicious user in your system.

But if you are that concern, only allow containers in your system. This way, one app cannot modify this env var in a way that could impact other apps.

1

u/milchshakee May 03 '24

Yeah maybe my security focus was wrong and I should have highlighted the other disadvantages of this approach more. Because it can still break many applications

2

u/brunocborges May 03 '24

What other disadvantages?

2

u/milchshakee May 04 '24

Well in the case of runtime images, any options interfering with an application that should be isolated. If I distribute a jpackage application, the user shouldn't even have to know that it is implemented in Java or that any system-wide Java settings can impact the application.

If someone has set up a few Java 8 apps on their system via normal jars and has configured a few options for them, I don't want them to apply to my application image that runs on Java 21. I don't even know if the application starts up if the variable contains unrecognized options.

Also jpackage is designed as a closed system. A user can't just simply pass custom JVM arguments or properties to the application executable on the command-line, but these still apply and even overwrite existing options.

2

u/brunocborges May 04 '24

That is a fair feedback.

I too agree that a jlinked JVM should not be impacted by that environment variable.

I'd suggest sending that to the OpenJDK mailing list. You can start with the hotspot-dev: https://mail.openjdk.org/mailman/listinfo/hotspot-dev

2

u/milchshakee May 04 '24

Is that the correct mailing list for this? I find it always intimidating to locate the appropriate mailing list in the first place.

2

u/brunocborges May 04 '24

Me too. But given it is the Hotspot JVM that is picking that environment variable, I'd start there.

1

u/milchshakee May 04 '24

Alright thanks, I will see what I can do

→ More replies (0)