Skip to content
Race condition Write-up Advanced

NixOS: Declarative Management, Imperative Privilege Escalation

The Nix daemon's garbage collector deletes store paths using openat with absolute paths, which ignores the directory file descriptor, so a user who retains write access to a failed build's output directory can swap directories during deletion and redirect the privileged recursive delete outside the store. Combined with other flaws, this allows privilege escalation from any user to root on a stock NixOS system.

labs.snyk.io

Published on labs.snyk.io

Recently, during a research project, the Snyk Security Labs team identified several vulnerabilities in implementations of the Nix package manager, the build system forming the basis of the NixOS operating system, which also impacted derivatives such as Lix and Guix. These vulnerabilities, when combined, can result in…

The author, on labs.snyk.io

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 write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the recursive delete routine passes absolute paths to openat, so the directory file descriptor is ignored and the path can be swapped between the type check and the open.

Impact

When chained with the other flaws, this could allow privilege escalation from any user to root on a stock NixOS system; the issues have been patched.

What the attacker needed

Local user account; ability to run Nix builds; attacker process outside sandbox; garbage collection triggered

The fix

The vulnerabilities were fixed by the NixOS, Lix and Guix teams, and users should update to the patched versions.

How it was found

  1. Start a fixed-output Nix build that fails, keeping its output directory in the store owned by the build user.
  2. From inside the build, send a file descriptor for the output directory over an abstract Unix socket to a cooperating process outside the sandbox.
  3. Use the received descriptor to keep write access to the store directory after the build ends.
  4. Trigger garbage collection so the daemon recursively deletes the directory.
  5. Swap a directory for a symlink or different path between the daemon's type check and its open call to redirect the delete.

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 write-up has not been written yet. The Original tab links to the source.

NixOS is a Linux system where all software lives in one read-only folder called the store, managed by a powerful background program. A normal user can start a software build, and if the build fails, its output folder is kept in the store but still owned by the unprivileged build user. The cleanup routine that later deletes such folders follows paths in a way that can be tricked, so the powerful program ends up deleting or touching files it should not, which can lead to full control of the machine.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.