Skip to content

eBPF-based security platform

upatches: add badDecoder, which shows whether the Base64 guard is in a JVM

John Fastabend0f3a16fbfb64
diff --git a/upatches/java-base64/README.md b/upatches/java-base64/README.md
index 6da80ad6..ece7af2a 100644
--- a/upatches/java-base64/README.md
+++ b/upatches/java-base64/README.md
@@ -49,6 +49,26 @@ Shields view of `tools/xtop` lists `java-base64` as available, its
`TARGET` the jar it guards and its `FIXES` CVE-2026-114938. Appending it
to a tree with `shirudo bpm tree append` moves it to the "in trees" tab.
+## Check that the guard is in a JVM
+
+`upatches/test/build.sh` builds `upatches/test/badDecoder.jar`, which
+decodes an input of the shape the guard refuses and says who refused it.
+It exits with 0 when the guard did and with 1 in a JVM without it, where
+the JDK's own decoder refuses the input:
+
+```sh
+upatches/test/build.sh
+java -jar upatches/test/badDecoder.jar
+```
+
+A test VM sees the checkout at `/mnt/shirudo-src`, so the jar built on
+the host runs there, in a JVM that a user manager starts after the
+upatch is loaded:
+
+```sh
+java -jar /mnt/shirudo-src/upatches/test/badDecoder.jar
+```
+
## Try it against the Elasticsearch lab
The Elasticsearch compose lab is a JVM that shirudo does not manage, so
diff --git a/upatches/test/.gitignore b/upatches/test/.gitignore
new file mode 100644
index 00000000..51afffae
--- /dev/null
+++ b/upatches/test/.gitignore
@@ -0,0 +1,2 @@
+/badDecoder.jar
+target/
diff --git a/upatches/test/BadDecoder.java b/upatches/test/BadDecoder.java
new file mode 100644
index 00000000..c5be199c
--- /dev/null
+++ b/upatches/test/BadDecoder.java
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: BSD-2-Clause
+// Copyright (c) 2026 Authors of shirudo
+//
+// Decodes a Base64 input of the shape the java-base64 guard refuses, and
+// says who refused it: exit status 0 when the guard did, 1 when the JVM
+// runs without it.
+
+import java.util.Base64;
+
+public class BadDecoder {
+ // 66 bytes: a tail of two past a 64-byte block, one of them padding.
+ private static final String CANDIDATE = "A".repeat(64) + "A=";
+ private static final String GUARD = "Rejected Base64 x64 tail-underflow candidate";
+
+ public static void main(String[] args) {
+ try {
+ Base64.getDecoder().decode(CANDIDATE);
+ System.out.println("badDecoder: decoded, no guard");
+ } catch (IllegalArgumentException e) {
+ if (GUARD.equals(e.getMessage())) {
+ System.out.println("badDecoder: refused by the guard");
+ return;
+ }
+ System.out.println("badDecoder: no guard, the JDK refused: " + e.getMessage());
+ }
+ System.exit(1);
+ }
+}
diff --git a/upatches/test/build.sh b/upatches/test/build.sh
new file mode 100755
index 00000000..96858348
--- /dev/null
+++ b/upatches/test/build.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# Build badDecoder.jar, the program that shows whether the java-base64
+# guard is in a JVM:
+# upatches/test/build.sh
+# java -jar upatches/test/badDecoder.jar
+#
+# Needs javac and jar on PATH. The jar runs on a JRE of release 17 or
+# newer, which is all a test VM has.
+
+set -eu
+
+cd "$(dirname "$0")"
+rm -rf target
+mkdir -p target
+javac --release 17 -d target BadDecoder.java
+jar cfe badDecoder.jar BadDecoder -C target .