From 293d885c5eea88b83c8ff75dc3929b49c4c242e6 Mon Sep 17 00:00:00 2001 From: Sola Ajayi Date: Wed, 18 Nov 2026 10:11:01 +0100 Subject: [PATCH] Mitigate CVE-2026-114938 (Java4Shell) with -XX:-UseBASE64Intrinsics Default Keycloak startup paths decode Base64 before authentication (Basic auth, JWTs, SAML). On vulnerable OpenJDK builds with AVX-512 VBMI, malformed input can trigger heap corruption (see https://calif.io/java4shell/). Add -XX:-UseBASE64Intrinsics to kc.sh, kc.bat, and the operator image entrypoint until patched JDKs are widely available in base images. Closes #55293 Signed-off-by: Sola Ajayi --- operator/Dockerfile | 2 +- quarkus/dist/src/main/content/bin/kc.bat | 3 ++- quarkus/dist/src/main/content/bin/kc.sh | 4 +++- .../java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/operator/Dockerfile b/operator/Dockerfile index 03c13de622af..75593a3fc972 100644 --- a/operator/Dockerfile +++ b/operator/Dockerfile @@ -18,7 +18,7 @@ USER 1000 WORKDIR /opt/keycloak -ENTRYPOINT [ "java", "-Djava.util.logging.manager=org.jboss.logmanager.LogManager", "-jar", "quarkus-run.jar" ] +ENTRYPOINT [ "java", "-XX:-UseBASE64Intrinsics", "-Djava.util.logging.manager=org.jboss.logmanager.LogManager", "-jar", "quarkus-run.jar" ] # common labels ARG KEYCLOAK_VERSION diff --git a/quarkus/dist/src/main/content/bin/kc.bat b/quarkus/dist/src/main/content/bin/kc.bat index fed43b1b50a1..40eac16c18b3 100644 --- a/quarkus/dist/src/main/content/bin/kc.bat +++ b/quarkus/dist/src/main/content/bin/kc.bat @@ -111,7 +111,8 @@ if not "x%JAVA_OPTS%" == "x" ( rem If the memory is not used, it will be freed. See https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers for details. rem To optimize for large heap sizes or for throughput and better response time due to shorter GC pauses, consider ZGC and Shenandoah GC. rem As of KC25 and JDK17, G1GC, ZGC and Shenandoah GC seem to be eager to claim the maximum heap size. Tests showed that ZGC might need additional tuning in reclaiming dead objects. - set "JAVA_OPTS=-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.err.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -XX:+ExitOnOutOfMemoryError -Djava.security.egd=file:/dev/urandom -XX:+UseG1GC -XX:FlightRecorderOptions=stackdepth=512 -Djdk.tls.rejectClientInitiatedRenegotiation=true" + rem -XX:-UseBASE64Intrinsics disables hardware-accelerated Base64 intrinsics to mitigate CVE-2026-114938 (Java4Shell). + set "JAVA_OPTS=-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.err.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -XX:+ExitOnOutOfMemoryError -Djava.security.egd=file:/dev/urandom -XX:+UseG1GC -XX:FlightRecorderOptions=stackdepth=512 -Djdk.tls.rejectClientInitiatedRenegotiation=true -XX:-UseBASE64Intrinsics" if "x%JAVA_OPTS_KC_HEAP%" == "x" ( if "!KC_RUN_IN_CONTAINER!" == "true" ( diff --git a/quarkus/dist/src/main/content/bin/kc.sh b/quarkus/dist/src/main/content/bin/kc.sh index 65d67bdd42ea..d19041ca2a4f 100644 --- a/quarkus/dist/src/main/content/bin/kc.sh +++ b/quarkus/dist/src/main/content/bin/kc.sh @@ -91,7 +91,9 @@ if [ -z "$JAVA_OPTS" ]; then # If the memory is not used, it will be freed. See https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers for details. # To optimize for large heap sizes or for throughput and better response time due to shorter GC pauses, consider ZGC and Shenandoah GC. # As of KC25 and JDK17, G1GC, ZGC and Shenandoah GC seem to be eager to claim the maximum heap size. Tests showed that ZGC might need additional tuning in reclaiming dead objects. - JAVA_OPTS="-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.err.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -XX:+ExitOnOutOfMemoryError -Djava.security.egd=file:/dev/urandom -XX:+UseG1GC -XX:FlightRecorderOptions=stackdepth=512 -Djdk.tls.rejectClientInitiatedRenegotiation=true" + # -XX:-UseBASE64Intrinsics disables hardware-accelerated Base64 intrinsics to mitigate CVE-2026-114938 (Java4Shell). + # See https://calif.io/java4shell/ + JAVA_OPTS="-XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.err.encoding=UTF-8 -Dstdout.encoding=UTF-8 -Dstderr.encoding=UTF-8 -XX:+ExitOnOutOfMemoryError -Djava.security.egd=file:/dev/urandom -XX:+UseG1GC -XX:FlightRecorderOptions=stackdepth=512 -Djdk.tls.rejectClientInitiatedRenegotiation=true -XX:-UseBASE64Intrinsics" if [ -z "$JAVA_OPTS_KC_HEAP" ]; then if [ "$KC_RUN_IN_CONTAINER" = "true" ]; then diff --git a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java index 83ca48c21d14..9d9240563bc2 100644 --- a/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java +++ b/quarkus/tests/integration/src/test/java/org/keycloak/it/cli/dist/JavaOptsScriptTest.java @@ -49,6 +49,7 @@ void testDefaultJavaOpts(LaunchResult result) { String output = result.getOutput(); assertThat(output, matchesPattern("(?s).*Using JAVA_OPTS: " + DEFAULT_OPTS + ".*")); assertThat(output, containsString("-Xms64m -Xmx512m")); + assertThat(output, containsString("-XX:-UseBASE64Intrinsics")); } @Test