Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-all-tests-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-22.04-arm, windows-2022, macos-15]
jdk: [21, 8]
jdk: [27, 21, 8]
include:
- jdk: 21
# Workaround for https://github.com/bazelbuild/bazel/issues/14502
Expand Down
35 changes: 32 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.2")
# TODO: Starting with version 0.28.0 the JUnit test runner is compiled for Java 11 which breaks our JDK 8 tests.
# https://github.com/bazel-contrib/rules_jvm/pull/307
bazel_dep(name = "contrib_rules_jvm", version = "0.27.0")

# java_junit5_test always passes -Djava.security.manager=allow, which JDK 24+ refuses to start with. rules_java already
# passes it to tests on JDK 17 to 23, which need it.
single_version_override(
module_name = "contrib_rules_jvm",
patch_strip = 1,
patches = ["//third_party:contrib_rules_jvm-no-security-manager-flag.patch"],
)

bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "protobuf", version = "33.5")
Expand Down Expand Up @@ -45,9 +54,9 @@ SHADED_RUNTIME_MAVEN_ARTIFACTS = [
"io.github.classgraph:classgraph:4.8.184",
"net.bytebuddy:byte-buddy-agent:1.18.4",
"net.jodah:typetools:0.6.3",
"org.ow2.asm:asm:9.9.1",
"org.ow2.asm:asm-commons:9.9.1",
"org.ow2.asm:asm-tree:9.9.1",
"org.ow2.asm:asm:9.11.1",
"org.ow2.asm:asm-commons:9.11.1",
"org.ow2.asm:asm-tree:9.11.1",
]

# Runtime dependencies of Jazzer that are expected to be provided by the fuzzed project.
Expand Down Expand Up @@ -424,6 +433,26 @@ REMOTE_JDK21 = [
for jdk in REMOTE_JDK21
]

remote_jdk27_repos = use_extension("//third_party:jdk_27.bzl", "remote_jdk27_repos")

REMOTE_JDK27 = [
"remote_jdk27_linux",
"remote_jdk27_linux_aarch64",
"remote_jdk27_macos",
"remote_jdk27_macos_aarch64",
"remote_jdk27_windows",
]

[
use_repo(remote_jdk27_repos, "{}_toolchain_config_repo".format(jdk))
for jdk in REMOTE_JDK27
]

[
register_toolchains("@{}_toolchain_config_repo//:all".format(jdk))
for jdk in REMOTE_JDK27
]

register_toolchains("//bazel/toolchains:kotlin_toolchain")

# Used in CI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public class FuzzTargetTestWrapper {
private static final Set<String> IGNORED_WARNINGS =
// Triggered by BatikTranscoderFuzzer on macOS in Github Actions.
Collections.singleton("WARNING: GL pipe is running in software mode (Renderer ID=0x1020400)");
// Printed by JDK 24+ when Jazzer uses the memory-access methods of sun.misc.Unsafe (#1069).
private static final Pattern IGNORED_UNSAFE_WARNINGS =
Pattern.compile(
String.join(
"|",
"^WARNING: A terminally deprecated method in sun\\.misc\\.Unsafe has been called",
"^WARNING: sun\\.misc\\.Unsafe::\\w+ has been called by ",
"^WARNING: sun\\.misc\\.Unsafe::\\w+ will be removed in a future release",
"^WARNING: Please consider reporting this to the maintainers of class "));
private static final String EXCEPTION_PREFIX = "== Java Exception: ";
private static final String FRAME_PREFIX = "\tat ";
private static final Pattern SANITIZER_FINDING = Pattern.compile("^SUMMARY: \\w*Sanitizer");
Expand Down Expand Up @@ -137,7 +146,8 @@ public static void main(String[] args) {
"-XX:+UseParallelGC",
"-XX:+IgnoreUnrecognizedVMOptions",
"-XX:+CriticalJNINatives",
"-XX:+EnableDynamicAgentLoading"));
"-XX:+EnableDynamicAgentLoading",
"--enable-native-access=ALL-UNNAMED"));
if (System.getenv("JAZZER_DEBUG") != null && System.getenv("JAZZER_DEBUG").equals("1")) {
command.add("--debug");
}
Expand Down Expand Up @@ -258,6 +268,7 @@ private static boolean verifyFuzzerOutput(
lines.stream()
.filter(line -> line.startsWith("WARN") || line.startsWith("ERROR"))
.filter(line -> !IGNORED_WARNINGS.contains(line))
.filter(line -> !IGNORED_UNSAFE_WARNINGS.matcher(line).find())
.collect(toList());
boolean sawError = warningsAndErrors.stream().anyMatch(line -> line.startsWith("ERROR"));
if (!expectedWarningOrError.isPresent() && !warningsAndErrors.isEmpty()) {
Expand Down
7 changes: 7 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ The following JVM settings are recommended for running Jazzer:
instrumentation.
* `-XX:+EnableDynamicAgentLoading`: Silences a warning with JDK 21 and later triggered by the Java agent that Jazzer
attaches to instrument the fuzzed code.
* `--enable-native-access=ALL-UNNAMED`: Allows Jazzer to load its native libraries.
JDK 24 and later warn without it, and a future JDK will refuse to run Jazzer without it.

The `jazzer` binary sets these options automatically.
When running fuzz tests with JUnit, pass them to the test JVM together with `-XX:+IgnoreUnrecognizedVMOptions`, so that
each JDK ignores the options it doesn't support, e.g. via `argLine` of the Maven Surefire plugin or `jvmArgs` of the
Gradle `test` task.


## Passing JVM Arguments
Expand Down
5 changes: 4 additions & 1 deletion launcher/jvm_tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,13 @@ JVM::JVM() {
// Optimize GC for high throughput rather than low latency.
options.push_back(JavaVMOption{(char *)"-XX:+UseParallelGC"});
// CriticalJNINatives has been removed in JDK 18, EnableDynamicAgentLoading
// has been added in JDK 9.
// has been added in JDK 9, --enable-native-access in JDK 17.
options.push_back(JavaVMOption{(char *)"-XX:+IgnoreUnrecognizedVMOptions"});
options.push_back(JavaVMOption{(char *)"-XX:+CriticalJNINatives"});
options.push_back(JavaVMOption{(char *)"-XX:+EnableDynamicAgentLoading"});
// Allows Jazzer to load its native libraries, which JDK 24+ otherwise warns
// about and a future JDK will deny.
options.push_back(JavaVMOption{(char *)"--enable-native-access=ALL-UNNAMED"});
#endif

std::vector<std::string> java_opts_args;
Expand Down
34 changes: 17 additions & 17 deletions maven_install.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
"org.openjdk.jmh:jmh-core": -975784527,
"org.openjdk.jmh:jmh-generator-annprocess": -833845560,
"org.opentest4j:opentest4j": -1152999839,
"org.ow2.asm:asm": 1206815935,
"org.ow2.asm:asm-commons": 1607605466,
"org.ow2.asm:asm-tree": -1365652182,
"org.ow2.asm:asm": 1350841764,
"org.ow2.asm:asm-commons": 890415337,
"org.ow2.asm:asm-tree": -1086258535,
"org.springframework.cloud:spring-cloud-function-context": 191971828,
"org.springframework.cloud:spring-cloud-function-core": -1854900684,
"org.springframework:spring-messaging": 328550982,
Expand All @@ -92,10 +92,10 @@
"com.google.guava:listenablefuture": 1079558157,
"com.google.j2objc:j2objc-annotations": -1008747351,
"com.google.protobuf:protobuf-java": 1555861032,
"com.google.truth.extensions:truth-java8-extension": 1186293162,
"com.google.truth.extensions:truth-liteproto-extension": 2044092816,
"com.google.truth.extensions:truth-proto-extension": -194966365,
"com.google.truth:truth": -1359112801,
"com.google.truth.extensions:truth-java8-extension": -2015579325,
"com.google.truth.extensions:truth-liteproto-extension": -1385654615,
"com.google.truth.extensions:truth-proto-extension": -2008601139,
"com.google.truth:truth": -1509608953,
"com.h2database:h2": 475457751,
"com.mikesamuel:json-sanitizer": 1715785415,
"com.unboundid:unboundid-ldapsdk": -911278373,
Expand Down Expand Up @@ -148,7 +148,7 @@
"org.glassfish:javax.el": 631698101,
"org.hamcrest:hamcrest-core": 649657847,
"org.hibernate:hibernate-validator": 1029552718,
"org.jacoco:org.jacoco.core": -1495664227,
"org.jacoco:org.jacoco.core": -1636461585,
"org.javassist:javassist": 1095674094,
"org.jboss.logging:jboss-logging": 197007362,
"org.jetbrains.kotlin:kotlin-reflect": -1292560044,
Expand All @@ -170,9 +170,9 @@
"org.openjdk.jmh:jmh-core": 262505124,
"org.openjdk.jmh:jmh-generator-annprocess": 554503664,
"org.opentest4j:opentest4j": -1584531193,
"org.ow2.asm:asm": 1614653533,
"org.ow2.asm:asm-commons": 33716409,
"org.ow2.asm:asm-tree": -1173653421,
"org.ow2.asm:asm": -406993722,
"org.ow2.asm:asm-commons": 1705619162,
"org.ow2.asm:asm-tree": -1950755079,
"org.reactivestreams:reactive-streams": -164947187,
"org.springframework.boot:spring-boot": 2047288717,
"org.springframework.boot:spring-boot-autoconfigure": 1133681824,
Expand Down Expand Up @@ -766,21 +766,21 @@
},
"org.ow2.asm:asm": {
"shasums": {
"jar": "6f3828a215c920059a5efa2fb55c233d6c54ec5cadca99ce1b1bdd10077c7ddd"
"jar": "ae4e6e10d59d0a1500317764b21881ad883f8550e33c66e6142f7032c6fb566c"
},
"version": "9.9.1"
"version": "9.11.1"
},
"org.ow2.asm:asm-commons": {
"shasums": {
"jar": "c2319e014ce7199f2b7f7d56d6bb991863168c3f4b6cd6c9f542a4937ef7ef88"
"jar": "6a5095ec53726156a78b2cd2efd45bc4e877754eca7c234f61224a53d6bfa661"
},
"version": "9.9.1"
"version": "9.11.1"
},
"org.ow2.asm:asm-tree": {
"shasums": {
"jar": "0f3555096b720b820bbacab0b515589bee0200bee099bda14c561738ae837ba1"
"jar": "2b15c3c1b288a9fad3bb2cd6d988ba9521554914ed1f2a2029141fa3f483154a"
},
"version": "9.9.1"
"version": "9.11.1"
},
"org.reactivestreams:reactive-streams": {
"shasums": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.lang.instrument.Instrumentation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import net.bytebuddy.agent.ByteBuddyAgent;

Expand Down Expand Up @@ -52,11 +55,31 @@ public static void install(boolean enableAgent) {
Class<?> agent = Class.forName("com.code_intelligence.jazzer.agent.Agent");
Method install = agent.getMethod("install", Instrumentation.class);
install.invoke(null, instrumentation);
} catch (ClassNotFoundException
| InvocationTargetException
| NoSuchMethodException
| IllegalAccessException e) {
} catch (InvocationTargetException e) {
if (isNativeAccessDenied(e)) {
throw new IllegalStateException(
"Jazzer needs native access: add --enable-native-access=ALL-UNNAMED to the JVM"
+ " arguments",
e);
}
throw new IllegalStateException("Failed to run Agent.install", e);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {
throw new IllegalStateException("Failed to run Agent.install", e);
}
}

// By default, installing the agent loads Jazzer's native library, which fails if the JVM denies
// native access.
static boolean isNativeAccessDenied(Throwable t) {
Set<Throwable> seen = Collections.newSetFromMap(new IdentityHashMap<>());
for (; t != null && seen.add(t); t = t.getCause()) {
// Compare by name as IllegalCallerException doesn't exist in Java 8, which Jazzer targets.
if (t.getClass().getName().equals("java.lang.IllegalCallerException")
&& t.getMessage() != null
&& t.getMessage().startsWith("Illegal native access")) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2026 Code Intelligence GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.code_intelligence.jazzer.agent;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNoException;

import org.junit.Test;

public class AgentInstallerTest {
private static Throwable illegalCallerException(String message) {
try {
return (Throwable)
Class.forName("java.lang.IllegalCallerException")
.getConstructor(String.class)
.newInstance(message);
} catch (ReflectiveOperationException e) {
// IllegalCallerException was added in Java 9.
assumeNoException(e);
throw new AssertionError(e);
}
}

@Test
public void detectsDeniedNativeAccess() {
Throwable denied = illegalCallerException("Illegal native access from an unnamed module");
assertTrue(
AgentInstaller.isNativeAccessDenied(
new RuntimeException(new ExceptionInInitializerError(denied))));
}

@Test
public void ignoresOtherIllegalCallerExceptions() {
Throwable other = illegalCallerException("module java.base does not open java.lang");
assertFalse(AgentInstaller.isNativeAccessDenied(new RuntimeException(other)));
}

@Test(timeout = 10_000)
public void handlesCyclicCauses() {
RuntimeException first = new RuntimeException();
RuntimeException second = new RuntimeException(first);
first.initCause(second);
assertFalse(AgentInstaller.isNativeAccessDenied(first));
}
}
35 changes: 35 additions & 0 deletions src/test/java/com/code_intelligence/jazzer/agent/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
java_test(
name = name,
srcs = ["NativeAccessTest.java"],
args = args,
jvm_flags = [
"-XX:+IgnoreUnrecognizedVMOptions",
"--illegal-native-access=deny",
],
main_class = "com.code_intelligence.jazzer.agent.NativeAccessTest",
use_testrunner = False,
deps = [
"//src/main/java/com/code_intelligence/jazzer/agent:agent_installer",
# Provides Jazzer's native library.
"//src/main/java/com/code_intelligence/jazzer/driver:fuzz_target_runner",
],
)
for name, args in [
("NativeAccessTest", []),
(
"NativeAccessWithoutAgentTest",
["--without_agent"],
),
]
]

java_test(
name = "AgentInstallerTest",
size = "small",
srcs = ["AgentInstallerTest.java"],
deps = [
"//src/main/java/com/code_intelligence/jazzer/agent:agent_installer",
"@maven//:junit_junit",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2026 Code Intelligence GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.code_intelligence.jazzer.agent;

import java.util.Arrays;

/** Runs with native access denied, see BUILD.bazel. */
public class NativeAccessTest {
public static void main(String[] args) {
boolean enableAgent = !Arrays.asList(args).contains("--without_agent");
String version = System.getProperty("java.specification.version");
// Older JDKs ignore --illegal-native-access, which was added in JDK 24.
boolean nativeAccessDenied = !version.startsWith("1.") && Integer.parseInt(version) >= 24;
// By default, installing the agent loads Jazzer's native library. Without the agent, e.g. in
// JUnit regression tests with hooks disabled, no native access is needed.
boolean expectFailure = enableAgent && nativeAccessDenied;
try {
AgentInstaller.install(enableAgent);
} catch (IllegalStateException e) {
if (expectFailure && e.getMessage().contains("--enable-native-access=ALL-UNNAMED")) {
return;
}
throw e;
}
if (expectFailure) {
throw new IllegalStateException("Expected AgentInstaller.install to fail");
}
}
}
Loading
Loading