Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log4j Disable Literal Pattern Converter #46

Open
wants to merge 1 commit into
base: decoupled
Choose a base branch
from

Conversation

cliveverghese
Copy link

Although -DformatMsgNoLookups=true prevents lookups directly in the message, Format Lookups are possible when reading a property from the ThreadContext/MDC in the pattern for the message. On certain scenarios, this can cause a StackOverflow through recursive lookups as described on CVE-2021-45105.

This patch disables lookups in Message Pattern by patching LiteralPatternConverter.

The patch for LiteralPatternConverter is not enabled by default and can be enabled using the following parameters

patcherClassName=com.amazon.corretto.hotpatch.patch.impl.set.Log4j2PatchSetWithDisableLookups

echo "Running Literal Pattern Converter JDK${JVM_MV} Test"
echo "------------------"

start_dos_test ${JDK_DIR} ${AGENT_JAR}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to capture the pid of the process and kill it later.

Comment on lines +47 to +50
public static boolean isEnabled(String args) {
String param = "--enable-" + NAME;
return args != null && args.contains(param);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think isEnabled is in the current implementation


@Override
public int getVersion() {
return 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the version for the patchset, if so this is version 1 of Log4j2PatchSetWithDisableLookups.

local agent_jar=$2

pushd "${ROOT_DIR}/test" > /dev/null
${jdk_dir}/bin/java -cp log4j-core-2.12.1.jar:log4j-api-2.12.1.jar:. -Dlog4j2.configurationFile=${ROOT_DIR}/src/test/resources/log4j-vuln2.properties -javaagent:${agent_jar}=patcherClassName=com.amazon.corretto.hotpatch.patch.impl.set.Log4j2PatchSetWithDisableLookups Vuln2 > /tmp/vuln2.log &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you hotpatch with this? If so please add tests and doc updates

restarting the Java process. This tool will also address
[CVE-2021-45046](https://nvd.nist.gov/vuln/detail/CVE-2021-45046/).

To Patch for [CVE-2021-45105](https://nvd.nist.gov/vuln/detail/CVE-2021-45105), you can run the tool with the following
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please expand on when/why some one would need to patch for this and what the side effects of it are.

@@ -46,6 +46,19 @@ function start_static_target() {
popd > /dev/null
}

function start_dos_test() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that verifies by default the dos patcher is not active?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants