Consider nesting the build directory in a not world-executable directory #919
Labels
No labels
Affects/CppNix
Affects/Nightly
Affects/Only nightly
Affects/Stable
Area/build-packaging
Area/cli
Area/evaluator
Area/fetching
Area/flakes
Area/language
Area/lix ci
Area/nix-eval-jobs
Area/profiles
Area/protocol
Area/releng
Area/remote-builds
Area/repl
Area/repl/debugger
Area/store
awaiting
author
awaiting
contributors
bug
Context
contributors
Context
drive-by
Context
maintainers
Context
RFD
crash 💥
Cross Compilation
devx
docs
Downstream Dependents
E/easy
E/hard
E/help wanted
E/reproducible
E/requires rearchitecture
Feature/S3
imported
Language/Bash
Language/C++
Language/NixLang
Language/Python
Language/Rust
Needs Langver
OS/Linux
OS/macOS
performance
regression
release-blocker
stability
Status
blocked
Status
invalid
Status
postponed
Status
wontfix
testing
testing/flakey
Topic/Large Scale Installations
ux
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lix-project/lix#919
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Describe the bug
Due to all parent directories of the build directory being world-executable, derivations can make their build directory world-writable. This allows other users to place unwanted files there, including AF_UNIX sockets which we probably don't want, similarly to the abstract sockets that are now blocked due to the network namespacing.
Steps To Reproduce
nix build --impure --expr '(import <nixpkgs> {}).runCommand "meow" {} "chmod 777 /build; sleep inf"'Expected behavior
The build directory should not be world-writable, probably best using an intermediate directory with 700 permission.
nix --versionoutputnix (Lix, like Nix) 2.94.0-dev
System type: x86_64-linux
Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/aloisw/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/aloisw/.local/share/flatpak/exports/etc/xdg/nix/nix.conf:/var/lib/flatpak/exports/etc/xdg/nix/nix.conf:/home/aloisw/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/aloisw/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user/aloisw/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/0f4j1zqffzg63746jgxi68g2g012wf15-lix-2.94.0-pre-20250713_2090853b8026/share
Additional context
Cppnix did this to make CVE-2024-38531 not exploitable due to lacking the allowlist sandbox (although apparently there might now be a way around that too?):
github.com/NixOS/nix@1d3696f0fb,github.com/NixOS/nix@ede95b1fc1. However this has caused several regressions (keep-failed not working properly, build directory not being cleaned up, Darwin breakage) which we should avoid.that's only possible for linux-sandboxed builds due to filesystem namespacing. without namespacing all intermediates must be executable by the build user, otherwise everything breaks. the best we could do for those cases is to make the intermediate directory 750 owned by daemon user and build user group.
You're right, that was actually the first regression they fixed but I overlooked it. They didn't do 750 but skipped the intermediate directory entirely without sandboxing. 700 but owned by the build user could work as well I guess. It probably doesn't really matter because with sandboxing disabled you can already place builder-accessible sockets anywhere you want.
750 would still not fix it though, right? because nixbld could still do the connecting shenanigans.
That would only be in the non-sandbox case. Sandboxed builds would get 700 root.
even in the sandboxed case we'd set the intermediate mode to 0710 just to keep the branch count low. darwin sandboxed builds still need it at 0710, and since linux sandbox builds are completely isolated from another anyway it seems a bit unnecessary to set g-x there.
This issue was mentioned on Gerrit on the following CLs: