eBPF-based security platform
attest: name records only by what their digests cover
Daniel Borkmann9ddbded2ecc5
diff --git a/Documentation/reference/formats/eventlog.rst b/Documentation/reference/formats/eventlog.rstindex 35fa587e..8c4a99bd 100644--- a/Documentation/reference/formats/eventlog.rst+++ b/Documentation/reference/formats/eventlog.rst@@ -205,7 +205,13 @@ Each digest is a SHA-256 over a tag, its terminating NUL byte and theevent's fields. Hex fields enter the hash as their 32 decoded bytes.``attest verify`` recomputes every non-``init`` digest from therecord's own fields and fails a record whose digest does not derive-from them.+from them. Its report names a record by what the digest covers: the+upatch name, the tree ``seq`` and ``operation_digest``, or the+certificate's ``cert_sha256``. A tree operation's ``op`` and ``id`` and+a key's ``fingerprint`` are not shown, as verify cannot tie them to the+digest. Evidence with a record ``type`` other than lowercase letters and+``_``, or an upatch record without a valid upatch name, is no evidence+document... list-table:::header-rows: 1diff --git a/Makefile.shirudo b/Makefile.shirudoindex f31e6ab5..14bec5cc 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -749,7 +749,7 @@ testing/helper/test-tpm-wire: testing/helper/test-tpm-wire.c util/tpm_wire.o uti$(Q)$(CC) $(CFLAGS) -o $@ $^ -lcrypto -lssltesting/helper/test-register: testing/helper/test-register.c util/attest.o util/keyring.o \- $(REGISTER_OBJS)+ util/upatch.o $(REGISTER_OBJS)@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)@@ -868,7 +868,7 @@ testing/helper/test-config-update: testing/helper/test-config-update.c \$(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)testing/helper/test-config-attest: testing/helper/test-config-attest.c \- util/attest.o $(REGISTER_OBJS)+ util/attest.o util/upatch.o $(REGISTER_OBJS)@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)@@ -1010,7 +1010,8 @@ testing/fuzz/fuzz-attest: testing/fuzz/fuzz-attest.c $(FUZZ_BASE) \util/crypto_openssl.c util/io.c $(FUZZ_SEAL) \util/config_attest.c util/config_update.c \util/config_measure.c util/initrd.c util/identity.c \- util/keyring.c util/version_id.c $(LIBBPF_A)+ util/keyring.c util/version_id.c util/upatch.c \+ $(LIBBPF_A)testing/fuzz/fuzz-attest: FUZZ_CFLAGS += $(TSS2_CFLAGS) $(LIBELF_CFLAGS)testing/fuzz/fuzz-attest: FUZZ_LIBS += $(TSS2_LIBS) $(LIBBPF_A) $(LIBELF_LIBS) $(ZLIB_LIBS)testing/fuzz/fuzz-eventlog: testing/fuzz/fuzz-eventlog.c $(FUZZ_BASE) \diff --git a/util/attest.c b/util/attest.cindex 8f9ff705..c2a91ccb 100644--- a/util/attest.c+++ b/util/attest.c@@ -33,6 +33,7 @@#include "malloc.h"#include "paths.h"#include "tpm.h"+#include "upatch.h"#include "version.h"#define FIRMWARE_LOG_PATH \@@ -497,6 +498,19 @@ static int on_pcr(void *ctx)return 0;}+/*+ * The report prints a record's type and label as they stand, and the+ * target writes them: only the words its writers use may pass, or an+ * escape sequence would rewrite what the operator reads.+ */+static bool record_word(const char *s)+{+ for (; *s; s++)+ if ((*s < 'a' || *s > 'z') && *s != '_')+ return false;+ return true;+}+static int on_record(void *ctx){struct parse *p = ctx;@@ -504,6 +518,8 @@ static int on_record(void *ctx)if (p->n_recs >= RECORDS_MAX)return -E2BIG;+ if (!record_word(p->type))+ return -EINVAL;r = &p->recs[p->n_recs];memset(r, 0, sizeof(*r));strscpy(r->type, p->type, sizeof(r->type));@@ -559,6 +575,8 @@ static int on_record(void *ctx)bool load = p->type[7] == 'l';__u8 payload[32], event[32];+ if (!upatch_name_valid(p->upatch_name))+ return -EINVAL;strscpy(r->label, p->upatch_name, sizeof(r->label));if (!hex_decode(p->upatch_payload_hex, payload, 32) &&!chain_upatch_event(load ? "shirudo-upatch" :@@ -568,21 +586,32 @@ static int on_record(void *ctx)} else if (!strcmp(p->type, "tree_op")) {__u8 operation[32], event[32];- if (strsprintf(r->label, sizeof(r->label), "%s %s seq %lld",- p->tree_op, p->tree_id, (__s64)p->tree_seq) < 0)+ /* verify cannot tie op and id to the digest: leave them out. */+ if (strsprintf(r->label, sizeof(r->label), "seq %lld",+ (__s64)p->tree_seq) < 0)return -E2BIG;if (p->tree_seq > 0 &&!strncmp(p->tree_digest_hex, "sha256:", 7) &&!hex_decode(p->tree_digest_hex + 7, operation, 32) &&- !chain_tree_event(p->tree_seq, operation, event))+ !chain_tree_event(p->tree_seq, operation, event)) {r->derived = !memneq_explicit(event, r->digest, 32);+ if (strsprintf(r->label, sizeof(r->label),+ "seq %lld operation %.12s",+ (__s64)p->tree_seq,+ p->tree_digest_hex + 7) < 0)+ return -E2BIG;+ }} else if (!strcmp(p->type, "key_revoke")) {__u8 sha[32], event[32];- strscpy(r->label, p->key_fingerprint, sizeof(r->label));+ /* Nor the fingerprint: name the measured certificate. */if (!hex_decode(p->key_sha_hex, sha, 32) &&- !chain_key_event("shirudo-key-revoke", sha, event))+ !chain_key_event("shirudo-key-revoke", sha, event)) {r->derived = !memneq_explicit(event, r->digest, 32);+ if (strsprintf(r->label, sizeof(r->label),+ "certificate %.12s", p->key_sha_hex) < 0)+ return -E2BIG;+ }}p->n_recs++;/* Reset the per-element scratch the next element may not set. */