r/programming • • 7d ago

Calif discloses Java4Shell flaw in OpenJDK's Base64 decoder

https://runtimewire.com/article/calif-discloses-java4shell-flaw-in-openjdk-s-base64-decoder
556 Upvotes

98 comments sorted by

24

u/stoops 6d ago

Q29uZ3JhdHVsYXRpb25zISBJZiB5b3UgYXJlIHJlYWRpbmcgdGhpcyBtZXNzYWdlIHdlJ2QgbGlrZSB0byBvZmZlciB5b3UgYSBwb3NpdGlvbiBhdCBNaWNyb3NvZnQgb2YgIkFzc2lzdGFudCB0byB0aGUgU2VuaW9yIFZpYmVzLU9QUyBNYW5hZ2VyIiE=

21

u/ryanmerket 6d ago

spoilers

-4

u/reddah 6d ago

Q29uZ3JhdHVsYXRpb25zISBJZiB5b3UgYXJlIHJlYWRpbmcgdGhpcyBtZXNzYWdlIHdlJ2QgbGlrZSB0byBvZmZlciB5b3UgYSBwb3NpdGlvbiBhdCBNaWNyb3NvZnQgb2YgIkFzc2lzdGFudCB0byB0aGUgU2VuaW9yIFZpYmVzLU9QUyBNYW5hZ2VyIiE=

Congratulations! If you are reading this message we'd like to offer you a position at Microsoft of "Assistant to the Senior Vibes-OPS Manager"!

Used Linux to decode the above, so, No, thanks, I'm good. Keep the offer.

1

u/Existing-Return-5308 6d ago

Padding attacks are a favorite; fertile ground for intelligence agency techniques.

1

u/stoops 6d ago edited 6d ago

Amen friend. I always use Macs for desktops and Linux for servers! :)

184

u/bowbahdoe 6d ago

The quickest way to deal with this is to add -XX:-UseBASE64Intrinsics to your JVM flags. After that, of course, upgrade.

303

u/RegisteredJustToSay 6d ago

Oh great. This one probably impacts more services than most of the other recent disclosures.

118

u/anurodhp 6d ago

Will be hard to beat php

56

u/alphex 6d ago

That was legit. But very hard to execute on. There were no major platform exploits reported.

-4

u/GeneralSEOD 6d ago

That we know off. My understanding into the exploit is it was also pretty hard to know if it actually popped off?

16

u/lurch303 6d ago

Java can beat PHP in deployment. This is much smaller in the number of versions affected though.

8

u/Chii 6d ago

the java exploit is harder to do tho, compared to the php one (apparently - each java server needs to have a customized exploit written for it based on what server it's running on? I have not investigated in detail).

10

u/ric2b 6d ago

Luckily we don't have machines capable of writing custom software quickly.

14

u/patmorgan235 6d ago

Yeah this sounds like a Log4J type event

38

u/fakehalo 6d ago

This seems harder to exploit than that was.

6

u/ManyInterests 6d ago

True, but honestly, we probably shouldn't rely on difficulty curve stopping exploits in today's world. Especially with user-controlled base64 inputs being so ubiquitous.

13

u/Pharisaeus 6d ago

Memory corruption requires a lot of insight into the target. Turning few bytes heap overflow into rce is not something easy to achieve, even with ai support. For custom software you're fine, but if you're running some standard docker container with a popular pierce of software, then it will be targeted for sure.

1

u/st4rdr0id 6d ago

Yes, the impact surface is huge. The ammount of companies heavily invested in Java and the criticality of the services provided with it demands proper formal verification of all those clever assembly replacements for what we devs thought was our code.

47

u/al2o3cr 6d ago

42

u/timwoj 6d ago

Or link directly to the actual report from the authors: https://calif.io/java4shell

5

u/meneldal2 6d ago

Kinda crazy how simple the input has to be to trigger the bug

4

u/renatoathaydes 5d ago

Yes but even when you trigger it, it’s not clear what happened because depending on what is on the heap, there are no symptoms. I was only able to reproduce the bug clearly by hitting a segfault during GC, otherwise the memory corruption just went unnoticed and you only see the expected IllegalArgumentException.

1

u/meneldal2 5d ago

Oh that makes sense it would manage to sneak for so long then.

45

u/SuperGr33n 6d ago

I still have PTSD from log4j. Once upon a time I managed logging for a web service and guess what we used for log aggregation? Logstash. Thousands of servers and very little in the way of config management. Absolutely no master inventory or cmdb. I spent days auditing and running ansible. Thank goodness I’ve since moved on to greener pastures because this one sounds like hell

11

u/stoops 6d ago

yeah log4j was ridiculous, people were going crazy just trying to patch that one on all servers/vms!

2

u/Squalphin 6d ago

Eh, still will not be convincing enough to upgrade away from Java 8 😂

3

u/ric2b 6d ago

I do not know with which weapons WW3 will be fought, but command and control systems in WW4 will still be running Java 8.

2

u/chicknfly 5d ago

From the article: “Upwind's scope is wider than the first reports focused on Java 17. It says Temurin 17.0.6, 17.0.21, 21.0.13 and 25.0.5 all wrote past the array in its tests, with Java 27 affected by its reading of the code. Java 11.0.33 and 17.0.5 were clean.”

They didn’t even test JDK 8 😭

3

u/bwainfweeze 6d ago edited 6d ago

The double edged sword of making every piece of code independent. You can experiment with new ideas and techniques, and if they don't work, it's fine. If they do work, you can share knowledge with other teams.

But now the other teams can vote with their feet and not listen to any of your advice. The Lava Flow antipattern is -everywhere- and if you have to go change some behavior, it's not only a giant slog, but some motherfuckers found a spot to hide several projects that aren't in the official location all projects are supposed to be, so you miss a couple in the audit.

Had a hosting project where every UI theme was a separate module, and we decided three or four times we were doing something wrong, from directory structure to CI steps to localization. Every one was a separate PR, and after the first one I broke it up into groups of 15 and had a handful of people do each clump, so none of us wanted to claw our eyes out. The perpetrator of this stupidity wasn't even there for me to throw things at. He noped out the minute he realized people weren't amazed by his ideas and were actually kinda done.

The worst part of looking at a wall of nearly identical upgrades is that sooner or later you go to lunch or someone distracts you with a question and you skip from project 15 to project 17, and you may even think you remember project 16 because it's a maze of twisty little passages, all alike.

Annoyingly that's probably the sort of thing AI would be good at.

1

u/ptrichardson 6d ago

Same here! When I saw "PHP4Shell" I shuddered. Now I see Java4Shell its the same, if not worse. Agghhhhhhh!!!!!!1

MS04-11 will come back up soon. Damn, I'm getting old!

169

u/Compux72 6d ago

Ofc the unsafe, hand written asm strikes again

13

u/pron98 6d ago

It's a compiler intrinsic. What would it be written in? A compiler intrinsic is some specific chunk of machine code.

-8

u/Compux72 6d ago

Calif’s report stated it was a piece of hand written asm that is there to replace the pure Java version as an throughput optimization, not a compiler intrinsic as you say.

17

u/pron98 6d ago edited 6d ago

I work on the JVM and I do, indeed, say that, and so did Calif:

The issue lies in OpenJDK HotSpot's x86-64 Base64 intrinsic.

Intrinsics are where we have hand-rolled assembly in the JVM (plus in the interpreter, but that's a separate matter). This is what intrinsics are in all compilers, regardless of the type-safety of the language they compile, because we're now dealing with the language's backend, where it turns into machine code.

45

u/6502zx81 6d ago

Yes, why use a bytecode vm with type safety etc. when you can use assembly?

91

u/SpudsRacer 6d ago

Because it's a hot spot in the applications using it.

12

u/lurch303 6d ago

Someone got a bonus and promotion for getting their P95 under 1ps

2

u/Compux72 6d ago

Wasn’t HotSpot VM so good it could beat C/ASM code?

1

u/st4rdr0id 6d ago

We certainly seem to be in the same bandwagon when it comes to securty.

0

u/svick 6d ago

.Net uses SIMD intrinsics for that. I guess Java doesn't have those?

49

u/bowbahdoe 6d ago

Java using SIMD intrinsics is what caused the problem. There was an issue with those intrinsics

7

u/bwainfweeze 6d ago

FTA, it's not the SIMD code that's the problem, it's the cleanup code to deal with the remainder. Which is probably why the repro takes a lot of explaining.

3

u/bowbahdoe 6d ago

Yeah its diving into assembly at all that is the risky thing. A JIT compiler needs to do it, which highlights why Java <in general> can be safer. Most of the code isn't written at that level.

1

u/bwainfweeze 6d ago

I know sometime around the second or third version of the JIT, there was a version of Java where a pretty significant chunk of the graphics code was rewritten in native code in one major version, and then ditched in the next because the JIT was fast enough to get similar results. Less maintenance overhead and better user visibility to go back, and that version of native calls had a pretty high overhead. They were okay with that because they didn't want to use it frivolously, but as Java got faster they eventually introduced a new calling convention that was faster.

0

u/Kjufka 6d ago

It was not Java SIMD intrinsics

-9

u/svick 6d ago

I mean, in .Net, you directly use the intrinsics from C#, no assembly necessary.

2

u/bowbahdoe 6d ago

I think in this case thats a point _for_ Java. The intrinsics here only kicked in because the JVM built them in. This is clearly a risky thing to do, as this issue shows. It is a good thing for overall security that that mechanism is kept out of reach for most.

-14

u/happyscrappy 6d ago

C# is compiled. Java is bytecoded.

You can't put x86 SIMD instructions inline in bytecode as it isn't x86 code.

10

u/ILMTitan 6d ago

C# is basically Microsoft Java. It compiles to a bytecode very similar to Java's.

-2

u/happyscrappy 6d ago

Okay. I give up then.

In the KerbalSpaceProgram subreddit I asked about if it (it's in C#) could be ported to another processor by changing the JIT and I was told it was compiled natively so that can't happen.

I guess I'll have to go back and ask again there because I got the wrong answer.

7

u/ILMTitan 6d ago

Kerbal Space Program isn't entirely C#. It is in Unity, which combines an (I assume C++) engine with C# scripting.

→ More replies

5

u/McLayan 6d ago

If it's based on Unity3D the game uses its own scripting runtime and also compiles the JIT code to native code through IL2CPP. If I got it correctly, the process is C# -> IL (bytecode) -> C++ -> native binary

4

u/Enerbane 6d ago

I don't know how Kerbal is compiled, but you can do AoT (Ahead of Time) compilation with C#, which avoids the JiT.

13

u/Kjufka 6d ago

Microsoft released a lot of silent RCE patches for dotnet, we don't know the details only because it never went through public channels.

5

u/svick 6d ago

Microsoft does release a lot of security patches for .Net, including some RCEs. But I don't think any of them are silent, they are announced publicly. See the dotnet/announcements repo.

5

u/ManyInterests 6d ago

So silent you've heard about them! Isn't dotnet Open Source now?

1

u/AlexanderMomchilov 6d ago

Those intrinsically are themselves implanted in hand rolled assembly, no?

1

u/svick 6d ago

The JIT has to generate the machine code and that part can have bugs.

But I think having to write assembly by hand for every optimized algorithm is much more risky.

1

u/AlexanderMomchilov 6d ago

The JIT is essentially stamping out instances of a hand written template of instructions, substituting in the names of registers, various flag bits, etc. That’s equally prone to mistakes, if not more.

But yeah I agree, at least that centralizes the risk to a single place to verify, rather than scattering it among many libraries hand rolling it

3

u/pron98 6d ago

This is the compiler backend; the thing the type-safe bytecode compiles to.

2

u/st4rdr0id 6d ago

I'm 100% for pure bytecode interpretation because thats what provides the security. However Sun chose to go down the JIT path already in the late 1990s. Would Java had survived had the JVM stayed pure? I don't know. But if performance was so important, then hardware accelerators should have been the way to go at that point. Otherwise they should have just created another C++ to begin with. Giving up on pure bytecode interpretation was a mistake. Let companies like Netflix use performance languages like C or Rust, and leave a pure JVM to us people who just demand secure conventional compute.

2

u/Living_Beyond_6613 5d ago

You can run with -Xint to force interpreted mode. I don't recommend it though, it's very slow.

32

u/eipMan 6d ago

Writeup by calif who discovered the bug: https://calif.io/java4shell

17

u/aookami 6d ago

uh oh

8

u/Cloudy-Blue 6d ago

Here go my next few nights

58

u/whinner 6d ago

“Calif’s Quang Luong found it with AI assistance in about an hour, and built the first working exploit in two more.”

We are so cooked

71

u/lurch303 6d ago edited 6d ago

I really do not like this part of the announcement. It is misleading propaganda. It's like saying a gambler in Vegas won millions by wagering only $1.00. It ignores all the failed attempts and wasted money that came before the one successful bet. It’s been a few weeks since their last exploit. How many hours and tokens did their team burn before hitting the jackpot?

-24

u/FriendlyKillerCroc 6d ago • Popcorn

Just can't admit AI is really fucking good, can you? 

6

u/lurch303 6d ago

It has nothing to do with the quality of AI. I take issue with the purposeful absence of information to mislead the reader.

2

u/lurch303 4d ago

It turns out that Calif just read the open pull requests of the repo... https://github.com/openjdk/jdk/pull/32781

3

u/inio 6d ago

Sure, but HTF do you burn $200 of tokens in 3hr? I wouldn't be surprised if 90% of that was in the first hour searching thousands of files in parallel for potential exploits.

4

u/Vakz 6d ago

No problem at all if you're using the bigger models. Also barely any money at all if you're a government sponsored black hat group looking for exploits. This was just one guy who thankfully told people about what he found. Probably don't want to know how many are using the exploits instead of disclosing.

4

u/Waste_Jello9947 6d ago

Isn't base64 used by JWT authentication? That's a big problem

2

u/Living_Beyond_6613 5d ago

Basic authentication also

10

u/TheMoatman 6d ago edited 6d ago

I haven't read their actual writeup yet to check, but it's potentially overhyped.
The article says they gave it a 9.2 CVSS, but the NVD currently has it at 8.1 (admittedly, rated by Oracle) and describes it as "difficult to exploit". It also says:

Note: This vulnerability can only be exploited by supplying data to APIs in the specified Component without using Untrusted Java Web Start applications or Untrusted Java applets, such as through a web service.

https://nvd.nist.gov/vuln/detail/cve-2026-114938

e: Still haven't actually read it but I did open their writeup: they rated it under CVSS 4.0, so it could could be a CVSS 3.0 vs 4.0 difference too. In that case, it may be real bad shit.

10

u/Pharisaeus 6d ago edited 6d ago

difficult to exploit

In needs to be running on specific hardware and that's a memory corruption bug, so not easy to exploit in general. You get few bytes heap overwrite so you need your exploit to setup the heap in a particular way. Realistically to develop an exploit you need an exact copy of the target.

So while it's not going to break the internet, it does provide a powerful attack vector for a targeted attack.

6

u/lurch303 6d ago

That note from Oracle is meaningless. An attacker is not going to be using your front end application to attack your services and trying to prevent anything but your front end from contacting your APIs is an exercise of futility. The Calif announcement includes an example using KeyCloak which is a very widely deployed open source IDP.

6

u/quack_quack_mofo 6d ago

Arm64 is safe no?

4

u/happyscrappy 6d ago

It would seem so. Unless you're emulating.

Wonder if there's any assembly in the ARM64 Java base64 decoder.

2

u/inio 6d ago

Well presumably there would be some NEON, but its vector length is much shorter so the same bug likely would be hard/impossible to turn into RCE.

1

u/nekokattt 6d ago

Neon isnt AVX-512 so isnt on the code path

3

u/isaackogan 6d ago

Well fuck

Q2hhdCwgd2UncmUgc28gY29va2VkLg==

1

u/stoops 6d ago

Q2hhdCwgd2UncmUgc28gY29va2VkLg==

bG9s

1

u/wildjokers 5d ago

We also demonstrated RCE in sample applications built on widely used frameworks, including Apache Struts

I bet there hasn't been any greenfield development done with Apache Struts in at least 15 years, it is definitely not "widely used".

-10

u/IndividualHouse8628 6d ago

What does this mean for people that don’t have any kind of programming or cybersecurity knowledge

28

u/spicypixel 6d ago

That you already died and this is purgatory 

-8

u/IndividualHouse8628 6d ago

Now what does that mean? Is it too much to ask for a straight answer?

1

u/Existing-Return-5308 6d ago

Good coders speak in riddles. It helps handle talking to machines all day.

It may be something that dies out, now AI will do all the coding.

9

u/mouse_8b 6d ago

You'll probably see a number of "*4Shell" exploits in the coming months. A "shell" is a command line/terminal, which is able to run any command on the system.

So Java4Shell means a server running a Java application can be exploited to give the attacker shell access on the machine, which means the attacker has full control of the server.

From that point there are many ways an attacker could use that compromised machine. Maybe it's an e-commerce server that processes customer data and payments. Maybe it's a server in a protected environment with access to other systems with sensitive info. Maybe the server controls infrastructure like an electric grid or water plant. Maybe it's a hospital server. Maybe it's a bank server.

In any case, that attacker could essentially see and control everything that the server is doing.

9

u/TinyBreadBigMouth 6d ago

I will note it's currently unproven that this exploit could be used to gain shell access. The exploit writes 62 bytes that the attacker does not directly control past the end of a buffer. A potential attacker would need to find a way to manipulate the program's memory allocations such that there is something important within those 62 bytes, and that the values which are written happen to contain whatever specific values will cause the program to give the attacker shell access. This has not yet been done, though the danger is definitely present.

1

u/IndividualHouse8628 6d ago

Thank you! Are average people like myself at risk? Should I upgrade the antivirus on my MacBook? I just watch movies on it and do school work for college.

2

u/SDraconis 6d ago

This is much more of a concern for servers. E.g. whether the server at your bank gets attacked using this exploit. If you aren't responsible for maintaining any Java applications, then all you need to do is update whatever Java version you have on your machine to one which has this patched.

2

u/mouse_8b 6d ago

The systems you own are likely not at risk, but the systems you use could be.

As an end-user, you should concentrate on having backups of your data (multiple if possible) and keeping your accounts secure.

For data backups, I'm talking about files that would be painful to lose. Personal pictures, videos, documents, media. The stuff you can't just download again if your hard drive crashes or the cloud goes down.

For account security, password hygiene is most important. Do not reuse a password across sites. These days, there's no reason not to use a password manager that can generate strong passwords. There are some places where it still makes sense to memorize the password, namely for the password manager itself. I also know my main email address password. Those passwords should still be unique and strong.

Further, there are more non-password options every day. Passkeys and emailing login links are becoming more mainstream.

MacOS is pretty secure by default. Try to avoid installing random software from unknown vendors, or typing terminal commands from an online stranger.

16

u/bonkyandthebeatman 6d ago

What are you doing in r/programming?

6

u/IndividualHouse8628 6d ago

It came across my explore feed

-2

u/Existing-Return-5308 6d ago edited 6d ago

https://chatgpt.com/share/6afd479a-7b94-83e8-a323-e382bb12dede

That help?

Its typically long winded AI, but sometimes it helps teach.

0

u/Existing-Return-5308 6d ago edited 6d ago

Note, there is NOTHING particularly new here.

Malformed Ethernet messages have done similar things since, oh, well before switched Ethernet came on the scene. One of the first worms used similar techniques, albeit at a different injection point.

Use the chatGPT link and go add some prompts, explore some more…. On your own using natural language, reddit type language. Throw in a bit of knowhow or conspiracy… See where it goes. Its fun.