summaryrefslogtreecommitdiff
path: root/nix/nix-daemon
diff options
context:
space:
mode:
authorReepca Russelstein <reepca@russelstein.xyz>2025-04-18 01:35:31 -0500
committerJohn Kehayias <john.kehayias@protonmail.com>2025-06-24 10:07:57 -0400
commitfb42611b8f27960304db5a1c0d33b8371dcde2a8 (patch)
treee4331b4b340c3304684914044d543ecd0e653fb7 /nix/nix-daemon
parentbe8aca065118aa4485c02f991c51bea89034defa (diff)
daemon: Use slirp4netns to provide networking to fixed-output derivations.
Previously, the builder of a fixed-output derivation could communicate with an external process via an abstract Unix-domain socket. In particular, it could send an open file descriptor to the store, granting write access to some of its output files in the store provided the derivation build fails—the fix for CVE-2024-27297 did not address this specific case. It could also send an open file descriptor to a setuid program, which could then be executed using execveat to gain the privileges of the build user. With this change, fixed-output derivations other than “builtin:download” and “builtin:git-download” always run in a separate network namespace and have network access provided by a TAP device backed by slirp4netns, thereby closing the abstract Unix-domain socket channel. * nix/libstore/globals.hh (Settings)[useHostLoopback, slirp4netns]: new fields. * config-daemon.ac (SLIRP4NETNS): new C preprocessor definition. * nix/libstore/globals.cc (Settings::Settings): initialize them to defaults. * nix/nix-daemon/guix-daemon.cc (options): add --isolate-host-loopback option. * doc/guix.texi: document it. * nix/libstore/build.cc (DerivationGoal)[slirp]: New field. (setupTap, setupTapAction, waitForSlirpReadyAction, enableRouteLocalnetAction, prepareSlirpChrootAction, spawnSlirp4netns, haveGlobalIPv6Address, remapIdsTo0Action): New functions. (initializeUserNamespace): allow the guest UID and GID to be specified. (DerivationGoal::killChild): When ‘slirp’ is not -1, call ‘kill’. (DerivationGoal::startBuilder): Unconditionally add CLONE_NEWNET to FLAGS. When ‘fixedOutput’ is true, spawn ‘slirp4netns’. When ‘fixedOutput’ and ‘useChroot’ are true, add setupTapAction, waitForSlirpReadyAction, and enableRouteLocalnetAction to builder setup phases. Create a /etc/resolv.conf for fixed-output derivations that directs them to slirp4netns's dns address. When settings.useHostLoopback is true, supply fixed-output derivations with a /etc/hosts that resolves "localhost" to slirp4netns's address for accessing the host loopback. * nix/libutil/util.cc (keepOnExec, decodeOctalEscaped, sendFD, receiveFD, findProgram): New functions. * nix/libutil/util.hh (keepOnExec, decodeOctalEscaped, sendFD, receiveFD, findProgram): New declarations. * gnu/packages/package-management.scm (guix): add slirp4netns input for linux targets. * tests/derivations.scm (builder-network-isolated?): new variable. ("fixed-output derivation, network access, localhost", "fixed-output derivation, network access, external host"): skip test case if fixed output derivations are isolated from the network. Change-Id: Ia3fea2ab7add56df66800071cf15cdafe7bfab96 Signed-off-by: John Kehayias <john.kehayias@protonmail.com>
Diffstat (limited to 'nix/nix-daemon')
-rw-r--r--nix/nix-daemon/guix-daemon.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index d7ab9c5e649..30727d55593 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -90,6 +90,7 @@ builds derivations on behalf of its clients.");
90#define GUIX_OPT_MAX_SILENT_TIME 19 90#define GUIX_OPT_MAX_SILENT_TIME 19
91#define GUIX_OPT_LOG_COMPRESSION 20 91#define GUIX_OPT_LOG_COMPRESSION 20
92#define GUIX_OPT_DISCOVER 21 92#define GUIX_OPT_DISCOVER 21
93#define GUIX_OPT_ISOLATE_HOST_LOOPBACK 22
93 94
94static const struct argp_option options[] = 95static const struct argp_option options[] =
95 { 96 {
@@ -160,6 +161,8 @@ to live outputs") },
160 n_("listen for connections on SOCKET") }, 161 n_("listen for connections on SOCKET") },
161 { "debug", GUIX_OPT_DEBUG, 0, 0, 162 { "debug", GUIX_OPT_DEBUG, 0, 0,
162 n_("produce debugging output") }, 163 n_("produce debugging output") },
164 { "isolate-host-loopback", GUIX_OPT_ISOLATE_HOST_LOOPBACK, 0, 0,
165 n_("do not allow fixed-output chroot builds to access the host loopback") },
163 { 0, 0, 0, 0, 0 } 166 { 0, 0, 0, 0, 0 }
164 }; 167 };
165 168
@@ -294,6 +297,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
294 case GUIX_OPT_SYSTEM: 297 case GUIX_OPT_SYSTEM:
295 settings.thisSystem = arg; 298 settings.thisSystem = arg;
296 break; 299 break;
300 case GUIX_OPT_ISOLATE_HOST_LOOPBACK:
301 settings.useHostLoopback = false;
302 break;
297 default: 303 default:
298 return (error_t) ARGP_ERR_UNKNOWN; 304 return (error_t) ARGP_ERR_UNKNOWN;
299 } 305 }