eBPF-based security platform
upatch: record an extend that finds a foreign register as tampered
Daniel Borkmannb28db449e4da
diff --git a/builtin-upatch.c b/builtin-upatch.cindex 44eacf7a..d87329d7 100644--- a/builtin-upatch.c+++ b/builtin-upatch.c@@ -2283,6 +2283,12 @@ static int upatch_chain_event_locked(const char *tag, const char *type,return 0;}+/* A register other than the one init set up is a verdict, not a TPM fault. */+static const char *chain_event_category(int rc, bool measured)+{+ return !measured && rc == -EACCES ? "tampered" : "tpm_error";+}+static int upatch_chain_event(const char *tag, const char *type,const char *op, const char *name,const __u8 payload[32], const char *reason,@@ -2741,12 +2747,14 @@ static int cmd_upatch_load(int argc, const char **argv)goto done;}- if (upatch_chain_event("shirudo-upatch", "upatch_load", "load",- name, payload, NULL, rep.chain_after,- &measured) != 0) {+ rc = upatch_chain_event("shirudo-upatch", "upatch_load", "load",+ name, payload, NULL, rep.chain_after,+ &measured);+ if (rc) {if (!measured)unload_unmeasured(name);- rep_fail(&rep, "tpm_extend", "tpm_error", EIO, measured ?+ rep_fail(&rep, "tpm_extend", chain_event_category(rc, measured),+ rc, measured ?"eventlog append failed after the extend" :"chain extend failed; the load was undone");goto done;@@ -2928,11 +2936,11 @@ static int cmd_upatch_unload(int argc, const char **argv)* fails after the event leaves a shield the register says is gone,* which the next status reports and the operator can repeat.*/- if (upatch_chain_event("shirudo-unload", "upatch_unload", "unload",- name, payload, NULL, rep.chain_after,- NULL) != 0) {- rep_fail(&rep, "tpm_extend", "tpm_error", EIO,- "chain extend failed; nothing detached");+ rc = upatch_chain_event("shirudo-unload", "upatch_unload", "unload",+ name, payload, NULL, rep.chain_after, NULL);+ if (rc) {+ rep_fail(&rep, "tpm_extend", chain_event_category(rc, false),+ rc, "chain extend failed; nothing detached");goto done;}