eBPF-based security platform
genkey: refuse to run on a target
Daniel Borkmann105b1c25019e
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex f455fe49..7bd81275 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -318,7 +318,7 @@ signed config image.* - ``t6113-verity-authority``- Task authority on exec, fork and failed exec* - ``t6114-output-paths``- - Output paths aimed at sealed state+ - Output paths aimed at sealed state; ``genkey`` refused on a target* - ``t6115-archive-restore``- Artifacts brought into the archive, a hidden state directory,``/etc/initrd-release``diff --git a/Documentation/reference/cli/genkey.rst b/Documentation/reference/cli/genkey.rstindex 2c4f1db2..a2010108 100644--- a/Documentation/reference/cli/genkey.rst+++ b/Documentation/reference/cli/genkey.rst@@ -11,8 +11,9 @@ shirudo genkeyGenerate an ML-DSA-87 private key and a self-signed X.509 certificate forsigning upatches.-Runs on: operator host, without the image gate. Requires: write-access to the keys directory. Changes measured state: no.+Runs on: operator host, without the image gate; refused on a target+where shirudo enforces. Requires: write access to the keys directory.+Changes measured state: no.Usage-----@@ -96,7 +97,8 @@ Exit status- The pair was written.* - 1- The pair exists and ``--force`` was not given, the directory is- unsafe or not writable, or generating or writing failed.+ unsafe or not writable, generating or writing failed, or shirudo+ enforces on this host.* - 2- An unknown option, or ``--keys-dir`` without a value.diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 7b0ac272..ed74368d 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -743,7 +743,10 @@ through a symbolic link and not created under a labeled directory. Whenroot makes the write fail, shirudo removes the file through thedirectory it opened it in, and only while the name still holds theinode it wrote, never by resolving the path again, where a directory-root swapped for a link would lead it to sealed state (``t6007``). The+root swapped for a link would lead it to sealed state (``t6007``).+``genkey`` refuses to run where shirudo enforces, so that no target holds+a private key and root cannot have shirudo write a key pair into sealed+state (``t6114``). Thecontents of a config image are read from the descriptor of its verifiedroot with ``openat2(2)`` and ``RESOLVE_BENEATH``, never through a``/proc/<pid>/fd`` path that root could mount over.diff --git a/builtin-genkey.c b/builtin-genkey.cindex cccbaba0..4e26475f 100644--- a/builtin-genkey.c+++ b/builtin-genkey.c@@ -28,6 +28,7 @@#include "builtin.h"#include "util/help.h"+#include "util/identity.h"#include "util/log.h"#include "util/crypto.h"#include "util/paths.h"@@ -429,6 +430,15 @@ int cmd_genkey(int argc, const char **argv)}}+ /*+ * A target never holds a private key, and its task has the authority+ * the seal denies root, which would write the pair wherever root asks.+ */+ if (enforcement_active()) {+ pr_err("genkey: refusing on a target: the signing key belongs on the operator host");+ return 1;+ }+keys_dir = keys_dir_resolve(keys_dir_arg);ret = key_paths(keys_dir, pkey_path, sizeof(pkey_path),diff --git a/testing/functional/tamperproof/t6114-output-paths.sh b/testing/functional/tamperproof/t6114-output-paths.shindex 5f869038..e41275dd 100755--- a/testing/functional/tamperproof/t6114-output-paths.sh+++ b/testing/functional/tamperproof/t6114-output-paths.sh@@ -6,8 +6,9 @@# runtime task write what it denies everyone else, so a --report, --output# or --json path pointed at sealed state, directly or through a symbolic# link, must be refused rather than clobber the eventlog or plant a file-# the next boot restores. Non-destructive: every refusal leaves the state-# as it was.+# the next boot restores, and genkey, whose key pair has no place on a+# target, writes none anywhere. Non-destructive: every refusal leaves the+# state as it was.cd "$(dirname "$0")/../..". ./integration-lib.sh@@ -60,6 +61,16 @@ test_expect_success 'evidence is not written over the eventlog' '[ "$(sha256sum "$EVENTLOG" | cut -d" " -f1)" = "$BEFORE" ]'+test_expect_success 'genkey writes no key pair on a target' '+ KEYS_BEFORE=$(ls -la /var/lib/shirudo/keys 2>/dev/null | sha256sum) &&+ ! "$SHIRUDO_BIN" genkey --force \+ --keys-dir=/var/lib/shirudo/keys >/dev/null 2>"$LINK.err" &&+ grep -q "refusing on a target" "$LINK.err" &&+ ! "$SHIRUDO_BIN" genkey --keys-dir=/tmp/t6114-keys >/dev/null 2>&1 &&+ [ ! -e /tmp/t6114-keys ] &&+ [ "$(ls -la /var/lib/shirudo/keys 2>/dev/null | sha256sum)" = "$KEYS_BEFORE" ]+'+test_expect_success 'the eventlog still replays' '"$SHIRUDO_BIN" status --json 2>/dev/null |python3 -c "import json,sys; d=json.load(sys.stdin); sys.exit(0 if d[\"tpm\"][\"chain_matches_eventlog\"] else 1)"