eBPF-based security platform
proofs: follow the config NvPCR in the config-evidence proofs
Daniel Borkmann3a6166d02106
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex e39c4048..dec23ae6 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -1068,10 +1068,11 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.events, cut or malformed at any point; ``json_parse()`` a model ofits contract, SHA-256 as any result- Takes exactly a history with every key, schema 1, a PCR from 0 to- 15 but 9 and 11, 32-bit counts, 64 hex digits of initial value and- one boot event then updates in sequence, as said, and names one- out of order with ``EKEYREJECTED``; a refusal and evidence without- a history return nothing, with nothing left allocated+ 15 but 9 and 11 or the config NvPCR's index, 32-bit counts, 64 hex+ digits of initial value and one boot event then updates in+ sequence, as said, and names one out of order with+ ``EKEYREJECTED``; a refusal and evidence without a history return+ nothing, with nothing left allocated* - ``config-evidence-roundtrip``- ``config_evidence_emit()``, ``emit_hash()`` into``config_evidence_parse()``@@ -1085,14 +1086,16 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.- ``replay()``, ``config_evidence_verify()``,``config_measure_event()``- Every view of 0 to 3 events, without events or past 4096 of them,- every quote mask, TPM boot, PCR value and expectation; SHA-256 as- any digest or failure- - Passes exactly when the PCR is one from 0 to 15 but 9 and 11,- quoted and the expected one, the reset count the quote's, the events- one boot event then updates in sequence, the quoted value the- initial one extended by each event's digest in order, and the last- root the expected one; a digest hashes the tag, the kind and the- root; a root without its PCR is refused+ every quote mask, TPM boot, PCR value, certified NvPCR value or+ none, and expectation; SHA-256 as any digest or failure+ - Passes exactly when the register is a PCR from 0 to 15 but 9 and 11+ that is quoted, or the config NvPCR, certified and with a history+ that starts at the digest of 64 zero bytes, and is the expected+ one, the reset count the quote's, the events one boot event then+ updates in sequence, the quoted or certified value the initial one+ extended by each event's digest in order, and the last root the+ expected one; a digest hashes the tag, the kind and the root; a+ root without its PCR is refused* - ``config-evidence-collect``- ``config_evidence_collect()``, ``collect_event()``- Every journal of 0 to 2 records and every active selection, thediff --git a/testing/proofs/cbmc/config-evidence-document.h b/testing/proofs/cbmc/config-evidence-document.hindex ed8c2426..df2f4dc9 100644--- a/testing/proofs/cbmc/config-evidence-document.h+++ b/testing/proofs/cbmc/config-evidence-document.h@@ -40,6 +40,13 @@ static struct said_config said;static bool breaks, broken, hash_failed;static __u8 last_digest[32];+/* A static PCR the register leaves alone, or the config NvPCR's index. */+static bool config_register(__s64 pcr)+{+ return (pcr >= 0 && pcr <= 15 && pcr != CHAIN_PCR &&+ pcr != CHAIN_PHASE_PCR) || pcr == TPM_CONFIG_NVPCR_INDEX;+}+int sha256_buffer(const void *data, size_t len, __u8 out[32]){int ret;diff --git a/testing/proofs/cbmc/config-evidence-parse.c b/testing/proofs/cbmc/config-evidence-parse.cindex 97ca53ab..5185b5f4 100644--- a/testing/proofs/cbmc/config-evidence-parse.c+++ b/testing/proofs/cbmc/config-evidence-parse.c@@ -44,8 +44,7 @@ static bool whole(void)size_t i;if (!said.schema.given || said.schema.value != 1 ||- !said.pcr.given || said.pcr.value < 0 || said.pcr.value > 15 ||- said.pcr.value == CHAIN_PCR || said.pcr.value == CHAIN_PHASE_PCR ||+ !said.pcr.given || !config_register(said.pcr.value) ||!count(&said.reset_count) || !count(&said.restart_count) ||!said.initial_pcr.given ||!hex_digits(said.initial_pcr.text, 64) || !said.events || !LEN)diff --git a/testing/proofs/cbmc/config-evidence-roundtrip.c b/testing/proofs/cbmc/config-evidence-roundtrip.cindex 1f51966d..0036541a 100644--- a/testing/proofs/cbmc/config-evidence-roundtrip.c+++ b/testing/proofs/cbmc/config-evidence-roundtrip.c@@ -131,14 +131,13 @@ static bool same(const __u8 *a, const __u8 *b)return true;}-/* What replay() takes: a config PCR and one boot event, then updates. */+/* What replay() takes: a config register and one boot event, then updates. */static bool replays(const struct config_evidence *view){const struct config_evidence_event *event = view->events;size_t i;- if (view->pcr > 15 || view->pcr == CHAIN_PCR ||- view->pcr == CHAIN_PHASE_PCR || !LEN)+ if (!config_register(view->pcr) || !LEN)return false;for (i = 0; i < LEN; i++) {if (event[i].kind != (i ? CONFIG_EVENT_UPDATE :diff --git a/testing/proofs/cbmc/config-evidence-verify.c b/testing/proofs/cbmc/config-evidence-verify.cindex 0efb1a99..87a90c44 100644--- a/testing/proofs/cbmc/config-evidence-verify.c+++ b/testing/proofs/cbmc/config-evidence-verify.c@@ -4,9 +4,10 @@** replay() and config_evidence_verify() of util/config_attest.c on every* history of LEN events: a history passes only as one boot event and then- * updates in sequence, and only when the quoted PCR holds the initial value- * extended by each event's digest in order. SHA-256 gives any digest or- * fails: nothing is assumed of it, collision resistance least of all.+ * updates in sequence, and only when the quoted PCR, or the certified+ * config NvPCR from the value systemd initializes it to, holds the initial+ * value extended by each event's digest in order. SHA-256 gives any digest+ * or fails: nothing is assumed of it, collision resistance least of all.*/#include "proof.h"@@ -27,7 +28,10 @@ static const char event_tag[] = "shirudo-config-root-v1";static const struct config_evidence *history;static __u8 pcr_now[32], event_digest[32];static size_t n_extended;-static bool digest_ready, hash_failed;+static bool digest_ready, initial_asked, hash_failed;++/* SHA-256 of 64 zero bytes, one value however often asked. */+static __u8 nvpcr_initial[32];static bool same(const __u8 *a, const __u8 *b){@@ -61,6 +65,22 @@ static void check_event(const __u8 *in)"the event's root");}+/*+ * The config NvPCR's value once systemd's unlogged initializing write+ * extended 64 zero bytes, asked of an NvPCR history before its first+ * event. A first extend without its event's digest comes here as well+ * and fails on its bytes.+ */+static void check_initial(const __u8 *in)+{+ size_t k;++ __CPROVER_assert(history->pcr == TPM_CONFIG_NVPCR_INDEX && !n_extended,+ "the NvPCR's start, before any event");+ for (k = 0; k < EXTEND_BYTES; k++)+ __CPROVER_assert(!in[k], "64 zero bytes");+}+/* A TPM's extend: the PCR's value, then the event's digest. */static void check_extend(const __u8 *in){@@ -77,6 +97,14 @@ int sha256_buffer(const void *data, size_t len, __u8 out[32])__CPROVER_assert(__CPROVER_w_ok(out, 32), "a digest's room");__CPROVER_assert(len == EVENT_BYTES || len == EXTEND_BYTES,"an event or an extend");+ if (len == EXTEND_BYTES && !digest_ready && !initial_asked) {+ check_initial(data);+ initial_asked = true;+ memcpy(out, nvpcr_initial, 32);+ if (ret)+ hash_failed = true;+ return ret;+ }if (len == EVENT_BYTES)check_event(data);else@@ -116,6 +144,7 @@ static void any_view(struct config_evidence *view, bool *holds_events)memcpy(pcr_now, view->initial_pcr, 32);n_extended = 0;digest_ready = false;+ initial_asked = false;hash_failed = false;}@@ -162,9 +191,9 @@ static void replayed(void)static void verified(void){- bool holds_events, config_pcr, approved, have_root;+ bool holds_events, config_pcr, nvpcr, approved, have_root, certified;+ const __u8 *expected_root = NULL, *nvpcr_value = NULL, *live;__u32 quote_mask, reset;- const __u8 *expected_root = NULL;struct config_evidence view;const char *reason = NULL;int expected_pcr, ret;@@ -173,8 +202,11 @@ static void verified(void)any_view(&view, &holds_events);if (have_root)expected_root = any_bytes(32);+ if (certified)+ nvpcr_value = any_bytes(32);ret = config_evidence_verify(&view, quote_mask, reset, pcrs,- expected_root, expected_pcr, &reason);+ nvpcr_value, expected_root, expected_pcr,+ &reason);__CPROVER_assert(reason, "a reason either way");if (!view.present) {__CPROVER_assert(ret == (expected_root || expected_pcr >= 0 ?@@ -184,13 +216,16 @@ static void verified(void)}config_pcr = view.pcr < 16 && view.pcr != CHAIN_PCR &&view.pcr != CHAIN_PHASE_PCR;- approved = config_pcr && (quote_mask >> view.pcr & 1) &&+ nvpcr = view.pcr == TPM_CONFIG_NVPCR_INDEX;+ approved = ((config_pcr && (quote_mask >> view.pcr & 1)) ||+ (nvpcr && nvpcr_value &&+ same(view.initial_pcr, nvpcr_initial))) &&(expected_pcr < 0 || view.pcr == (__u32)expected_pcr) &&view.reset_count == reset &&!(expected_root && expected_pcr < 0);if (!approved) {__CPROVER_assert(ret,- "refused unless quoted, expected and of the quote's TPM boot");+ "refused unless quoted or certified, expected and of this boot");return;}if (!holds_events || !in_order(&view) || hash_failed) {@@ -198,16 +233,18 @@ static void verified(void)return;}__CPROVER_assert(n_extended == LEN, "every event extended");+ live = nvpcr ? nvpcr_value : pcrs[view.pcr];__CPROVER_assert(!ret ==- (same(pcrs[view.pcr], pcr_now) &&+ (same(live, pcr_now) &&(!expected_root ||same(view.events[LEN - 1].root_hash,expected_root))),- "passes exactly on the quoted PCR's replay and the expected last root");+ "passes exactly on its register's replay and the expected last root");}void harness(void){+ __CPROVER_havoc_slice(nvpcr_initial, sizeof(nvpcr_initial));replayed();verified();}diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.listindex f40db2c0..1c07b6f2 100644--- a/testing/proofs/cbmc/proofs.list+++ b/testing/proofs/cbmc/proofs.list@@ -119,7 +119,7 @@ options-table --object-bits 12 --unwind 8 --unwindset strcmp.0:12config-evidence-event --unwind 1 --unwindset harness.0:33,same_event.0:33,hex_digits.0:65,room_for.0:10,on_event.0:4,hex_decode.0:33,strlen.0:66 LEN=0,1,15,16,128,4095,4096config-evidence-parse --unwind 1 --unwindset config_evidence_parse.0:7,on_event.0:4,replay.0:4,hex_decode.0:33,strlen.0:66,strcmp.0:15,named.0:7,json_parse.0:7,json_parse.1:4,give_event.0:4,give_text.0:66,any_document.0:4,whole.0:4,in_order.0:4,hex_digits.0:65,spells.0:33,blank.0:33,check_as_said.0:4,check_as_said.1:33 --memory-leak-check --slice-formula LEN=0-2config-evidence-roundtrip --unwind 1 --unwindset config_evidence_emit.0:4,hex_encode.0:33,config_evidence_parse.0:7,on_event.0:4,replay.0:4,hex_decode.0:33,strlen.0:66,strcmp.0:15,named.0:7,json_parse.0:7,json_parse.1:4,give_event.0:4,give_text.0:66,json_kv_string.0:66,sequence_overflows.0:4,replays.0:4,same.0:33,blank.0:33,check_read_back.0:4 --memory-leak-check --slice-formula LEN=0-2-config-evidence-verify --unwind 1 --unwindset replay.0:4,memcmp.0:33,in_order.0:4,check_event.0:24,same.0:33 --slice-formula LEN=0-3+config-evidence-verify --unwind 1 --unwindset replay.0:4,memcmp.0:33,in_order.0:4,check_event.0:24,check_initial.0:65,same.0:33 --slice-formula LEN=0-3config-evidence-collect --unwind 1 --unwindset config_update_events.0:4,replay.0:4,memcmp.0:33,history.0:4,this_boot_at.0:4,check_exported.0:4,same.0:33,blank.0:33,harness.0:4 --memory-leak-check --slice-formula LEN=0-2upatch-writer-header --unwind 2 --unwindset strnlen.0:257,memchr.0:257,memcmp.0:33upatch-writer-sections --memory-leak-check --max-field-sensitivity-array-size 512 --object-bits 10 --unwind 2 --unwindset harness.0:9,compose_signed_data.0:3,compose_signed_data.1:3,parse_signed_sections.0:3,parse_decoders.0:0,parse_policy_labels.0:0 LEN=0,1,7,8