eBPF-based security platform
config: refuse a load or a define whose settings cannot be read
Daniel Borkmanncd33119c692a
diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rstindex d654624b..3bc13ec1 100644--- a/Documentation/reference/failure-categories.rst+++ b/Documentation/reference/failure-categories.rst@@ -285,10 +285,11 @@ Categoriescannot be recorded on the pin directory or a failed archive copy(the load is undone for both). In ``pin``, from ``upatch unload``,a pin directory that cannot be looked at for a reason other than- its absence: nothing is detached. In ``pre_flight``, the ``lsm_link``- pin or, from ``upatch reconcile``, an XDP program pin that cannot be- opened for a reason that says nothing about the pin, such as- ``EMFILE`` or ``ENOMEM``.+ its absence: nothing is detached. In ``pre_flight``, settings that+ cannot be read, which leave ``eventlog.max_bytes`` unknown, or the+ ``lsm_link`` pin or, from ``upatch reconcile``, an XDP program pin+ that cannot be opened for a reason that says nothing about the pin,+ such as ``EMFILE`` or ``ENOMEM``.- Read ``message`` and the journal. For ``persist``, check the spaceon the file system that holds ``/var/lib/shirudo``.diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 371e79d8..109ff510 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -1124,8 +1124,9 @@ recorded is gone or replaced it refuses ``tampered``. Which recordcounts as this boot's depends on what the caller sees (U9). A load oran unload refuses ``eventlog_full`` before it touches the TPM when thelog would exceed ``eventlog.max_bytes``, and ``init`` checks the limit-before it binds. The ``tree_op`` and ``key_revoke`` events do not check-it (U6).+before it binds; each refuses as well when the settings that hold the+limit cannot be read. The ``tree_op`` and ``key_revoke`` events do not+check it (U6).``upatch load`` and ``upatch unload`` given ``--expect-chain`` compareit with the register before acting. The comparison is not atomic withthe extend and does not serialize concurrent commands, and package anddiff --git a/builtin-upatch.c b/builtin-upatch.cindex 0b3e04c5..4ecb529f 100644--- a/builtin-upatch.c+++ b/builtin-upatch.c@@ -2786,8 +2786,16 @@ static int upatch_preflight(const char *expect_chain,static int eventlog_room(struct op_report *rep, const char *op){struct config cfg __cleanup(config_clear);+ int ret;- config_load(&cfg);+ ret = config_load(&cfg);+ if (ret) {+ pr_err("upatch %s: configuration unreadable: %s; refused, nothing loaded or extended",+ op, strerror(-ret));+ rep_fail(rep, "pre_flight", "unknown", -ret,+ "configuration unreadable");+ return -1;+ }if (eventlog_would_exceed(cfg.eventlog_max_bytes)) {pr_err("upatch %s: eventlog %s would exceed ""eventlog.max_bytes %llu; refused, nothing loaded or "diff --git a/testing/fuzz/fuzz-config.c b/testing/fuzz/fuzz-config.cindex 449db622..a1c9d751 100644--- a/testing/fuzz/fuzz-config.c+++ b/testing/fuzz/fuzz-config.c@@ -5,6 +5,7 @@* shirudo.conf, and the lines of a registry source and of upatch-tree.conf.*/+#include <stdlib.h>#include <string.h>#include "bpm_oci.h"@@ -25,7 +26,9 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)fd = fuzz_file(data, size, path, sizeof(path));if (fd < 0)return 0;- config_load_path(&cfg, path);+ if (!config_load_path(&cfg, path) &&+ cfg.tpm_owner_auth_len > sizeof(cfg.tpm_owner_auth))+ abort();/* Read as load_source() and load_tree_config() read their files. */fp = fopen(path, "r");while (fp && fgets(line, sizeof(line), fp)) {diff --git a/util/chain.c b/util/chain.cindex e71fff5c..183a1ce1 100644--- a/util/chain.c+++ b/util/chain.c@@ -303,7 +303,11 @@ static int register_define(struct tpm *tpm, bool defined,struct config cfg __cleanup(config_clear) = {};int ret;- config_load(&cfg);+ ret = config_load(&cfg);+ if (ret) {+ pr_err("tpm: configuration unreadable: %s", strerror(-ret));+ return ret;+ }if (defined) {ret = tpm_nv_undefine(tpm, NV_INDEX,cfg.tpm_owner_auth,diff --git a/util/config.h b/util/config.hindex 4937b49c..f6eb7c6d 100644--- a/util/config.h+++ b/util/config.h@@ -11,6 +11,7 @@#include <stdbool.h>#include <stddef.h>+#include <shirudo/compiler.h>#include <shirudo/misc.h>#include "tenant_id.h"@@ -53,7 +54,7 @@ struct config {};/* A missing file is not an error. */-int config_load(struct config *cfg);+int config_load(struct config *cfg) __must_check;/** Scrub a config, which holds the TPM owner's authorization; declare one@@ -62,8 +63,8 @@ int config_load(struct config *cfg);void config_clear(struct config *cfg);/* Testable path-specific loader; unlike config_load(), no env. */-int config_load_path(struct config *cfg, const char *path);+int config_load_path(struct config *cfg, const char *path) __must_check;/* The same from an open descriptor, read from its start. */-int config_load_fd(struct config *cfg, int fd, const char *label);+int config_load_fd(struct config *cfg, int fd, const char *label) __must_check;#endif /* SHIRUDO_CONFIG_H */