GHSL-2023-046: Local Privilege Escalation in sccache - CVE-2023-1521
The sccache client sends its local environment variables to the server, which then executes compile commands with those variables. An attacker can set LD_PRELOAD to a malicious shared library, and if the server runs as root, this allows the attacker to execute arbitrary code with root privileges.
Originally disclosed on GitHub Security Lab
On Linux the sccache client can execute arbitrary code with the privileges of a local sccache server, by preloading the code in a shared library passed to LDPRELOAD.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The server executes compile commands using environment variables supplied by the client without filtering dangerous variables like LD_PRELOAD.
Impact
A regular user on a Linux machine with a system-wide sccache installation running the server as root can gain full administrative access to the machine.
What the attacker needed
Sccache server running as root; local user can run sccache client
The fix
The issue was fixed in v0.4.0.
How it was found
- Install sccache via snap.
- Run the provided poc.sh script.
- The script creates a root-owned file at /oops_I_shouldnt_be_here.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
sccache is a tool that speeds up compiling by sharing results between builds. The client sends its environment settings to a server, which runs the compiler. If an attacker sets a special environment variable called LD_PRELOAD to point to their own code, the server will load and run that code. If the server runs as root, the attacker's code runs as root too.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.