diff options
author | Matthew Bauer <mjbauer95@gmail.com> | 2019-07-25T13·37-0400 |
---|---|---|
committer | Matthew Bauer <mjbauer95@gmail.com> | 2019-07-25T18·42-0400 |
commit | d171090530f4a2a79efec2c385bee1a10844c706 (patch) | |
tree | 709ddf2bd276cb5cea94b7a4088547b37ec67c76 /src/libstore | |
parent | b640f69a4d33eb3833cf0ac3000d189dacbd0f5a (diff) |
Disable CLONE_NEWUSER when it’s unavailable
Some kernels disable "unpriveleged user namespaces". This is unfortunate, but we can still use mount namespaces. Anyway, since each builder has its own nixbld user, we already have most of the benefits of user namespaces.
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/build.cc | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index cf6428e12467..c10005839bf7 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -2302,10 +2302,20 @@ void DerivationGoal::startBuilder() flags |= CLONE_NEWNET; pid_t child = clone(childEntry, stack + stackSize, flags, this); - if (child == -1 && errno == EINVAL) + if (child == -1 && errno == EINVAL) { /* Fallback for Linux < 2.13 where CLONE_NEWPID and CLONE_PARENT are not allowed together. */ - child = clone(childEntry, stack + stackSize, flags & ~CLONE_NEWPID, this); + flags &= ~CLONE_NEWPID; + child = clone(childEntry, stack + stackSize, flags, this); + } + if (child == -1 && (errno == EPERM || errno == EINVAL)) { + /* Some distros patch Linux to not allow unpriveleged + * user namespaces. If we get EPERM or EINVAL, try + * without CLONE_NEWUSER and see if that works. + */ + flags &= ~CLONE_NEWUSER; + child = clone(childEntry, stack + stackSize, flags, this); + } if (child == -1) throw SysError("cloning builder process"); writeFull(builderOut.writeSide.get(), std::to_string(child) + "\n"); |