r/programming • • 17d ago

Calif discloses Java4Shell flaw in OpenJDK's Base64 decoder

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

99 comments sorted by

View all comments

Show parent comment

0

u/svick 17d ago

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

49

u/bowbahdoe 17d ago

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

7

u/bwainfweeze 16d 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 16d 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 16d 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 17d ago

It was not Java SIMD intrinsics

-9

u/svick 17d ago

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

2

u/bowbahdoe 17d 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 16d 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 16d ago

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

-2

u/happyscrappy 16d 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 16d ago

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

1

u/happyscrappy 16d ago

I had assumed the Unity runtime would be replaced with the one for the other architecture. Those are available to download. Note that finding a match by version number could be difficult or even impossible. And other versions would use different APIs I assume.

5

u/McLayan 16d 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 16d 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 17d 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 16d 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 16d ago

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

1

u/AlexanderMomchilov 16d ago

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

1

u/svick 16d 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 16d 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