Skip to content
Path traversal Write-up Advanced

Nix 2.24 is vulnerable to (remote) privilege escalation

Nix 2.24 mishandles NAR archive unpacking so that a directory entry containing both a symlink and a directory of the same name causes the symlink to be followed and written through. Because the daemon runs as root, a local unprivileged user or a malicious binary cache can write files into privileged locations and gain persistent root access, and signatures are checked only after unpacking.

puckipedia.com

Published on puckipedia.com

okay so. nix 2.24+ vuln: nar unpacking is fucked, and local unprivileged users, or any binary cache you have configured, can just Get Root on your system

The author, on puckipedia.com

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 a refactoring mistake in NAR unpacking that lets a symlink and a directory sharing a name be conflated, so writes follow the symlink instead of staying inside the archive.

Impact

An unprivileged local user or a malicious binary cache could write files as root and gain persistent root access; in some cases, such as a trusted NAR containing a symlink to root, this could be done silently.

What the attacker needed

Access to the nix daemon as an untrusted user; or a configured binary cache; daemon runs as root with store writable

The fix

It should be fixed by correcting the NAR unpacking so symlinks are not followed, and by validating signatures before unpacking; the text notes downgrading to Nix 2.23 or restricting allowed-users as mitigations.

How it was found

  1. Create a NAR file containing a directory with both a symlink and a directory of the same name.
  2. Have the Nix daemon unpack the NAR, either by submitting it as an untrusted user or by serving it from a configured binary cache.
  3. The symlink is followed and the directory contents are written to the symlink's target, such as a systemd unit directory.
  4. The written files give persistent root access.

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.

Nix is a package manager that stores software in a shared folder called the Nix store, and a background service (the daemon) manages that store as the root user. A NAR is the archive format Nix uses to pack up files. The unpacking code confused a link (a shortcut to another file) with a real folder of the same name, so it wrote data through the link to wherever it pointed, including system folders that only root should change.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.