yawkat LZ4 Java: Native library extraction to a shared temporary directory is vulnerable to file replacement by another local userGHSA-mcr4-qmvw-px4g
Fix: yawkat/lz4-java@7a48b7fGHSA-mcr4-qmvw-px4g is a CWE-367 vulnerability in at.yawk.lz4:lz4-java. A fix is available for at.yawk.lz4:lz4-java — see the affected versions and patch details below.
Exploitation Status
No confirmed exploitation observed yet
- A successful exploit gives an attacker total control of the affected component, not partial access.
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for GHSA-mcr4-qmvw-px4g.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
Real-World Exposure
at.yawk.lz4:lz4-java☕org.lz4:lz4-javaReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects Maven packages — download data is not available via public APIs for these ecosystems.
Description
Summary
When no system-installed liblz4-java is found, net.jpountz.util.Native.load() extracts the bundled native library to java.io.tmpdir and loads it with System.load. The path of the extracted library can be predicted before it is created, and the library file is opened without exclusive creation. Another local user who can write to the same temporary directory can therefore create the file first and control the code that is loaded.
Details
tempLibLock = File.createTempFile("liblz4-java-", "." + os().libExtension + ".lck");
tempLib = new File(tempLibLock.getAbsolutePath().replaceFirst(".lck$", ""));
// copy to tempLib
try (FileOutputStream out = new FileOutputStream(tempLib)) { ... }
...
System.load(tempLib.getAbsolutePath());
Only the .lck file is created safely, with a random name and exclusive creation. The library path is the .lck name without the .lck suffix, and nothing reserves it. new FileOutputStream(tempLib) opens it with O_CREAT|O_TRUNC and follows symlinks.
In a shared, world-writable temporary directory, another user can watch for the .lck file and create the corresponding library file before it is opened. If they win that race, they own the file. The victim then writes into the attacker-owned file, and the attacker can overwrite it again before System.load.
Whether this can be exploited depends on the host:
- With
fs.protected_regular = 0, the attacker can pre-create a world-writable file, and their code is then loaded into the victim's JVM. - With
fs.protected_regular >= 1(the default on many systemd-based distributions), the victim's open fails. The library then fails to load and the library falls back to the Java implementations, so the attacker can only cause a denial of service. - A symlink variant is blocked by
fs.protected_symlinks = 1. - Temporary directories without the sticky bit, or shared across users in containers, are exploitable whatever these settings are.
This behaviour was introduced upstream in commit c3ddae5 (lz4-java 1.7.0), which swapped which of the two files is created with createTempFile.
Impact
A local user who can write to the same temporary directory as a victim process that uses the bundled JNI library may be able to execute code as the victim. Exploitation requires a shared temporary directory, host settings that permit it, and winning a race.
The issue does not apply if liblz4-java is found on java.library.path, if java.io.tmpdir is private to the user (for example systemd PrivateTmp, or a per-user temporary directory), or if only the Java implementations are used.
Patch
Fixed in lz4-java 1.11.4. The native library is now extracted directly into a file created by File.createTempFile, which has a random name and is created exclusively, so a file or symlink planted in advance cannot be reused. The .lck lock files are no longer used. Instead, the startup cleanup removes stale liblz4-java-* temporary files (including .lck files left by older versions) only once they are more than one hour old.
For older versions, the workaround is to set java.io.tmpdir to a directory writable only by the application user, or install liblz4-java on java.library.path.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| ☕Maven | at.yawk.lz4:lz4-java | all versions | 1.11.4at.yawk.lz4:lz4-java:1.11.4 |
| ☕Maven | org.lz4:lz4-java | ≥ 1.7.0 | No fix |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for at.yawk.lz4:lz4-java, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update at.yawk.lz4:lz4-java to 1.11.4 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-mcr4-qmvw-px4g is resolved across your whole dependency graph.
Workarounds
Cap what an attacker can consume: apply request size, rate and timeout limits in front of the affected component, and run it with memory and CPU limits so exhaustion degrades one worker rather than the whole service.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
This vulnerability is rated as Moderate impact for Red Hat products because exploitation requires a local attacker to win a race condition during native library extraction within a shared temporary folder. An unauthorized user on the same host must predict and alter the extracted library file before the runtime…
Configure affected Java applications to use a dedicated, private temporary directory rather than a world-writable directory such as /tmp. 1. Create a directory accessible only by the service account running the Java process: ```bash mkdir -p /var/run/app-private-tmp chmod 700 /var/run/app-private-tmp ``` 2. Add the `java.io.tmpdir` system property to the application startup arguments or service environment: ``` -Djava.io.tmpdir=/var/run/app-private-tmp ``` Caveats: Applying this configuration change requires restarting the target Java application or service. Ensure that the configured directory is maintained across reboots with correct ownership and SELinux permissions.Source: Red Hat security advisory for GHSA-mcr4-qmvw-px4g (CC BY 4.0)
Frequently Asked Questions
Is GHSA-mcr4-qmvw-px4g in your dependencies?
Find it across Maven, including transitive dependencies.