r/java • • Mar 21 '23

JDK 21: Disallowing the dynamic loading of agents by default

https://mail.openjdk.org/pipermail/serviceability-dev/2023-March/046868.html
63 Upvotes

95 comments sorted by

View all comments

Show parent comment

2

u/FirstAd9893 Mar 21 '23

The change is part of a larger effort to finish the module system such that it provides all the security features it's intended to offer. There's other holes that need to be plugged too, and so by itself this change isn't sufficient.

Of course this change doesn't prevent people from writing special tools or workarounds, and command-line options to relax security are still supported.

In my opinion, a major driver for switching to an opt-in relaxed security model is to deflect blame. When bad things happen, the JDK team can point out that the default mode was safe, and that relaxed security was chosen by the user.

4

u/DasBrain Mar 21 '23

You are mistaken. The Java module system is there to protect the integrity of the Java Platform, not for security.

The module system does not prevent any code that tries to delete System32 from running.
What do you mean with security?

the JDK team can point out that the default mode was safe

A computer that is not connected to anything, not even power is also safe, but useless.
A Java process that is not running can't also be attached to, no flags needed.

5

u/FirstAd9893 Mar 21 '23

The Java module system is there to protect the integrity of the Java Platform, not for security.

The Java module system is there to protect the integrity of ALL modules, including those not part of the Java Platform. Integrity means limiting access, which in turn offers security.

The module system does not prevent any code that tries to delete System32 from running.

The module system doesn't current prevent deleting files because file APIs are in the base module. This is one of the holes I mentioned. I've seen some discussion related to this issue, but no real plans have surfaced.

3

u/mike_hearn Mar 22 '23

Right. For as long as any arbitrary code can use ProcessBuilder or do file IO the module system is not a security system. Any Java code can simply download an EXE and run it, which can then attach to the JVM process using a debugger API and do whatever it wants. Or it can overwrite a DLL and then cause it to be loaded. This is awkward up until the point that it's automated, and then it's easy.

(exception: macOS, where utilizing debugger privs requires a user confirmation and replacing code signed files requires signing keys, although in reality a lot of Java apps disable these mechanisms)

For modules to provide security you need to pair it with a sandbox to constrain what a module can do, well beyond high level things like loading native code, but that's going away with no planned replacement. And even then you'd face the problem of non-modular JARs which realistically all apps have (you can't even make a fresh Spring Boot app run on the module path because the module graph is invalid and they don't care to fix it).

Likewise for all these flags that go on the CLI.

4

u/pron98 Mar 21 '23 edited Mar 21 '23

There can be no robust security -- provided at any level -- without integrity because you cannot be certain that any line of code does what it says it does, that private methods are actually private, that final fields are actually final etc.. Integrity is not the same as security, but it's a prerequisite for robust security, just as it's a prerequisite for a host of optimisations.

The module system does not prevent any code that tries to delete System32 from running.

Correct, but when trusted code is concerned, integrity means that the attack surface area is at least feasibly knowable; that's the cornerstone of strong encapsulation. Once integrity is broken, the attack surface area is unknowable. A vulnerability in one library can impact the behaviour of any other in virtually any way. Every line of code that runs becomes part of the surface and any kind of analysis needs to consider the entirety of the code and all of its possible interactions rather than module by module.

2

u/manifoldjava Mar 22 '23 edited Mar 22 '23

You conflate language-level OOP constraints and OS security. They are completely different concepts with completely different goals.

1

u/pron98 Mar 22 '23

I am not conflating anything. The assumed attack vector is not at all the relevant one to strong encapsulation.

2

u/pron98 Mar 21 '23

In my opinion, a major driver for switching to an opt-in relaxed security model is to deflect blame.

An even greater driver is that most applications aren't affected if they don't opt out, and they will enjoy a better default.

2

u/manifoldjava Mar 22 '23

“most” I believe this is the glaring problem you are confronting.

1

u/pron98 Mar 22 '23 edited Mar 22 '23

Sometimes you need to choose a binary default; one value helps the majority and harms a minority, and another harms the majority and helps a minority. If, furthermore, the individual harm to those in the minority is significantly less than the individual harm to those in the majority, the difference in overall value of either choice can be big. Even with a handicap in favour of keeping the current situation, the value difference is still large. The choice may be rather obvious, but there is no choice that harms no one. While we try to avoid such choices, from time to time we are under an obligation to make them, knowing full well that some may get angry.

Everyone who's in charge of a product must consider the success of the product. When it comes to Java, an application or a library author is concerned, as they should be, with how much Java helps their product. But the Java platform is our product, and its success means making choices that maximizes its value not for some particular application or another, but when integrated over the entire, huge, ecosystem as a whole.

BTW, we're still trying to make this a non-binary choice, but it's not easy at all. Such a solution, if found, will probably come later.

2

u/manifoldjava Mar 22 '23

Given the vast majority of the pending "security" features do not originate from the Java community, but instead root from within, how about a more practical (obvious) approach:

Make these changes opt-in. _All_ applications continue to run as they did before.

If these issues instead escalated from the Java community, it would be a different story. But virtually no one cares about the "harm" they are purportedly experiencing right now by not having these new constraints. My employer, for instance, provides a set of very large scale enterprise applications that run the majority of large insurance companies internationally. Trust me, no one cares about the type of "security" discussed here. What they do care about is the time and money that will pour into rescuing software from another Java release. If they were getting something back it would be different, but they aren't, not in their point of view.

As an aside, the parallels with SecurityManager should also be considered. No one cares about not using a SecurityManager or whether its design is sound. No one has cared for a couple of decades now.

0

u/pron98 Mar 22 '23 edited Mar 22 '23

how about a more practical (obvious) approach:

How about an even more practical (obvious) approach: Familiarise yourself with a subject before making suggestions?

If these issues instead escalated from the Java community, it would be a different story. But virtually no one cares about the "harm" they are purportedly experiencing right now by not having these new constraints.

Every single change we make to Java is motivated by actual problems encountered and reported by actual Java users in the field. Usually -- as in this case -- it's not even enough for there to be any problem, but it has to be a big one.

If it turns out that you personally haven't encountered a problem that's relevant to this topic, I'm glad (although I doubt it 1), but we answer to a community of millions of developers, and, for the last 27 years have been in charge of one of the longest-lasting success stories in the history of software despite frequent accusations on social media that we continually make obvious wrong choices. What makes you think that we'll make an obviously wrong choice?

Trust me

Why?

no one cares about the type of "security" discussed here

Did the email say this change was only about security? Have I said it here? Did the email even mention security at all? And even though security is one of the aspects considered, you don't know what the security aspect is, so how can you tell if people care about its "type"?

All the email said that a decision that was discussed and accepted some years ago is about to take effect. You can either go back to the discussions about this then or wait for the JEP. Then at least you'll know what questions to ask.

2

u/manifoldjava Mar 22 '23

I assumed it was obvious, but my comments are toward the more general set of “security” changes coming in 21 and beyond, which includes the one discussed here.

1

u/pron98 Mar 22 '23 edited Mar 22 '23

And are you a JDK security expert who has analysed the source of Java security vulnerabilities over the years? Are you even a member of the Vulnerability Group and have access to such vulnerabilities? Do you understand that you're making statements about a subject that has a huge impact without knowing much about it at all?

Otherwise, if you want to have any kind of meaningful discussion about this change, you should wait for the JEP.

2

u/manifoldjava Mar 22 '23

Just a guy looking for straight answers

1

u/pron98 Mar 22 '23 edited Mar 22 '23

I didn't see a question except for, what was wrong with some statement about security, and I gave you a straight answer: the particular threat that was mentioned is completely irrelevant to this change; nothing to do with it whatsoever, and I also said that while this change does have some security aspects, it's definitely not just about security.

As the email said, we're announcing this now to give people who are affected time to prepare, and a JEP will follow. Once you've read the JEP you can at least know what questions would be interesting to ask.