eBPF-based security platform
ci: Build libtpms from source for the functional TPM tests
Tobias Klauser60f15320d982
diff --git a/.github/scripts/install-libtpms.sh b/.github/scripts/install-libtpms.shnew file mode 100755index 00000000..aed53f5e--- /dev/null+++ b/.github/scripts/install-libtpms.sh@@ -0,0 +1,72 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# .github/scripts/install-libtpms.sh -- build the libtpms the host-side TPM+# simulator (testing/helper/tpmsim-cmd, used only by the functional TPM+# tests) links, at a commit newer than any distribution package. Ubuntu+# noble's 0.9.3 null-derefs inside NvReadRamIndexAttributes() when an+# orderly NV index's RAM entry goes missing across a save/restore cycle,+# which this test's tpm_open()/tpm_close()-per-cycle usage can trigger+# under load; fixed upstream by+# a0f832aaa50d52bf9a4f3cfd30e76573c1561d5b ("tpm2: Check orderly RAM+# entries against NV indices on state load"), not yet in a tagged+# release. Bump LIBTPMS_COMMIT and LIBTPMS_SHA256 together once one+# exists.+#+# .github/scripts/install-libtpms.sh <cache-dir> [<install-prefix>]+#+# <cache-dir> is where the build is kept for the caller's own cache+# action, restored and saved around this script so a pinned commit is+# built once and reused across runs; it is rebuilt only when missing or+# when LIBTPMS_COMMIT changes (the caller keys its cache on this script's+# hash). <install-prefix>, if different from <cache-dir>, is where the+# build is actually used from, for a caller running inside a VM whose+# host mount is slower than its own disk; it defaults to <cache-dir>.+# Runs as root in a runner or LVH guest that is discarded afterwards.++set -eu++LIBTPMS_COMMIT=165c303ccc4784fb3d8cadbb3d71205641ba380b+LIBTPMS_SHA256=b5b4917ab5f9360377a93f74b406fbc2e5ee0a1a0b6d18018762793d03f48741++cache=$1+prefix=${2:-$1}++if [ -s "$cache/lib/libtpms.so" ]; then+ if [ "$prefix" != "$cache" ]; then+ rm -rf "$prefix"+ cp -a "$cache" "$prefix"+ fi+ exit 0+fi++apt-get update+apt-get install -y --no-install-recommends \+ autoconf \+ autoconf-archive \+ automake \+ build-essential \+ ca-certificates \+ curl \+ libssl-dev \+ libtool \+ pkg-config++rm -rf "$prefix" "/tmp/libtpms-$LIBTPMS_COMMIT"+tarball="libtpms-$LIBTPMS_COMMIT.tar.gz"+curl -fsSL --retry 3 -o "/tmp/$tarball" \+ "https://github.com/stefanberger/libtpms/archive/$LIBTPMS_COMMIT.tar.gz"+printf '%s /tmp/%s\n' "$LIBTPMS_SHA256" "$tarball" | sha256sum -c --quiet+tar -C /tmp -xf "/tmp/$tarball"+cd "/tmp/libtpms-$LIBTPMS_COMMIT"+./autogen.sh+./configure --prefix="$prefix" --with-tpm2 --with-openssl+make -j"$(nproc)"+make install++if [ "$prefix" != "$cache" ]; then+ rm -rf "$cache"+ mkdir -p "$(dirname "$cache")"+ cp -a "$prefix" "$cache"+fidiff --git a/.github/scripts/vm-toolchain.sh b/.github/scripts/vm-toolchain.shindex 7479d308..cc383491 100755--- a/.github/scripts/vm-toolchain.sh+++ b/.github/scripts/vm-toolchain.sh@@ -5,10 +5,12 @@# .github/scripts/vm-toolchain.sh -- prepare the LVH guest a workflow builds# in, or the runner itself: check that the kernel the BPF objects are# built for takes signed BPF, install clang 23 with install-clang.sh and the-# build dependencies, and build or reuse an OpenSSL 3.5 toolchain, since the-# distribution's predates ML-DSA. The-# environment the build then needs is written to build/vm-toolchain.env-# for the caller to source.+# build dependencies, build or reuse an OpenSSL 3.5 toolchain since the+# distribution's predates ML-DSA, and build or reuse a libtpms with+# install-libtpms.sh since the distribution's segfaults under the+# functional TPM tests' load (see that script for why). The environment+# the build then needs is written to build/vm-toolchain.env for the+# caller to source.## .github/scripts/vm-toolchain.sh [<apt package>...]#@@ -27,6 +29,7 @@ OPENSSL_SHA256=603f5602e2eef00d77fbd429d34dcd5822bb301757a1bc9cdb24c670f1eb859aroot=$(cd "$(dirname "$0")/../.." && pwd)OPENSSL_PREFIX=$root/build/host-opensslOPENSSL_STAMP=$OPENSSL_PREFIX/.shirudo-openssl-built+LIBTPMS_PREFIX=$root/build/host-libtpmsopenssl_ready() {[ -f "$OPENSSL_STAMP" ] &&@@ -62,7 +65,6 @@ apt-get install -y --no-install-recommends \libcurl4-openssl-dev \libelf-dev \libluajit-5.1-dev \- libtpms-dev \libtss2-dev \zlib1g-dev \"$@"@@ -91,9 +93,11 @@ elseecho "using cached OpenSSL $OPENSSL_VERSION from $OPENSSL_PREFIX"fi+sh "$root/.github/scripts/install-libtpms.sh" "$LIBTPMS_PREFIX"+mkdir -p buildcat >build/vm-toolchain.env <<EOTexport PATH=$OPENSSL_PREFIX/bin:\$PATH-export PKG_CONFIG_PATH=$OPENSSL_PREFIX/lib/pkgconfig-export LD_LIBRARY_PATH=$OPENSSL_PREFIX/lib+export PKG_CONFIG_PATH=$OPENSSL_PREFIX/lib/pkgconfig:$LIBTPMS_PREFIX/lib/pkgconfig+export LD_LIBRARY_PATH=$OPENSSL_PREFIX/lib:$LIBTPMS_PREFIX/libEOTdiff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 01b42745..eed73a0a 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -84,6 +84,13 @@ jobs:path: build/host-opensslkey: host-openssl-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/scripts/vm-toolchain.sh') }}+ - name: Restore the host libtpms toolchain+ id: host-libtpms+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: build/host-libtpms+ key: host-libtpms-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/scripts/vm-toolchain.sh', '.github/scripts/install-libtpms.sh') }}+- name: Restore the VM imagesif: matrix.vm == '1'id: images@@ -158,6 +165,13 @@ jobs:path: build/host-opensslkey: ${{ steps.host-openssl.outputs.cache-primary-key }}+ - name: Save the host libtpms toolchain+ if: always() && steps.host-libtpms.outputs.cache-hit != 'true' && hashFiles('build/host-libtpms/lib/libtpms.so') != ''+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0+ with:+ path: build/host-libtpms+ key: ${{ steps.host-libtpms.outputs.cache-primary-key }}+# hashFiles reads every byte it matches and gives up after two# minutes, too short for an image; the key file beside one is# written once the image is complete.