Summary
Print warnings to standard error when agents are loaded dynamically into a running JVM. The warnings aim to prepare users for a future release which disallows the dynamic loading of agents by default.
Problem
Libraries that dynamically load agents that grant them "superpowers" are one of the current "loopholes" in strong integrity (see https://openjdk.org/jeps/8305968)
Solution
Print a warning to standard error when an agent is loaded into a running VM. Add a statement to the JVM TI specification, and the java.lang.instrument
package description, to mandate that a warning be printed.
For JVM TI agents, the warning is:
WARNING: A JVM TI agent has been loaded dynamically (file:/u/bob/libagent.so)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: Dynamic loading of agents will be disallowed by default in a future release
and for Java agents the warning is:
WARNING: A Java agent has been loaded dynamically (file:/u/bob/agent.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information
WARNING: Dynamic loading of agents will be disallowed by default in a future release
The warning is printed when an agent is loaded into a running VM. The trigger to load an agent into a running VM is a program using the Attach API or the jcmd JVMTI.agent_load
command.
The warning may be suppressed by running with -XX:+EnableDynamicAgentLoading
. This XX option exists since JDK 9 and is an explicit opt-in to allow agents be dynamically loaded. The default for this option is "true" and is not changed by this CSR.
As detailed in the JEP, this warning will prepare users for a future where the dynamic loading of agents will be disabled by default.
There is already a Java Flight Recorder (JFR) event when agents are loaded (https://bugs.openjdk.org/browse/JDK-8257967). No changes to this event are proposed by this CSR.
Additionally, the system property jdk.instrument.traceUsage
will enable tracing of calls to the java.lang.instrument.Instrumentation
API to help identify cases where libraries using the Instrumentation
API. If the system property is set on the command line (-Djdk.instrument.traceUsage
) or set to the value "true" ( -Djdk.instrument.traceUsage=true
) then a trace message and stack trace is printed to the standard output when the API is used.
JVM TI already has extensive tracing options since JDK 5, no changes are proposed to this tracing.
Specification
A zip file with the specdiffs is attached.
For JVM TI, "Agent Start-Up (Live phase)" section is updated to mandate that a warning be printed when an agent is started in the live phase.
The java.lang.instrument
package description has been restructured so the diffs may be difficult to read. The significant changes are:
The "Starting an agent in a running JVM" section has a statement to mandate that a warning be printed when a Java agent is loaded into a running JVM.
The description Launcher-Agent-Class, Premain-Class, and Agent-Class JAR file attributes are changed to use "binary name" rather than "class name".
There are no specification changes to go with the JDK-specific system property to enable tracing.
- csr of
-
JDK-8307478 Implementation of Prepare to Restrict The Dynamic Loading of Agents
-
- Resolved
-
- relates to
-
JDK-8177154 Default configuration should disallow loading agents
-
- Resolved
-
-
JDK-8306275 JEP 451: Prepare to Disallow the Dynamic Loading of Agents
-
- Closed
-