Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.23.1] nix sandbox broken on darwin #11002

Closed
utkarshgupta137 opened this issue Jul 1, 2024 · 5 comments · Fixed by #11031
Closed

[2.23.1] nix sandbox broken on darwin #11002

utkarshgupta137 opened this issue Jul 1, 2024 · 5 comments · Fixed by #11031
Labels
bug macos Nix on macOS, aka OS X, aka darwin regression Something doesn't work anymore

Comments

@utkarshgupta137
Copy link

utkarshgupta137 commented Jul 1, 2024

Describe the bug

Most nix commands which require building are not working on darwin anymore after upgrading to nix 2.23.1

Steps To Reproduce

Run any nix command such as darwin-rebuild, home-manager, nix flake run etc. which tries to trigger a build.

Error on darwin-rebuild switch:

error:
       … while setting up the build environment

       error: getting status of '/private/tmp/nix-build-builder.pl.drv-0/build': Permission denied

Error on home-manager switch:

       … while realising the context of path '/nix/store/v2m51qlv1l2ipahav76bj4j20j946qdh-default-conf.json'

       … while setting up the build environment

       error: getting status of '/private/tmp/nix-build-default-conf.json.drv-0/build': Permission denied

Expected behavior

No errors. I'm unable to use any nix commands which trigger a build

nix-env --version output

nix-env (Nix) 2.23.1

Additional context

The culprit seems to be: 20ac781.
My nix config: https://github.com/utkarshgupta137/nix-config/
P.S. I've enabled nix.settings.sandbox

Priorities

Add 👍 to issues you find important.

@utkarshgupta137
Copy link
Author

utkarshgupta137 commented Jul 1, 2024

Found a fix:

  • cd /etc/nix
  • sudo mv nix.conf nix.conf1
  • sudo cp nix.conf1 nix.conf
  • sudo vi nix.conf => change sandbox = true to sandbox = false
  • sudo launchctl unload /Library/LaunchDaemons/org.nixos.nix-daemon.plist
  • sudo launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
  • sudo rm nix.conf
  • sudo mv nix.conf1 nix.conf

Basically, these are the steps to manually change nix.conf & reload nix-daemon. We also need to undo changes to nix.conf, so that darwin-rebuild can update them.
I would recommend changing your conf to set nix.settings.sandbox to false, until this is fixed.
Alternatively, if your user is a trusted-user, you can do darwin-rebuild switch --option sandbox false.

Leaving it open till sandbox option is fixed on darwin.

@utkarshgupta137 utkarshgupta137 changed the title nix broken on darwin after patch for GHSA-q82p-44mg-mgh5 [2.23.1] nix sandbox broken on darwin Jul 1, 2024
@emilazy
Copy link
Member

emilazy commented Jul 1, 2024

Seeing this on 2.18.4 too; seems like it must be caused by the recent Linux security fix: 2.18.3...2.18.4. Ironically this regresses the sandboxing on Darwin.

@emilazy
Copy link
Member

emilazy commented Jul 1, 2024

I believe relaxing the read permissions on the build parent directory, at least on macOS, would address this.

Edit: Although actually I have no idea why the sandbox would affect things in that case. I’ll have to dig into this more another day.

Edit edit: Oh, it’s because useChroot logic is followed even though the macOS sandbox doesn’t use chroot.

@emilazy
Copy link
Member

emilazy commented Jul 1, 2024

I will try to fix this tomorrow.

Eliot00 added a commit to Eliot00/NixOSConfig that referenced this issue Jul 2, 2024
@uncenter
Copy link
Member

uncenter commented Jul 2, 2024

Found a fix:

Thank you @utkarshgupta137! Worked flawlessly for me, disabled sandboxing right away!

@roberth roberth added macos Nix on macOS, aka OS X, aka darwin regression Something doesn't work anymore labels Jul 3, 2024
@roberth roberth closed this as completed in af2e114 Jul 5, 2024
github-actions bot pushed a commit that referenced this issue Jul 5, 2024
The recent fix for CVE-2024-38531 broke the sandbox on macOS
completely. As it’s not practical to use `chroot(2)` on
macOS, the build takes place in the main filesystem tree, and the
world‐unreadable wrapper directory prevents the build from accessing
its `$TMPDIR` at all.

The macOS sandbox probably shouldn’t be treated as any kind of a
security boundary in its current state, but this specific vulnerability
wasn’t possible to exploit on macOS anyway, as creating `set{u,g}id`
binaries is blocked by sandbox policy.

Locking down the build sandbox further may be a good idea in future,
but it already has significant compatibility issues. For now, restore
the previous status quo on macOS.

Thanks to @alois31 for helping me come to a better understanding of
the vulnerability.

Fixes: 1d3696f
Closes: #11002
(cherry picked from commit af2e114)
github-actions bot pushed a commit that referenced this issue Jul 5, 2024
The recent fix for CVE-2024-38531 broke the sandbox on macOS
completely. As it’s not practical to use `chroot(2)` on
macOS, the build takes place in the main filesystem tree, and the
world‐unreadable wrapper directory prevents the build from accessing
its `$TMPDIR` at all.

The macOS sandbox probably shouldn’t be treated as any kind of a
security boundary in its current state, but this specific vulnerability
wasn’t possible to exploit on macOS anyway, as creating `set{u,g}id`
binaries is blocked by sandbox policy.

Locking down the build sandbox further may be a good idea in future,
but it already has significant compatibility issues. For now, restore
the previous status quo on macOS.

Thanks to @alois31 for helping me come to a better understanding of
the vulnerability.

Fixes: 1d3696f
Closes: #11002
(cherry picked from commit af2e114)
roberth pushed a commit that referenced this issue Jul 5, 2024
The recent fix for CVE-2024-38531 broke the sandbox on macOS
completely. As it’s not practical to use `chroot(2)` on
macOS, the build takes place in the main filesystem tree, and the
world‐unreadable wrapper directory prevents the build from accessing
its `$TMPDIR` at all.

The macOS sandbox probably shouldn’t be treated as any kind of a
security boundary in its current state, but this specific vulnerability
wasn’t possible to exploit on macOS anyway, as creating `set{u,g}id`
binaries is blocked by sandbox policy.

Locking down the build sandbox further may be a good idea in future,
but it already has significant compatibility issues. For now, restore
the previous status quo on macOS.

Thanks to @alois31 for helping me come to a better understanding of
the vulnerability.

Fixes: 1d3696f
Closes: #11002
(cherry picked from commit af2e114)
github-actions bot pushed a commit that referenced this issue Jul 5, 2024
The recent fix for CVE-2024-38531 broke the sandbox on macOS
completely. As it’s not practical to use `chroot(2)` on
macOS, the build takes place in the main filesystem tree, and the
world‐unreadable wrapper directory prevents the build from accessing
its `$TMPDIR` at all.

The macOS sandbox probably shouldn’t be treated as any kind of a
security boundary in its current state, but this specific vulnerability
wasn’t possible to exploit on macOS anyway, as creating `set{u,g}id`
binaries is blocked by sandbox policy.

Locking down the build sandbox further may be a good idea in future,
but it already has significant compatibility issues. For now, restore
the previous status quo on macOS.

Thanks to @alois31 for helping me come to a better understanding of
the vulnerability.

Fixes: 1d3696f
Closes: #11002
(cherry picked from commit af2e114)
(cherry picked from commit 9feee13)
github-actions bot pushed a commit that referenced this issue Jul 5, 2024
The recent fix for CVE-2024-38531 broke the sandbox on macOS
completely. As it’s not practical to use `chroot(2)` on
macOS, the build takes place in the main filesystem tree, and the
world‐unreadable wrapper directory prevents the build from accessing
its `$TMPDIR` at all.

The macOS sandbox probably shouldn’t be treated as any kind of a
security boundary in its current state, but this specific vulnerability
wasn’t possible to exploit on macOS anyway, as creating `set{u,g}id`
binaries is blocked by sandbox policy.

Locking down the build sandbox further may be a good idea in future,
but it already has significant compatibility issues. For now, restore
the previous status quo on macOS.

Thanks to @alois31 for helping me come to a better understanding of
the vulnerability.

Fixes: 1d3696f
Closes: #11002
(cherry picked from commit af2e114)
(cherry picked from commit 9feee13)
github-actions bot pushed a commit that referenced this issue Jul 5, 2024
The recent fix for CVE-2024-38531 broke the sandbox on macOS
completely. As it’s not practical to use `chroot(2)` on
macOS, the build takes place in the main filesystem tree, and the
world‐unreadable wrapper directory prevents the build from accessing
its `$TMPDIR` at all.

The macOS sandbox probably shouldn’t be treated as any kind of a
security boundary in its current state, but this specific vulnerability
wasn’t possible to exploit on macOS anyway, as creating `set{u,g}id`
binaries is blocked by sandbox policy.

Locking down the build sandbox further may be a good idea in future,
but it already has significant compatibility issues. For now, restore
the previous status quo on macOS.

Thanks to @alois31 for helping me come to a better understanding of
the vulnerability.

Fixes: 1d3696f
Closes: #11002
(cherry picked from commit af2e114)
(cherry picked from commit 9feee13)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug macos Nix on macOS, aka OS X, aka darwin regression Something doesn't work anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants