# Copyright 2026 Tailwind Resource Group # SPDX-License-Identifier: Apache-2.0 # Provided as is, with no warranty. License: https://everythingsfine.io/license/ # # java4shell_check.sh: report the exposure of this Linux host to CVE-2026-114938. # # The script only reads /proc and the JDK "release" file. It changes nothing # and it does not start Java. Run it with bash, as root, so that it can see # every JVM: # # bash java4shell_check.sh # # Exit status: 0 = no running JVM is exposed, 1 = one or more JVMs are EXPOSED # or need REVIEW, 2 = the script cannot do the check on this host. # # The script examines running JVMs only. It does not find a JDK that is # installed but not running, or a JDK in a container image that is not running. # Lowest version with the vulnerable code on the 17 line (source: Calif). FIRST_17="17.0.6" # Lowest version with the fix on each line. Change these to agree with the # release notes of your JDK vendor. FIXED_17="17.0.21.1" FIXED_21="21.0.13.1" FIXED_25="25.0.5.1" FIXED_27="27.0.1.1" # ver_ge A B: true when version A is equal to or higher than version B. ver_ge() { [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -n 1)" = "$2" ] } # classify VERSION CPU_EXPOSED OPTIONS: print one status word and a reason. classify() { c_ver=$1 c_cpu=$2 c_opts=$3 c_major=${c_ver%%.*} c_fixed="" case "$c_ver" in "") echo "REVIEW: cannot read the Java version" return ;; 1.8.*perf*) echo "REVIEW: Java 8 performance build; Oracle lists 8u511b33-perf as affected" return ;; 1.*) echo "OK: Java 8 or earlier; the standard builds are not listed as affected" return ;; esac case "$c_major" in *[!0-9]*) echo "REVIEW: cannot read the Java version" return ;; esac if [ "$c_major" -lt 17 ]; then echo "OK: Java $c_major is not listed as affected" return fi case "$c_major" in 17) c_fixed=$FIXED_17 ;; 21) c_fixed=$FIXED_21 ;; 25) c_fixed=$FIXED_25 ;; 27) c_fixed=$FIXED_27 ;; esac if [ "$c_major" = 17 ] && ! ver_ge "$c_ver" "$FIRST_17"; then echo "OK: lower than $FIRST_17; Calif says the vulnerable code starts at $FIRST_17" return fi if [ -n "$c_fixed" ] && ver_ge "$c_ver" "$c_fixed"; then echo "OK: at or above $c_fixed; confirm the fix in the release notes of your vendor" return fi if [ "$c_cpu" != yes ]; then echo "OK: affected version, but this CPU does not use the vulnerable code" return fi # The JVM uses the last value of an option. If the options disagree, # the script does not decide. c_b64=no c_avx=no c_dis=no c_plus=no c_avx3=no case " $c_opts " in *" -XX:-UseBASE64Intrinsics "*) c_b64=yes ;; esac case " $c_opts " in *" -XX:UseAVX=0 "*|*" -XX:UseAVX=1 "*|*" -XX:UseAVX=2 "*) c_avx=yes ;; esac case " $c_opts " in *DisableIntrinsic=*_base64_decodeBlock*) c_dis=yes ;; esac case " $c_opts " in *" -XX:+UseBASE64Intrinsics "*) c_plus=yes ;; esac case " $c_opts " in *" -XX:UseAVX=3 "*) c_avx3=yes ;; esac if [ "$c_avx" = yes ] && [ "$c_avx3" = no ]; then echo "MITIGATED: -XX:UseAVX is 2 or lower; install the fixed JDK" return fi if [ "$c_b64" = yes ] && [ "$c_plus" = no ]; then echo "MITIGATED: -XX:-UseBASE64Intrinsics is set; install the fixed JDK" return fi if [ "$c_dis" = yes ] && [ "$c_plus" = no ]; then echo "MITIGATED: DisableIntrinsic names the Base64 decode intrinsic; install the fixed JDK" return fi if [ "$c_b64$c_avx$c_dis" != nonono ]; then echo "REVIEW: the options disagree; confirm with jcmd" return fi if [ -z "$c_fixed" ]; then echo "EXPOSED: Java $c_major has no fixed version; move to a supported line (our estimate)" return fi echo "EXPOSED: affected version on an affected CPU, and no mitigation option found" } if [ ! -r /proc/cpuinfo ]; then echo "Cannot read /proc/cpuinfo. This script is for Linux." >&2 exit 2 fi cpu_exposed=no if [ "$(uname -m)" = "x86_64" ]; then cpu_flags=$(grep -m 1 '^flags' /proc/cpuinfo) cpu_exposed=yes for flag in avx512f avx512bw avx512vbmi bmi2; do case " $cpu_flags " in *" $flag "*) ;; *) cpu_exposed=no ;; esac done fi echo "CPU: $(uname -m), uses the vulnerable Base64 code: $cpu_exposed" if [ "$(id -u)" != 0 ]; then echo "WARNING: not root. JVMs of other users are not visible." fi found=0 bad=0 for dir in /proc/[0-9]*; do pid=${dir#/proc/} jvm=$(grep -m 1 '/libjvm\.so' "$dir/maps" 2>/dev/null | awk '{ print $NF }') [ -n "$jvm" ] || continue found=$((found + 1)) # libjvm.so is in /lib/server/. Read through /proc//root # so that a JVM in a container gives the path in its own file system. home=${jvm%/lib/*} version=$(sed -n 's/^JAVA_VERSION="\(.*\)"$/\1/p' "$dir/root$home/release" 2>/dev/null | head -n 1) opts=$(tr '\0' ' ' < "$dir/cmdline" 2>/dev/null) env_opts=$(tr '\0' '\n' < "$dir/environ" 2>/dev/null | sed -n 's/^\(JAVA_TOOL_OPTIONS\|_JAVA_OPTIONS\|JDK_JAVA_OPTIONS\)=//p' | tr '\n' ' ') result=$(classify "$version" "$cpu_exposed" "$opts $env_opts") case "$result" in EXPOSED*|REVIEW*) bad=$((bad + 1)) ;; esac echo "pid $pid: java ${version:-unknown} in $home" echo " $result" done echo "JVMs found: $found. EXPOSED or REVIEW: $bad." if [ "$bad" -gt 0 ]; then exit 1 fi exit 0