Skip to content

eBPF-based security platform

tree: stop a sync whose kconfig selector cannot be evaluated

Daniel Borkmannbc3fa05bddbd
diff --git a/Documentation/operate/run/deliver-packages.rst b/Documentation/operate/run/deliver-packages.rst
index e99ba9c9..9132a746 100644
--- a/Documentation/operate/run/deliver-packages.rst
+++ b/Documentation/operate/run/deliver-packages.rst
@@ -372,7 +372,10 @@ publication:
- A sync moves the target's cursor past an operation whose selectors do
not match. The target never applies that operation later, even when
- its labels or kernel change.
+ its labels or kernel change. A selector the target cannot evaluate,
+ because its kernel config or its node labels cannot be read, stops
+ the sync with ``selector_evaluate`` and leaves the cursor on the
+ operation, so the next sync tries again.
- An ``add`` whose attach target is in a kernel module that is not
loaded is recorded as ``skipped: module not loaded``, and the cursor
moves past it.
diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rst
index d39a84e5..c95a679d 100644
--- a/Documentation/reference/failure-categories.rst
+++ b/Documentation/reference/failure-categories.rst
@@ -551,7 +551,8 @@ rc=<rc> (<strerror>)`` and exits 1:
- An interrupted operation cannot be reconciled with the tree
eventlog.
* - ``selector_evaluate``
- - The selector cannot be evaluated.
+ - The selector cannot be evaluated: the node labels or the kernel
+ config cannot be read. The cursor stays on the operation.
* - ``operation_digest_parse``
- The operation digest is malformed.
* - ``expected_payload_digest``
diff --git a/util/bpm_tree.h b/util/bpm_tree.h
index 4ebb3281..c9e3abf6 100644
--- a/util/bpm_tree.h
+++ b/util/bpm_tree.h
@@ -102,7 +102,8 @@ int tree_emit_publication(const struct tree_publication *pub,
/*
* Evaluate a publication selector against the running node. An empty
* selector is an unconstrained wildcard and matches every node. 1 on a
- * match, 0 without one, -errno when the node's labels cannot be read.
+ * match, 0 without one, -errno when the node's labels or kernel config
+ * cannot be read.
*/
int tree_selector_matches(const struct tree_selector *selector);
diff --git a/util/bpm_tree_state.c b/util/bpm_tree_state.c
index 2976f17a..22c7a655 100644
--- a/util/bpm_tree_state.c
+++ b/util/bpm_tree_state.c
@@ -426,10 +426,22 @@ int tree_selector_matches(const struct tree_selector *s)
if (config_rc || !config_any) {
memset(cfg_found, 0, sizeof(cfg_found));
if (strsprintf(path, sizeof(path), "/boot/config-%s",
- u.release) < 0 ||
- read_selector_config_file(path, s, cfg_slots, cfg_values,
- cfg_found, false))
- return 0;
+ u.release) < 0)
+ return -ENAMETOOLONG;
+ ret = read_selector_config_file(path, s, cfg_slots,
+ cfg_values, cfg_found,
+ false);
+ /*
+ * No config to show, or a value longer than any
+ * selector names, matches nothing; a config that
+ * cannot be read is no answer, and the sync must not
+ * move past the operation on it.
+ */
+ if (ret == -ENOENT || ret == -ENOSPC)
+ return config_rc && config_rc != -ENOENT &&
+ config_rc != -ENOSPC ? config_rc : 0;
+ if (ret)
+ return ret;
}
/*
* The config is read into the first entry of a key, so a key