Skip to content

Commit 3c57db1

Browse files
authored
Merge pull request #6710 from edolstra/embedded-sandbox-shell
Embed the sandbox shell into the statically linked 'nix' binary
2 parents 0b2ea00 + 925b975 commit 3c57db1

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

Makefile.config.in

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
HOST_OS = @host_os@
21
AR = @AR@
32
BDW_GC_LIBS = @BDW_GC_LIBS@
43
BOOST_LDFLAGS = @BOOST_LDFLAGS@
@@ -13,13 +12,14 @@ ENABLE_S3 = @ENABLE_S3@
1312
GTEST_LIBS = @GTEST_LIBS@
1413
HAVE_LIBCPUID = @HAVE_LIBCPUID@
1514
HAVE_SECCOMP = @HAVE_SECCOMP@
15+
HOST_OS = @host_os@
1616
LDFLAGS = @LDFLAGS@
1717
LIBARCHIVE_LIBS = @LIBARCHIVE_LIBS@
1818
LIBBROTLI_LIBS = @LIBBROTLI_LIBS@
1919
LIBCURL_LIBS = @LIBCURL_LIBS@
20+
LIBSECCOMP_LIBS = @LIBSECCOMP_LIBS@
2021
LOWDOWN_LIBS = @LOWDOWN_LIBS@
2122
OPENSSL_LIBS = @OPENSSL_LIBS@
22-
LIBSECCOMP_LIBS = @LIBSECCOMP_LIBS@
2323
PACKAGE_NAME = @PACKAGE_NAME@
2424
PACKAGE_VERSION = @PACKAGE_VERSION@
2525
SHELL = @bash@
@@ -31,6 +31,7 @@ datadir = @datadir@
3131
datarootdir = @datarootdir@
3232
doc_generate = @doc_generate@
3333
docdir = @docdir@
34+
embedded_sandbox_shell = @embedded_sandbox_shell@
3435
exec_prefix = @exec_prefix@
3536
includedir = @includedir@
3637
libdir = @libdir@

configure.ac

+8
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ if test ${cross_compiling:-no} = no && ! test -z ${sandbox_shell+x}; then
320320
fi
321321
fi
322322

323+
AC_ARG_ENABLE(embedded-sandbox-shell, AS_HELP_STRING([--enable-embedded-sandbox-shell],[include the sandbox shell in the Nix binary [default=no]]),
324+
embedded_sandbox_shell=$enableval, embedded_sandbox_shell=no)
325+
AC_SUBST(embedded_sandbox_shell)
326+
if test "$embedded_sandbox_shell" = yes; then
327+
AC_DEFINE(HAVE_EMBEDDED_SANDBOX_SHELL, 1, [Include the sandbox shell in the Nix binary.])
328+
fi
329+
330+
323331
# Expand all variables in config.status.
324332
test "$prefix" = NONE && prefix=$ac_default_prefix
325333
test "$exec_prefix" = NONE && exec_prefix='${prefix}'

flake.nix

+5-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,11 @@
578578
doInstallCheck=1
579579
'';
580580

581-
configureFlags = [ "--sysconfdir=/etc" ];
581+
configureFlags =
582+
configureFlags ++
583+
[ "--sysconfdir=/etc"
584+
"--enable-embedded-sandbox-shell"
585+
];
582586

583587
enableParallelBuilding = true;
584588

src/libstore/build/local-derivation-goal.cc

+13-1
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,19 @@ void LocalDerivationGoal::runChild()
17171717

17181718
for (auto & i : dirsInChroot) {
17191719
if (i.second.source == "/proc") continue; // backwards compatibility
1720-
doBind(i.second.source, chrootRootDir + i.first, i.second.optional);
1720+
1721+
#if HAVE_EMBEDDED_SANDBOX_SHELL
1722+
if (i.second.source == "__embedded_sandbox_shell__") {
1723+
static unsigned char sh[] = {
1724+
#include "embedded-sandbox-shell.gen.hh"
1725+
};
1726+
auto dst = chrootRootDir + i.first;
1727+
createDirs(dirOf(dst));
1728+
writeFile(dst, std::string_view((const char *) sh, sizeof(sh)));
1729+
chmod_(dst, 0555);
1730+
} else
1731+
#endif
1732+
doBind(i.second.source, chrootRootDir + i.first, i.second.optional);
17211733
}
17221734

17231735
/* Bind a new instance of procfs on /proc. */

src/libstore/local.mk

+10
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,19 @@ libstore_CXXFLAGS += \
4343
-DNIX_MAN_DIR=\"$(mandir)\" \
4444
-DLSOF=\"$(lsof)\"
4545

46+
ifeq ($(embedded_sandbox_shell),yes)
47+
libstore_CXXFLAGS += -DSANDBOX_SHELL=\"__embedded_sandbox_shell__\"
48+
49+
$(d)/build/local-derivation-goal.cc: $(d)/embedded-sandbox-shell.gen.hh
50+
51+
$(d)/embedded-sandbox-shell.gen.hh: $(sandbox_shell)
52+
$(trace-gen) hexdump -v -e '1/1 "0x%x," "\n"' < $< > $@.tmp
53+
@mv $@.tmp $@
54+
else
4655
ifneq ($(sandbox_shell),)
4756
libstore_CXXFLAGS += -DSANDBOX_SHELL="\"$(sandbox_shell)\""
4857
endif
58+
endif
4959

5060
$(d)/local-store.cc: $(d)/schema.sql.gen.hh $(d)/ca-specific-schema.sql.gen.hh
5161

0 commit comments

Comments
 (0)