Kai Ole Hartwig
24 min read
By

OpenJDK CVE-2026-114938 (Java4Shell): One padding character too many opens the Base64 decoder's write mask

Once a Java service has decoded enough Base64, the JIT compiler swaps the Java code for a hand-written assembly routine that writes up to 64 bytes at once on servers with AVX-512 VBMI. A bit mask decides which of those bytes actually reach memory, and the routine computes exactly that mask wrongly for a short remainder with padding. An output length of zero becomes minus one once the equals sign is subtracted, the mask opens completely, and for an input of 64 characters plus = the routine puts 62 bytes past the end of the target array. Java then rejects the input correctly, but by that time the neighbouring objects on the heap are already damaged. Because Keycloak, Jenkins and many other applications decode Base64 before any login, the researchers who found it turned this into code execution without credentials.

TL;DR — 90 seconds

Why a Java decoder can overwrite memory

Java counts as memory safe because the virtual machine checks every array access. Those checks live in the bytecode and in the code the JIT compiler generates from it. For some frequently used methods of the standard library HotSpot takes a different route. The optimising compiler C2 replaces them with so-called intrinsics, machine code that the JDK developers wrote by hand for a particular CPU. For java.util.Base64.Decoder, StubGenerator::generate_base64_decodeBlock in src/hotspot/cpu/x86/stubGenerator_x86_64.cpp generates such a routine. It only runs once C2 has classified the method as hot and compiled it, which happens quickly in a busy service. From that moment on the JVM relies on the stub to respect the bounds of the target array by itself.

The AVX-512 variant entered the main line in June 2021 with JDK-8268276, shipped in JDK 18 and was backported to OpenJDK 17.0.6, released in January 2023. According to Calif it processes input in blocks of 256 bytes, then in blocks of 64 bytes. For a remainder below 64 bytes it uses the instruction VMOVDQU8, evmovdqub in the HotSpot assembler. This instruction reads or writes up to 64 bytes at once and takes a 64-bit mask whose set bits determine which bytes actually go to memory. The mask is built with bzhi from a value with all bits set and the desired length. bzhi clears all bits from the given position upwards. If that position is 64 or larger, the value stays unchanged.

This is exactly where the bug was. The routine computes the output length of the remainder as three quarters of the input length, rounded down to whole groups of four, and then subtracts one byte for each padding character at the end. If the remainder is shorter than one complete group of four, for example just = or X==, the output length is already zero before the subtraction. Afterwards it reads minus one or minus two, which as an unsigned number is a huge value. bzhi then leaves the mask fully set, and evmovdqub writes all 64 bytes. For the input of 64 characters plus =, Java allocates an array of 50 bytes according to Calif, the stub decodes the first 48 correctly, and the following write with an open mask starts at offset 48. 62 bytes land past the array. On JDK 17 the threshold is higher, there it takes 128 characters plus padding.

That Java still rejects the input is no comfort. The stub detects the invalid position, stops and reports how many bytes it processed. The Java code takes over the rest and cleanly throws an IllegalArgumentException. By then the write has long happened. According to the analyses by Endor Labs and other researchers, the basic and the URL decoder are affected, while the MIME decoder does not use the stub. The reason the bug went unnoticed for so long is simple: valid Base64 never reaches the faulty branch, it takes deliberately broken input. Even so, a user had already hit it in production in June and reported a crash to Adoptium.

What the fix commit changes

The fix is commit 5177a70 with the unremarkable title “8393212: Base64 optimization improvements”, written by Tobias Hartmann together with Albert Mingkun Yang. It adds exactly four lines to stubGenerator_x86_64.cpp, right after the label L_finalBit, where according to the comment 1 to 63 bytes remain to be decoded. The new logic compares the remaining length with 4 and jumps to L_bruteForce if fewer than four characters are left. The accompanying comment says that a padded remainder shorter than one complete block is handled by Java.

What the fix does not do is worth noting. It does not correct the mask arithmetic and does not catch the negative length either. Instead it restores the precondition under which the arithmetic holds: at least one complete group of four has to be present. Everything below that goes to the slower but checked Java path. My reading is that the root cause was less a calculation error than an unstated assumption the code never checked. A proposed fix had already been opened in September as pull request openjdk/jdk#32781 and, according to Calif, was closed without being merged. Only after Calif had shown exploitable chains did the fix make it into the coordinated update on 17 November.

From the login form to code execution

Red Hat lists four conditions that must all hold. The application runs on OpenJDK from 17.0.6 or on 21, 25 or 27 before the fix. The CPU is an x86-64 CPU with AVX-512 VBMI. The JVM was not started with -XX:UseAVX=2 or lower. And the application passes Base64 from an untrusted source to java.util.Base64.Decoder. No special configuration is needed, because HotSpot picks the accelerated path automatically as soon as the CPU reports the extension. Every such installation is therefore affected out of the box.

The fourth condition is almost always met in practice. Base64 is used in HTTP Basic credentials, JSON Web Tokens, SAML messages, cookies and CSRF tokens, and all of these are typically decoded before a login has even been checked. The Keycloak team explicitly confirms that Keycloak processes Base64 on requests before authentication, so a login requirement does not protect it. Calif also describes a client-side path: a Java program that opens a TLS connection to a malicious server can be compromised as well, even if it offers no service of its own.

Turning the overflow into code execution, on the other hand, is manual work. According to Calif the attacker essentially controls only where the write lands, while the overwritten values are fixed except for two bytes. Calif uses this limited write to enlarge the length field of a neighbouring array. Through that array further neighbours can then be overwritten with chosen values, and a second enlarged array whose content flows back into the application's response discloses parts of the heap. Already at this intermediate step the attacker sees memory contents such as keys, tokens and personal data. Only after that come arbitrary writes reaching the JVM's code cache.

For the objects to sit next to each other, the attacker has to prepare the heap. According to Calif the decoder first has to warm up until C2 has compiled it, then suitable objects are sprayed and the overflow is triggered. If the layout is wrong, the JVM crashes and the attacker tries again. The remote variant Calif describes controls the order of allocations through partially sent request bodies and is sensitive to network latency and jitter. A reverse proxy that buffers request bodies completely, as nginx does by default with proxy_request_buffering, removes the basis for some of these profiles. Calif stresses, however, that this is no general protection, because the chain against Elasticsearch works with a single complete request and websocket frames pass unbuffered after the upgrade. There is no universal exploit, every application needs its own profile.

Really affected is therefore any service that runs on a matching node and accepts external Base64, above all identity services, CI servers and admin interfaces exposed to the internet. Only believing to be affected applies to anyone running exclusively on ARM64 such as AWS Graviton or on older x86 generations like Skylake-SP, Cascade Lake or AMD before Zen 4. In between lies a grey area that is easy to overlook. In a Kubernetes cluster with mixed node groups the scheduler decides anew on every rollout which CPU a pod lands on, and a virtual machine is only affected if the hypervisor passes avx512vbmi through to the guest. AWS lists C6i, M6i, R6i, C7i, M7i, R7i, C7a, M7a and R7a as affected EC2 families, while Java workloads on Graviton are not affected according to AWS.

CVEAffectedFixPreconditionCVSS
CVE-2026-114938 (JDK-8393212, Java4Shell)OpenJDK 17.0.6 to 17.0.21.0.3, 21 up to 21.0.13.0.3, 25 up to 25.0.5.0.3, 27 up to 27.0.1.0.3; only x86-64 with AVX-512 VBMI17.0.21.1 / 21.0.13.1 / 25.0.5.1 / 27.0.1.1Application decodes external Base64 with java.util.Base64, C2 has compiled the decoder8.1 (OpenJDK/Oracle), 9.8 (Red Hat), 9.2 under CVSS 4.0 (Calif)

The different scores come from how attack complexity is rated. OpenJDK and Oracle set it to high because of the heap grooming required, Red Hat to low. Amazon Linux rates it 8.8. Calif has published a harmless trigger that only checks whether a runtime is affected, but is holding back the application-specific chains. Several security firms say they have built their own exploits. According to Tenable, GreyNoise reported scanning and exploitation attempts as of 18 November, with no confirmed compromise so far. According to Tenable the flaw is not in the CISA KEV catalog. The EPSS score, however, has risen sharply: according to FIRST it stood at 57.3 percent on 23 November, which corresponds to the 99.1st percentile.

Fixed versions and how to get there

The complete fix is a new Java runtime. OpenJDK and Oracle published the builds 17.0.21.1, 21.0.13.1, 25.0.5.1 and 27.0.1.1 on 17 November. Distributions follow with their own version numbers. Amazon Corretto ships 17.0.21.1.2, 21.0.13.1.2, 25.0.5.1.2 and 27.0.1.1.4. On Amazon Linux 2023, according to AWS bulletin 2026-189-AWS, the fixes are in ALAS2023-2026-3478 for Corretto 17, 3479 for Corretto 21, 3480 for Corretto 25 and 3481 for Corretto 27. On Amazon Linux 2, ALAS2-2026-4123 contains the package java-17-amazon-corretto-17.0.21.1.2-1.amzn2.1. There are no fixes for the intermediate lines 18 to 20, 22 to 24 and 26, the only option there is moving to a maintained line.

For Keycloak one distinction matters that many overlook. The flaw is not in Keycloak but in the runtime underneath, so the Keycloak version alone says nothing about protection. Since 19 November the official images tagged latest, 26.8, 26.8.2 and 26.8.2-3 contain Red Hat OpenJDK 21.0.13.1. The tags 26.8.2-1 and 26.8.2-2 still contain the vulnerable runtime. If you build your own images on top of quay.io/keycloak/keycloak, you inherit the base image's runtime and need to rebuild. The Keycloak Operator runs in its own JVM, based on OpenJDK 25 in the 26.8.2 image, and needs separate treatment.

The fix itself changes no observable behaviour, it simply sends short padded remainders to the Java path. The pitfalls are in the rollout. Rebuilding your own image only helps if the base image has already been republished. The Apollo project, for example, pointed out on 18 November that eclipse-temurin:17-jre-jammy had not been updated yet and a rebuild still pulled the old runtime. So check with java -version in the finished image which runtime is really inside after every build. On Amazon Linux 2023 the repository metadata initially did not list the CVE, so dnf upgrade --cve CVE-2026-114938 found nothing. Update the Corretto packages explicitly instead, as the AWS bulletin shows with dnf update … --releasever=latest. Instances locked to a release version need at least 2023.12.20261117 according to AWS. Amazon Linux AMIs and container images do not include Corretto by default, so only systems where it was installed are affected. And finally every update only takes effect after the JVM restarts, a package on disk changes nothing about the running process.

Until the new runtime runs everywhere, -XX:-UseBASE64Intrinsics is Red Hat's preferred interim mitigation. The flag disables only the accelerated Base64 routine and leaves all other AVX-512 optimisations alone. The alternative -XX:UseAVX=2 switches AVX-512 off entirely, costs correspondingly more performance and keeps the JVM from starting on ARM64, where the flag is unknown. In fleets with mixed architectures it is therefore the worse choice.

For Keycloak, the Keycloak team and Red Hat describe the path precisely. The server reads additional JVM options from JAVA_OPTS_APPEND. With the Operator, the variable belongs in the Keycloak resource, either under spec.env or under spec.unsupported.podTemplate in the keycloak container. An existing value is extended, not replaced. The Operator pod itself starts java directly and ignores JAVA_OPTS_APPEND, so there you set JDK_JAVA_OPTIONS on the Deployment, or with OLM in spec.config.env of the Subscription. Afterwards all pods have to restart, and you verify on the running process with jcmd <pid> VM.flags -all. The expected line is bool UseBASE64Intrinsics = false with the origin {command line}. A configured environment variable alone proves nothing.

Hardening beyond the patch

First some context, because many familiar reflexes fail with this flaw. The bug sits below the language, in machine code the JVM brings along itself. Nothing at the Java level can catch it, no framework, no input validation in application code and no security library, as long as it ends up calling java.util.Base64. Only four classes of measures are effective: removing the faulty code path, keeping it away from matching hardware, making exploitation harder, and limiting the damage after successful exploitation. The first two prevent the memory corruption, the last two make it expensive and less rewarding.

Disabling the intrinsic and deciding deliberately

The flag -XX:-UseBASE64Intrinsics works because it prevents exactly the substitution that makes the bug possible in the first place. The decoder stays Java code with the usual bounds checks, and the faulty stub never runs. The price is slower decoding of large amounts of data. The benchmarks from the original review show how large the difference is: at 64 bytes the stub was about 1.4 times as fast, at 512 bytes about nine times, at 20 kilobytes almost twenty times. For an identity service that decodes short tokens and headers, I consider this a small part of the work per request, and the Apollo project calls the cost negligible for its case. Calif draws a fundamental lesson from it: an optimisation that few applications need runs as attack surface on all the others. I therefore consider it reasonable to keep the flag on services with little Base64 load even after patching. The downside is that you then maintain a deviation from the default that deserves a deliberate review with every runtime update.

Where you set the flag matters. According to the JDK documentation, JDK_JAVA_OPTIONS is only read by the java launcher, and applications that start the JVM differently ignore it. JAVA_TOOL_OPTIONS is evaluated by the JVM itself at startup, which reports it with “Picked up JAVA_TOOL_OPTIONS” on stderr. For Keycloak the start script takes JAVA_OPTS_APPEND. In all cases: setting the variable in a Deployment overrides a default value from the image. The Cardano Rosetta Java project points out exactly this: setting your own JDK_JAVA_OPTIONS replaces the image default and with it the protection.

Keeping Java workloads off AVX-512 VBMI nodes

The faulty code only exists for one specific CPU extension. If a pod runs on a node without avx512vbmi or on ARM64, HotSpot never selects the stub. In Kubernetes this can be steered through labels. Node Feature Discovery publishes CPU features as labels, in this case feature.node.kubernetes.io/cpu-cpuid.AVX512VBMI, and a nodeAffinity with the operator NotIn on the value true keeps affected workloads off such nodes. Alternatively you schedule Java services onto ARM64 nodes via kubernetes.io/arch, provided your images are multi-arch.

The limits are clear. The NFD documentation notes that a label only shows that the CPU supports a feature, not that it is enabled. Without NFD the label is missing entirely, and a NotIn rule then admits every node. New node groups with modern hardware undermine the rule as soon as the label is not maintained. I therefore see it as a stopgap for clusters where patching takes longer, not as a replacement for the flag or the update.

Making exploitation harder and failed attempts visible

The chain Calif describes depends on two things: retries after crashes and precise timing. In Kubernetes the kubelet restarts a crashed container automatically, and that is exactly what gives the attacker the next attempt. What I derive from this: a JVM crash in an internet-facing Java service should not be restarted silently but should raise an alert, for example via the container's restart count and via hs_err_pid files. A rate limit on login and token endpoints at the ingress also reduces the number of attempts per source. Buffering complete request bodies in the reverse proxy disrupts some profiles according to Calif, but is explicitly no general protection.

Limiting the damage after exploitation

If the chain succeeds, foreign code runs with the privileges of the Java process. What it can do there is decided by the securityContext. With runAsNonRoot: true, allowPrivilegeEscalation: false, capabilities.drop: ["ALL"], readOnlyRootFilesystem: true and seccompProfile.type: RuntimeDefault a pod largely meets the Pod Security Standard “restricted”. These settings do not prevent the memory corruption, but they take away the easiest ways for loaded code to persist in the container or to break out towards the node. With a read-only file system Keycloak needs at least /opt/keycloak/data as emptyDir, because according to the docs the server stores runtime data such as transaction logs there, plus /tmp as the JVM's default directory for temporary files. Test the combination before rolling it out, since custom providers or themes may need further writable paths.

A NetworkPolicy with policyTypes: [Egress] works at a different point. Keycloak needs only a few outbound destinations: the database, the other cluster members for the cache, DNS, SMTP and connected identity providers or LDAP. Everything else can be blocked, which removes reverse connections, downloading further tooling and exfiltration over new connections. There is one limit you should know. The heap disclosure Calif describes returns its data to the attacker in the normal HTTP response, and no egress rule helps against that.

Keeping secrets in the heap short-lived

Whatever sits in a JVM's memory cannot be protected against heap disclosure, only limited in how long it stays valid. For Keycloak this includes the realm signing keys, client secrets, sessions and the database password. Short token lifetimes, a practised rotation of realm keys and database credentials that can be changed without downtime decide how long a stolen secret stays valuable. This is not a special measure for this flaw, but the flaw shows why it pays off.

Runtime inventory instead of a dependency scan alone

Whether a service is affected follows from three facts that usually live in different tools: the runtime build in the image, the CPU of the node, and whether external Base64 is decoded. An image scanner such as Trivy or Grype reliably detects a packaged OpenJDK, but often not a runtime created with jlink or a JRE embedded in a product. A CVE gate in the pipeline prevents new images with a vulnerable runtime from being rolled out, but it does not find existing deployments. I therefore recommend an inventory that records runtime version and node type for every Java workload, complemented by a regular comparison with the running pods.

What does not help here

A login does not protect, because decoding happens before it. Signatures in a web application firewall only cover part of it. AWS has published dedicated Java4Shell rules in the KnownBadInputs rule group from version 1.28, but states itself that they provide only partial coverage and recommends running them in count mode against your own traffic before blocking. The reason lies in the mechanism, because the trigger is ordinary Base64 with a padding character at the end and can appear in headers, JWTs, SAML messages or cookies. seccomp, dropped capabilities and read-only file systems do not prevent the memory corruption, they only take effect afterwards. Updating the application, Keycloak for example, only helps if the new image ships a patched runtime. And a look at a pod's environment variables says nothing about which flags the running JVM actually uses.

You can find more on egress rules, Pod Security and running workloads on Kubernetes in the series TYPO3 on Kubernetes under IT-Grundschutz.

Detection and verification

You can find out whether you are affected in three steps. First the CPU: Red Hat and Calif check /proc/cpuinfo for the four flags avx512f, avx512bw, avx512vbmi and bmi2, and only if all four are present can the stub run. In Kubernetes this check belongs on every node a Java pod can land on, and with NFD a look at the label feature.node.kubernetes.io/cpu-cpuid.AVX512VBMI is enough. Then the runtime: java -version in the respective image shows the build, keeping in mind that vendor builds carry their own numbers. Finally the running flags with jcmd, as described above.

Whether someone has already attacked the flaw is harder to answer. No indicators of compromise have been published so far. Semgrep names unexplained JVM crashes with hs_err_pid files and bursts of IllegalArgumentException from java.util.Base64$Decoder as signs worth reviewing. Neither is proof, because broken clients leave such traces too. In Kubernetes, unexpected container restarts add to the picture. For Keycloak it is also worth checking the admin events, if enabled, for changes to clients, roles or identity providers that nobody initiated.

If you suspect an attack, first set the flag or roll out the patched runtime and restart all instances. Then assume that heap contents may have leaked. For Keycloak this means: create new realm keys with higher priority and deactivate the old ones once their tokens have expired, renew client secrets and administrator accounts, change the database password and end existing sessions. This order is my own derivation from the mechanism, there is no official guidance for it yet.

Recommendation for operators

Act now if a Java service with a runtime from 17.0.6 runs on x86-64 nodes with AVX-512 VBMI and accepts requests from the internet or from less trusted networks. This applies especially to Keycloak, Jenkins and the other services Calif names explicitly. Set -XX:-UseBASE64Intrinsics there today, verify the flag on the running process and then replace the runtime with a fixed build. With Keycloak the Operator is part of this too.

Monitoring is enough if your Java workloads run exclusively on ARM64 or on older x86 generations without AVX-512 VBMI, or still use Java 11. The runtime update still belongs in the next regular maintenance window, because the next node group with new hardware quickly turns a safe cluster into an affected one.

Regardless of the individual case, what I say with every flaw applies: patches and updates belong automated. This case shows why that also covers the runtime underneath the application. If Renovate or Dependabot propose new base images and image digests as merge requests on their own and the pipeline tests the result against staging, a runtime fix like 21.0.13.1 is a matter of hours rather than weeks. A cooldown for routine updates protects against compromised releases, and you exempt security updates from it. Because the pipeline can check the actual Java version in the image after the build, a base image that has not been updated yet also shows up in testing rather than in production. Updating by hand, on the other hand, means that during holidays nobody notices for weeks that a base image was renewed, followed by one large batch update to the cluster where nobody can tell which change caused what.

Frequently asked questions about CVE-2026-114938

Is a Keycloak update enough?+

Only if the new image contains a patched runtime. The official tags from 26.8.2-3 ship OpenJDK 21.0.13.1. Check it with java -version inside the image.

Are ARM64 nodes and older Xeons safe?+

Yes, the faulty code only runs on x86-64 with AVX-512 VBMI. Watch out for mixed node groups, though. With every rollout a pod can land on newer hardware.

Should I set -XX:UseAVX=2 instead of the Base64 flag?+

Better not. It switches off AVX-512 entirely and costs more performance. On ARM64 the JVM will not even start with it. Use -XX:-UseBASE64Intrinsics.

Do I need to rotate keys after a suspected attack?+

Yes. The flaw can disclose heap contents. For Keycloak, renew realm keys, client secrets, admin accounts and the database password, and end existing sessions.

Conclusion

Java4Shell shows where the memory safety of a managed language ends. It holds for the code the developer writes and for everything the JVM generates from it. It does not hold for the hand-written shortcuts the platform itself brings along to be faster. The fix is four lines, the bug affected only one CPU extension and still sat in the main line since 2021 and in Java 17 since January 2023, even though someone had already reported it in June. The transferable lesson has two parts. The runtime is a dependency like any other and belongs in the inventory, the scan and the update automation. And code paths a service does not need are attack surface that can be switched off, whether it is an intrinsic, a protocol or a module. How a similar case looked in PHP is shown in the article on PHP2Shell, found by the same researchers.

Sources

I check which of your Java services run a vulnerable runtime on AVX-512 nodes, apply the interim mitigation cleanly and roll out patched images automatically.

Runtime inventory for containers and hosts, Keycloak hardening on Kubernetes, egress rules and Pod Security, update automation with Renovate and tested pipelines.

Platform operations instead of consulting on paper: I continuously check, patch and harden your infrastructure.

About the author

Photo of Kai Ole Hartwig.

Kai Ole Hartwig

Freelance DevSecOps consultant · OnlyOle Consulting

Programming since 2002 – self-taught, set up my own business with KO-Web in 2012. Over 100 projects, with a focus on security, performance, automation and quality. Today freelance: DevSecOps consulting, training and software development.