bind-mount nix build sandbox before building derivations to allow noexec on /tmp #610
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lix-project/lix#610
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?
Is your feature request related to a problem? Please describe.
/tmpcan be mounted with mount optionnoexec. This is paranoid, but quite a common thing while hardening linux systems. Currently, the nix-daemon expects theTMPDIRto be mounted executable. Specifically, somenix buildtasks fail if this assumption aboutTMPDIRis unmet.This is an issue i came across during hardening experiments on NixOS, but can very well break on non-NixOS systems as well. To reproduce, setting up a VM and mounting
/tmpwithnoexecis not quite enough. Not all nix builds require the mount to be executable. One failure mode i found is any rust package depending on serde, but there are most certainly more failing packages.I believe this is an issue, because this makes packages sometimes fail in a way that is entirely dependent on the host setup. This means this directly impacts reproducibility.
Describe the solution you'd like
The nix daemon (here lix) should explicitly list assumptions and make sure they are met. The ideal way is to use a bind mount to create an executable mount for the build sandbox.
mount bind /tmp/noexec-dir /tmp/exec-dir -o execwill make the kernel drop thenoexecoption otherwise inherited from the parent file system. This bind mount can even optionally be in-place.Adding this bind mount would mean
TMPDIRwould still be respected, but with explicit assumptions about the underlying file system. Bind mounts basically cost nothing to create or to destroy.Adding these changes would mean lix could build derivations in a more reproducible way while keeping the security benefits users might chose with a
noexec/tmpdirectory. These changes should be compatible with any system running a kernel that supports bind mounts. This might not be all systems that Lix supports! Linux would work, but some of the more exotic platforms might not support this. In which case, there might need to be special casing. Not sure how best to handle this.Describe alternatives you've considered
One obvious option is to just not support
noexecon theTMPDIR. This would mean any user choosingnoexecfor/tmpwould have to provide an explicitTMPDIRmounted as executable. This is my current workaround [EXTERNAL LINK]. However, this is very inconvenient on non-NixOS systems where this immediately means messing with the fstab and manually changing systemd rules. And double irritating on specifically hardened impermanent systems like TailsOS.An alternative to using a bind mount can be using a
tmpfsfor the build sandbox. @atemu had voiced some concerns about this approach, as RAM limitations as well as other weirdness specific to tmpfs might cause unexpected side effects. I believe it is worth considering, but not likely to be a viable alternative to a simple bind mount.Additional context
bind mounts can give exec
Yes, bind mounts do allow

execif mounted with-o execeven if their mount parent isnoexec. I did receive some confusion about this, see screenshot for confirmation.tmpfs on nixos
For those not trusting external links, the current workaround is this:
bind mount on nixos
Similarly, bind would work as a workaround too:
Test VM with
/tmpas noexecThis VM can be built with
nix-build '<nixpkgs/nixos>' -A vm -I nixpkgs=channel:nixos-24.11 -I nixos-config=./configuration.nix.CAREFUL: requires a lot of RAM so you can use this VM to try and build nix packages.
example for a failing build
nix build github:lordgrimmauld/aa-alias-managerfor example, there is more packages, this is where i first found it.Log (notice the permission denied/never executed cased by
noexec):This seems somewhat related to
lix-project/lix@3c8096e5cbin which @lilyball allowed setting a specific temp directory for lix. That change makes this workaround significantly less cursed, setting the temp directory for the daemon in an actually intended place! Nice to see that.Assuring that temp directory is mounted with
execpermissions might still be a good idea, but at this point a simple warning/error about the temp directory not being executable could be a valid option too. That would mean the bind mount would still have to happen manually, but at least the failure mode could be loud.Do you feel like you could send us such a change?
the build sandbox has been moved out of TMPDIR to
/nixand hence this issue is no longer valid