eBPF-based security platform
image: strip the target binary on the runtime image
Daniel Borkmann8faab8869b2d
diff --git a/Documentation/operate/system-requirements.rst b/Documentation/operate/system-requirements.rstindex 1f39a62d..0833eb60 100644--- a/Documentation/operate/system-requirements.rst+++ b/Documentation/operate/system-requirements.rst@@ -419,6 +419,9 @@ keyrings. Any Linux kernel on which the tools below run serves.* - ``veritysetup`` (``cryptsetup-bin`` or ``cryptsetup``),``mkfs.ext4`` (``e2fsprogs``), Bash and GNU coreutils- Building runtime and config images, and ``shirudo image verify``.+ * - ``llvm-strip`` (LLVM), ``readelf`` (binutils) and ``ldd``+ - ``shirudo-gen-runtime`` strips the target binary it puts on the+ runtime image and resolves the libraries of a dynamic one.* - ``CAP_IPC_LOCK`` or an ``RLIMIT_MEMLOCK`` large enough for theprocess- ``shirudo`` and ``shirudo-build`` lock all their memory beforediff --git a/Documentation/reference/cli/gen-tools.rst b/Documentation/reference/cli/gen-tools.rstindex 6439534a..8a0be5c8 100644--- a/Documentation/reference/cli/gen-tools.rst+++ b/Documentation/reference/cli/gen-tools.rst@@ -101,7 +101,8 @@ shirudo-gen-runtimeBuilds the runtime image, the image whose root hash the bootstrapsettings pin. It holds:-- ``usr/bin/shirudo``: ``--binary``, the target binary.+- ``usr/bin/shirudo``: ``--binary``, the target binary without its+ symbols and debug sections, as ``llvm-strip`` writes it.- ``etc/shirudo/shirudo.conf``: ``--bootstrap-conf``.- ``keys/cert.der``: ``--cert``, the initial BPF signing certificate.- ``etc/shirudo/config-cert.der``: ``--config-cert``, the certificate@@ -117,7 +118,7 @@ that clears ``EnvironmentFile=`` and ``ExecStart=`` and runs the runtimebinary with ``init``. No drop-in is written for the other units.``ldd`` runs the inputs' dynamic loader on the operator host: pass only-trusted binaries. Requires ``readelf`` and ``ldd``.+trusted binaries. Requires ``readelf``, ``ldd`` and ``llvm-strip``... list-table:::header-rows: 1diff --git a/testing/functional/image/t5001-config-image.sh b/testing/functional/image/t5001-config-image.shindex f9f93c8e..91591b16 100755--- a/testing/functional/image/t5001-config-image.sh+++ b/testing/functional/image/t5001-config-image.sh@@ -301,10 +301,15 @@ if command -v mkfs.ext4 >/dev/null 2>&1 && command -v debugfs >/dev/null 2>&1; t"$W/static-runtime.service" &&debugfs -R "dump /usr/bin/shirudo $W/extracted-static" \"$W/static-runtime.img" >/dev/null 2>&1 &&- cmp "$W/static-probe" "$W/extracted-static" &&+ llvm-strip -o "$W/static-probe.stripped" "$W/static-probe" &&+ cmp "$W/static-probe.stripped" "$W/extracted-static" &&debugfs -R "ls /" "$W/static-runtime.img" >"$W/static-root" 2>/dev/null &&! grep -Eq "(lib|lib64)" "$W/static-root"'+ test_expect_success 'the runtime image holds the binary without its symbols' '+ LC_ALL=C readelf -S "$W/static-probe" | grep -q "\.symtab" &&+ ! LC_ALL=C readelf -S "$W/extracted-static" | grep -q "\.symtab"+ 'fidiff --git a/tools/gen-image/shirudo-gen-runtime b/tools/gen-image/shirudo-gen-runtimeindex da77f63a..036a4c68 100755--- a/tools/gen-image/shirudo-gen-runtime+++ b/tools/gen-image/shirudo-gen-runtime@@ -15,8 +15,9 @@ usage: shirudo-gen-runtime --binary <shirudo-target> --bootstrap-conf <file>[--size <MiB>] [--builder <shirudo-build>] [--unit-output <file>][--extra-binary <trusted-ELF>]-Package the trusted executable, bootstrap settings and public certificates.-Static targets run directly. Dynamic executables bring their loader and libraries.+Package the trusted executable without its symbols, bootstrap settings and+public certificates. Static targets run directly. Dynamic executables bring+their loader and libraries.Use trusted inputs: ldd invokes dynamic loaders on the operator.EOF}@@ -58,6 +59,7 @@ check_inputs()check_image_options "$output" "$keys_dir" "$size"require_command readelf 'install binutils (readelf)'require_command ldd 'ldd is required on the operator'+ require_command llvm-strip 'install LLVM (llvm-strip)'LC_ALL=C readelf -h "$binary" >/dev/null || die 'target binary is not ELF'interpreter=$(elf_interpreter "$binary")if [ -n "$interpreter" ]; then@@ -69,7 +71,9 @@ check_inputs()stage_files(){mkdir -p "$work/root/usr/bin" "$work/root/etc/shirudo" "$work/root/keys"- install -m 0755 "$binary" "$work/root/usr/bin/shirudo"+ # llvm-strip, unlike binutils strip, handles a target of another architecture.+ llvm-strip -o "$work/root/usr/bin/shirudo" "$binary"+ chmod 0755 "$work/root/usr/bin/shirudo"install -m 0644 "$conf" "$work/root/etc/shirudo/shirudo.conf"install -m 0644 "$cert" "$work/root/keys/cert.der"install -m 0644 "$config_cert" "$work/root/etc/shirudo/config-cert.der"