eBPF-based security platform
testing: cover a kconfig selector the target cannot read
Daniel Borkmannc590ec7b6d5d
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 6f652273..c0c5c9fb 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -405,6 +405,9 @@ signed config image.- Re-sync and the next generation* - ``t7103-bpm-tree-delete``- A delete operation and adding the upatch back+ * - ``t7104-bpm-tree-kconfig``+ - A kconfig selector the target cannot read stops the sync where it+ is; the operation applies once the config reads``otel`` (8)~~~~~~~~~~~~@@ -603,7 +606,7 @@ Coverage by area``oci-http``, ``oci-manifest``, ``oci-ref``, ``registry-auth``* - upatch tree- ``t3011``, ``t5004``, ``t7005``, ``t7101``, ``t7102``,- ``t7103``, ``t9105``. Fuzz: ``tree``, ``tree-state``,+ ``t7103``, ``t7104``, ``t9105``. Fuzz: ``tree``, ``tree-state``,``kconfig``. Unit: ``kernel_build_id``, ``kernel_release``* - Policy labels- upatch labels and Beefile serialization: ``t3109``, ``t7006``.@@ -664,7 +667,7 @@ The threats are those of :doc:`/security/threat-model`.- ``t1006``, ``t4101``, ``t6115``, ``t6126``* - T7 The delivery path- ``t7002``, ``t7003``, ``t7005``, ``t7101``, ``t7102``,- ``t7103``, ``t8005``, ``t9105``+ ``t7103``, ``t7104``, ``t8005``, ``t9105``* - T8 Quantum-capable adversaries- ``t2001``, ``t2002``, ``t5001``, ``t8005``* - T9 A target lying about its statediff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 348a7818..4d3b621a 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -968,7 +968,7 @@ revocation does not reach tree publications (U13).kernel verifies each loader (T1):Refusal: the ``bpm`` command fails and installs nothing:Counters: none-:Tests: ``t7005``, ``t7101``, ``t7102``, ``t7103``, ``t8005``+:Tests: ``t7005``, ``t7101``, ``t7102``, ``t7103``, ``t7104``, ``t8005``:Residual: R8, R9, U3, U4, U13, U15T8 Quantum-capable adversaries against the trust anchordiff --git a/testing/functional/bpm/t7104-bpm-tree-kconfig.sh b/testing/functional/bpm/t7104-bpm-tree-kconfig.shnew file mode 100755index 00000000..e2795a12--- /dev/null+++ b/testing/functional/bpm/t7104-bpm-tree-kconfig.sh@@ -0,0 +1,133 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t7104 -- a kconfig selector the target cannot read stops the sync where+# it is; once the config reads, the operation applies.++cd "$(dirname "$0")/../.."+. ./integration-lib.sh+target_guard+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"++FIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}+REGISTRY="$FIXTURES/tree-oci"+TREE_REPO="$REGISTRY/shirudo/upatch-tree"+MATCH_PIN=/run/shirudo/bpffs/upatches/shirudo-test-tree-match/link+PROC=/proc/config.gz+CONFIG="/boot/config-$(uname -r)"+WORK=$(mktemp -d)+PROC_BOUND=0+CONFIG_BOUND=0+CONFIG_MADE=0++for fixture in \+ "$TREE_REPO/manifests/kconfig" \+ "$FIXTURES/shirudo-test-tree-match.upatch" \+ "$FIXTURES/shirudo-test-tree-match.unload.upatch" \+ "$FIXTURES/cert.der" \+ "./helper/test-oci-registry.py"+do+ [ -s "$fixture" ] || test_skip_all "missing tree fixture: $fixture"+done++[ "$(tree_state_field tree_id)" = shirudo-test-tree ] &&+ [ "$(tree_state_field last_seq)" = 5 ] ||+ test_skip_all "tree state is not where t7103 leaves it"++# What the kernel shows as its config, in /proc and in /boot, is the+# test's own file for the duration.+clear_config()+{+ [ "$PROC_BOUND" -eq 0 ] || umount "$PROC"+ PROC_BOUND=0+ [ "$CONFIG_BOUND" -eq 0 ] || umount "$CONFIG"+ CONFIG_BOUND=0+ [ "$CONFIG_MADE" -eq 0 ] || rm -f "$CONFIG"+ CONFIG_MADE=0+}++make_socket()+{+ python3 -c "+import socket, sys+socket.socket(socket.AF_UNIX).bind(sys.argv[1])+" "$1"+}++# A socket in the config's place: its open fails with ENXIO, a read+# error rather than a missing config.+show_socket()+{+ clear_config+ make_socket "$WORK/socket"+ if [ -e "$PROC" ]; then+ mount --bind "$WORK/socket" "$PROC"+ PROC_BOUND=1+ fi+ if [ -e "$CONFIG" ]; then+ mount --bind "$WORK/socket" "$CONFIG"+ CONFIG_BOUND=1+ else+ make_socket "$CONFIG"+ CONFIG_MADE=1+ fi+}++# A config the selector of operation 6 matches.+show_matching()+{+ clear_config+ printf 'CONFIG_BPF=y\n' >"$WORK/config"+ if [ -e "$PROC" ]; then+ mount --bind "$WORK/config" "$PROC"+ PROC_BOUND=1+ fi+ if [ -e "$CONFIG" ]; then+ mount --bind "$WORK/config" "$CONFIG"+ CONFIG_BOUND=1+ else+ cp "$WORK/config" "$CONFIG"+ CONFIG_MADE=1+ fi+}++cleanup()+{+ tree_registry_stop+ clear_config || true+ if [ -e "$MATCH_PIN" ]; then+ "$SHIRUDO_BIN" upatch unload \+ "$FIXTURES/shirudo-test-tree-match.unload.upatch" \+ --no-precheck >/dev/null 2>&1 || true+ fi+ tree_cleanup_config+ rm -rf "$WORK"+}+trap cleanup EXIT++tree_configure kconfig+tree_registry_start "$REGISTRY" "$WORK"+show_socket++test_expect_success 'a config that cannot be read stops the sync on the operation' '+ require_loaded shirudo-test-tree-match &&+ ! BPM_OCI_SCHEME=http "$SHIRUDO_BIN" bpm tree sync \+ --report "$WORK/stopped.json" >/dev/null 2>"$WORK/stopped.err" &&+ grep -q "phase=selector_evaluate seq=6 " "$WORK/stopped.err" &&+ [ ! -e "$WORK/stopped.json" ] &&+ [ "$(tree_state_field last_seq)" = 5 ] &&+ [ -e "$MATCH_PIN" ]+'++show_matching++test_expect_success 'the operation applies once the config can be read' '+ tree_sync "$WORK/applied.json" &&+ [ "$(report_field selected <"$WORK/applied.json")" = 1 ] &&+ [ "$(report_field applied <"$WORK/applied.json")" = 1 ] &&+ [ "$(report_field last_seq <"$WORK/applied.json")" = 6 ] &&+ [ ! -e "$MATCH_PIN" ]+'++test_donediff --git a/testing/vm/build-bundle.sh b/testing/vm/build-bundle.shindex 7c380bb1..96c1c290 100755--- a/testing/vm/build-bundle.sh+++ b/testing/vm/build-bundle.sh@@ -400,7 +400,7 @@ build_tree_test_registry()local payloads="$FIXTURE_WORK/tree-payload"local reference- # One append-only tree that t7101, t7102 and t7103 walk in order:+ # One append-only tree that t7101 to t7104 walk in order:# the tree state a target writes is sealed, so no test can start# over, and each generation extends the one before it.python3 - "$registry_dir" \@@ -483,6 +483,8 @@ match_unload_artifact = artifact("shirudo/tree-match-unload",this_node = {"architecture": [node_arch], "labels": {"env": ["tree-test"]}}other_node = {"architecture": [node_arch],"labels": {"env": ["not-this-node"]}}+# Selected by the kernel config alone, which t7104 takes away and gives.+kconfig_node = {"architecture": [node_arch], "kconfig": {"CONFIG_BPF": ["y"]}}operations = [operation(1, "shirudo-test-tree-match", {}, match_artifact),operation(2, "shirudo-test-tree-skip", other_node, skip_artifact),@@ -490,8 +492,10 @@ operations = [operation(4, "shirudo-test-tree-match", this_node,match_unload_artifact, op="delete"),operation(5, "shirudo-test-tree-match", this_node, match_artifact),+ operation(6, "shirudo-test-tree-match", kconfig_node,+ match_unload_artifact, op="delete"),]-references = ("stable", "updated", "deleted", "restored")+references = ("stable", "updated", "deleted", "restored", "kconfig")for generation, reference in enumerate(references, start=1):head = generation + 1publication = {@@ -507,7 +511,7 @@ for generation, reference in enumerate(references, start=1):.encode())PY- for reference in stable updated deleted restored; do+ for reference in stable updated deleted restored kconfig; doopenssl cms -sign -binary -md sha512 \-in "$payloads-$reference.json" \-signer "$FIXTURE_WORK/trusted/cert.der" \@@ -535,7 +539,7 @@ def write(path, body):path.write_bytes(body)-for reference in ("stable", "updated", "deleted", "restored"):+for reference in ("stable", "updated", "deleted", "restored", "kconfig"):stem = payloads.name + "-" + referencepayload = payloads.with_name(stem + ".json").read_bytes()signature = payloads.with_name(stem + ".sig").read_bytes()diff --git a/testing/vm/image-fixtures.sh b/testing/vm/image-fixtures.shindex c47ac478..59c9e033 100755--- a/testing/vm/image-fixtures.sh+++ b/testing/vm/image-fixtures.sh@@ -66,6 +66,7 @@ cp "$keys_dir/cert.der" "$output/public/primary.der"for name in config-boot-keys config-live-new-key config-a config-b config-bad config-revoke \config-tree-stable config-tree-updated config-tree-deleted config-tree-restored \+ config-tree-kconfig \config-otel config-jsonl config-jsonl-bad config-interrupted config-end2end \config-builtin; do[ "$name" != config-builtin ] || [ -n "$builtin_key" ] || continue