eBPF-based security platform
quote-check: link the checker as a static PIE
John Fastabend3d1ee783261e
diff --git a/.github/scripts/build-debian.sh b/.github/scripts/build-debian.shindex 463b67dd..4312142d 100755--- a/.github/scripts/build-debian.sh+++ b/.github/scripts/build-debian.sh@@ -44,6 +44,7 @@ apt-get install -y --no-install-recommends \libtss2-dev \zlib1g-devsh .github/scripts/install-clang.sh+sh .github/scripts/install-static-libcrypto-deps.shgit config --global --add safe.directory "$PWD"uname -m@@ -55,5 +56,6 @@ make shirudo-buildmake quote-checkmake -C testing unitsh .github/scripts/check-operator-linkage.sh shirudo \- tools/shirudo-build/shirudo-build \+ tools/shirudo-build/shirudo-build+sh .github/scripts/check-static-target.sh \tools/quote-check/shirudo-quote-checkdiff --git a/.github/scripts/install-static-libcrypto-deps.sh b/.github/scripts/install-static-libcrypto-deps.shnew file mode 100755index 00000000..62bf0ed4--- /dev/null+++ b/.github/scripts/install-static-libcrypto-deps.sh@@ -0,0 +1,55 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# .github/scripts/install-static-libcrypto-deps.sh -- install the static+# archives shirudo-quote-check links beside libcrypto.a. Which ones depends+# on how the libcrypto in use was built, so the list is read from+# "pkg-config --static --libs libcrypto" and not kept here: a+# distribution's OpenSSL may name zlib, zstd and a jitter entropy source,+# one built from source names none of them.+#+# .github/scripts/install-static-libcrypto-deps.sh+#+# Run as root on Debian or Ubuntu, after libssl-dev and pkg-config are+# installed and with the PKG_CONFIG_PATH the build will use.++set -eu++libs=$(pkg-config --static --libs libcrypto)++# The first of the named packages the distribution has.+first_available() {+ for pkg; do+ if apt-cache show "$pkg" >/dev/null 2>&1; then+ printf '%s\n' "$pkg"+ return 0+ fi+ done+ printf 'install-static-libcrypto-deps: none of %s is available\n' "$*" >&2+ return 1+}++pkgs=libc6-dev+for lib in $libs; do+ case $lib in+ -lz)+ pkgs="$pkgs zlib1g-dev"+ ;;+ -lzstd)+ pkgs="$pkgs libzstd-dev"+ ;;+ -ljitterentropy|-l:libjitterentropy.a)+ pkgs="$pkgs $(first_available libjitterentropy3-dev libjitterentropy-dev)"+ ;;+ -lcrypto|-ldl|-lpthread|-pthread|-latomic|-L*)+ ;;+ *)+ printf 'install-static-libcrypto-deps: no package known for %s\n' "$lib" >&2+ exit 1+ ;;+ esac+done++# shellcheck disable=SC2086+apt-get install -y --no-install-recommends $pkgsdiff --git a/.github/scripts/lvh-prepare.sh b/.github/scripts/lvh-prepare.shindex 572402f2..d056a810 100644--- a/.github/scripts/lvh-prepare.sh+++ b/.github/scripts/lvh-prepare.sh@@ -49,5 +49,7 @@ apt-get install -y --no-install-recommends \jq \git+sh .github/scripts/install-static-libcrypto-deps.sh+git config --global --add safe.directory /hostsh .github/scripts/lvh-target-deps.shdiff --git a/.github/scripts/vm-toolchain.sh b/.github/scripts/vm-toolchain.shindex cc383491..a0845ada 100755--- a/.github/scripts/vm-toolchain.sh+++ b/.github/scripts/vm-toolchain.sh@@ -35,6 +35,7 @@ openssl_ready() {[ -f "$OPENSSL_STAMP" ] &&[ -x "$OPENSSL_PREFIX/bin/openssl" ] &&[ -s "$OPENSSL_PREFIX/lib/libcrypto.so.3" ] &&+ [ -s "$OPENSSL_PREFIX/lib/libcrypto.a" ] &&[ -s "$OPENSSL_PREFIX/lib/libssl.so.3" ] || return 1version=$(LD_LIBRARY_PATH="$OPENSSL_PREFIX/lib" \diff --git a/.github/workflows/build.yml b/.github/workflows/build.ymlindex 67e9c349..3206f0e9 100644--- a/.github/workflows/build.yml+++ b/.github/workflows/build.yml@@ -56,7 +56,8 @@ jobs:make -C testing CC=${{ matrix.cc }} test-helpersmake -C testing CC=${{ matrix.cc }} unitsh .github/scripts/check-operator-linkage.sh shirudo \- tools/shirudo-build/shirudo-build \+ tools/shirudo-build/shirudo-build+ sh .github/scripts/check-static-target.sh \tools/quote-check/shirudo-quote-checkbtf:diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.ymlindex 84c653ed..26066f7c 100644--- a/.github/workflows/packages.yml+++ b/.github/workflows/packages.yml@@ -121,7 +121,8 @@ jobs:apt-get install -y /host/shirudo-operator_*.debsh .github/scripts/check-operator-linkage.sh /usr/bin/shirudo \- /usr/libexec/shirudo/shirudo-build \+ /usr/libexec/shirudo/shirudo-build+ sh .github/scripts/check-static-target.sh \/usr/bin/shirudo-quote-check/usr/bin/shirudo genkey@@ -384,7 +385,8 @@ jobs:rpm -q shirudo-operator clangrpm -qV shirudo-operatorsh .github/scripts/check-operator-linkage.sh /usr/bin/shirudo \- /usr/libexec/shirudo/shirudo-build \+ /usr/libexec/shirudo/shirudo-build+ sh .github/scripts/check-static-target.sh \/usr/bin/shirudo-quote-checkshirudo genkeyrm -rf /tmp/shirudo-smoke && mkdir -p /tmp/shirudo-smokediff --git a/AGENTS.md b/AGENTS.mdindex f63940a2..ce064e0e 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -318,7 +318,8 @@ one usually still compiles and passes tests.## Building, testing, packaging- `make` builds the operator binary, `make shirudo-build` the helper,- `make quote-check` the backend's quote checker `shirudo-quote-check`+ `make quote-check` the backend's quote checker `shirudo-quote-check`,+ a static PIE in either profile,and `make target` the fully static PIE target profile (`make target-deps`builds OpenSSL, libcurl and tpm2-tss from source first). A checkoutused in place of an installed operator package names the helper withdiff --git a/Documentation/contribute/code/developer-guide.rst b/Documentation/contribute/code/developer-guide.rstindex fd7ea035..c656b5eb 100644--- a/Documentation/contribute/code/developer-guide.rst+++ b/Documentation/contribute/code/developer-guide.rst@@ -314,8 +314,16 @@ Other make targetstimers, the dracut module and ``shirudo-gen-initrd``.* - ``make quote-check``- Builds ``tools/quote-check/shirudo-quote-check``, the program a- telemetry backend runs on keepalive quotes. See- :doc:`/reference/cli/quote-check`.+ telemetry backend runs on keepalive quotes, as a static PIE in+ either profile. The link needs the static archives of the C+ library and of ``libcrypto`` with those+ ``pkg-config --static --libs libcrypto`` names: on Ubuntu 26.04,+ ``libzstd-dev`` and ``libjitterentropy3-dev`` beside+ ``libssl-dev`` and ``zlib1g-dev``. CI installs them with+ :src:`.github/scripts/install-static-libcrypto-deps.sh`, which+ reads that list. A ``SANITIZE=`` build links it+ against the shared libraries, because the sanitizer runtimes do+ not link statically. See :doc:`/reference/cli/quote-check`.* - ``make install-operator``- Installs the operator binary, the helper under``$(libexecdir)/shirudo``, ``shirudo-quote-check``, the imagediff --git a/Documentation/reference/cli/quote-check.rst b/Documentation/reference/cli/quote-check.rstindex b93010f8..9c2f1a7c 100644--- a/Documentation/reference/cli/quote-check.rst+++ b/Documentation/reference/cli/quote-check.rst@@ -19,6 +19,11 @@ Runs on: a backend host, installed by the operator package askeeps no state, holds no key list and opens no connection. Changesmeasured state: no.+The program is a static PIE: it needs no shared library and no dynamic+loader, unlike the other programs of the operator package. Copy the one+file to where the backend runs it, into a database container for one,+and it runs there whatever C library and OpenSSL that system has.+Usage-----diff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rstindex f8c10223..5c472b5e 100644--- a/Documentation/reference/files.rst+++ b/Documentation/reference/files.rst@@ -64,8 +64,8 @@ Operator host* - ``$(bindir)/shirudo-quote-check``- operator package, ``make install-operator``- ``0755``- - Checks keepalive quotes for a telemetry backend. It reads standard- input alone and writes no file. See+ - Checks keepalive quotes for a telemetry backend. A static PIE.+ It reads standard input alone and writes no file. See:doc:`/reference/cli/quote-check`.* - ``/tmp/shirudo-build-XXXXXX.bpf.o``- ``build``diff --git a/Documentation/start/install.rst b/Documentation/start/install.rstindex 018d9fe6..9728f3cf 100644--- a/Documentation/start/install.rst+++ b/Documentation/start/install.rst@@ -42,8 +42,8 @@ Packages- Operator host- - ``/usr/bin/shirudo``, linked against the host's shared libraries- the helper ``/usr/libexec/shirudo/shirudo-build``- - ``/usr/bin/shirudo-quote-check``, which checks keepalive quotes- for a telemetry backend+ - ``/usr/bin/shirudo-quote-check``, a static PIE that checks+ keepalive quotes for a telemetry backend- the image generators ``shirudo-gen-image``,``shirudo-gen-runtime`` and ``shirudo-gen-verity`` under``/usr/libexec/shirudo/gen-image/``diff --git a/Makefile.shirudo b/Makefile.shirudoindex 7bb44928..3e5c1495 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -512,13 +512,25 @@ tools/shirudo-build/shirudo-build: $(BUILD_OBJS) util/sign.o util/config_image.o$(Q)$(LD) $(CFLAGS) $(HARDEN_LDFLAGS) $(LDFLAGS) $(RPATH_LDFLAGS) -o $@ $^ \$(STATIC_LIBS) $(DYNAMIC_LIBS)+# A backend runs the checker where it does not choose the libraries, as+# a function inside a database container for one, so it is a static PIE+# whatever the profile. The sanitizer runtimes do not link statically.+PKG_CONFIG ?= pkg-config+ifeq ($(SANITIZE),)+QUOTE_CHECK_LDFLAGS := $(HARDEN_STATIC_PIE_LDFLAGS) -static-pie -static-libgcc+QUOTE_CHECK_LIBS := $(shell $(PKG_CONFIG) --static --libs libcrypto 2>/dev/null)+else+QUOTE_CHECK_LDFLAGS := $(HARDEN_LDFLAGS)+QUOTE_CHECK_LIBS := $(LIBCRYPTO_LIBS)+endif+tools/quote-check/shirudo-quote-check: $(QUOTE_CHECK_OBJS) util/tpm_wire.o \util/crypto_openssl.o util/hex.o \util/json.o util/io.o util/seal.o \util/log.o util/malloc.o util/string.o@printf ' LD $@\n'- $(Q)$(LD) $(CFLAGS) $(HARDEN_LDFLAGS) $(LDFLAGS) $(RPATH_LDFLAGS) -o $@ $^ \- $(LIBCRYPTO_LIBS)+ $(Q)$(LD) $(CFLAGS) $(QUOTE_CHECK_LDFLAGS) $(LDFLAGS) -o $@ $^ \+ $(QUOTE_CHECK_LIBS)# ----- install ----------------------------------------------------diff --git a/packaging/deb/builddeb.sh b/packaging/deb/builddeb.shindex cca05d5f..efcbf158 100755--- a/packaging/deb/builddeb.sh+++ b/packaging/deb/builddeb.sh@@ -48,8 +48,7 @@ target)operator)pkg=shirudo-operatorother=shirudo-target- bins="$stage/usr/bin/shirudo $stage/usr/libexec/shirudo/shirudo-build- $stage/usr/bin/shirudo-quote-check"+ bins="$stage/usr/bin/shirudo $stage/usr/libexec/shirudo/shirudo-build"short="signed-BPF lockdown LSM platform (operator tools)";;*)