Skip to content

Commit

Permalink
Use sandbox fallback when cloning fails in builder
Browse files Browse the repository at this point in the history
When sandbox-fallback = true (the default), the Nix builder will fall
back to disabled sandbox mode when the kernel doesn’t allow users to
set it up. This prevents hard errors from occuring in tricky places,
especially the initial installer. To restore the previous behavior,
users can set:

  sandbox-fallback = false

in their /etc/nix/nix.conf configuration.
  • Loading branch information
matthewbauer committed Jul 25, 2019
1 parent d171090 commit 11d8534
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2316,13 +2316,22 @@ void DerivationGoal::startBuilder()
flags &= ~CLONE_NEWUSER;
child = clone(childEntry, stack + stackSize, flags, this);
}
/* Otherwise exit with EPERM so we can handle this in the
parent. This is only done when sandbox-fallback is set
to true (the default). */
if (child == -1 && (errno == EPERM || errno == EINVAL) && settings.sandboxFallback)
_exit(EPERM);
if (child == -1) throw SysError("cloning builder process");

writeFull(builderOut.writeSide.get(), std::to_string(child) + "\n");
_exit(0);
}, options);

if (helper.wait() != 0)
int res = helper.wait();
if (res == EPERM && settings.sandboxFallback) {
useChroot = false;
goto fallback;
} else if (res != 0)
throw Error("unable to start build process");

userNamespaceSync.readSide = -1;
Expand Down Expand Up @@ -2353,6 +2362,7 @@ void DerivationGoal::startBuilder()
} else
#endif
{
fallback:
options.allowVfork = !buildUser && !drv->isBuiltin();
pid = startProcess([&]() {
runChild();
Expand Down
3 changes: 3 additions & 0 deletions src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ public:
"The paths to make available inside the build sandbox.",
{"build-chroot-dirs", "build-sandbox-paths"}};

Setting<bool> sandboxFallback{this, true, "sandbox-fallback",
"Whether to disable sandboxing when the kernel doesn't allow it."};

Setting<PathSet> extraSandboxPaths{this, {}, "extra-sandbox-paths",
"Additional paths to make available inside the build sandbox.",
{"build-extra-chroot-dirs", "build-extra-sandbox-paths"}};
Expand Down

0 comments on commit 11d8534

Please sign in to comment.