Skip to content

eBPF-based security platform

tree: stop a sync whose label selector cannot be evaluated

Daniel Borkmann1931cb233a53
diff --git a/builtin-bpm.c b/builtin-bpm.c
index b2654bed..4e291811 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -1610,12 +1610,16 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
struct shirudo_tree_operation *op = &pub.operations[i];
uint8_t digest[32], previous[32], next[32];
char artifact[PATH_MAX];
- bool match, skipped_module = false;
+ bool skipped_module = false;
if (op->seq <= state.last_seq)
continue;
- match = shirudo_tree_selector_matches(&op->selector);
- if (!match) {
+ rc = shirudo_tree_selector_matches(&op->selector);
+ if (rc < 0) {
+ tree_sync_report_error("selector_evaluate", op, rc);
+ TREE_SYNC_RETURN(rc);
+ }
+ if (!rc) {
skipped++;
if (!dry_run) state.last_seq = op->seq;
continue;
diff --git a/util/bpm_tree.h b/util/bpm_tree.h
index 70e81224..ffe7c617 100644
--- a/util/bpm_tree.h
+++ b/util/bpm_tree.h
@@ -100,7 +100,8 @@ int shirudo_tree_emit_publication(const struct shirudo_tree_publication *pub,
/*
* Evaluate a publication selector against the running node. An empty
- * selector is an unconstrained wildcard and matches every node.
+ * 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.
*/
int shirudo_tree_selector_matches(const struct shirudo_tree_selector *selector);
diff --git a/util/bpm_tree_state.c b/util/bpm_tree_state.c
index 63cf8897..6978baa3 100644
--- a/util/bpm_tree_state.c
+++ b/util/bpm_tree_state.c
@@ -280,7 +280,7 @@ int shirudo_tree_selector_matches(const struct shirudo_tree_selector *s)
char cfg_values[SHIRUDO_TREE_MAX_KCONFIG][SHIRUDO_TREE_STRING_MAX];
int cfg_slots[SHIRUDO_TREE_SELECTOR_HASH_SIZE];
bool cfg_found[SHIRUDO_TREE_MAX_KCONFIG] = {};
- int nl = 0, config_rc;
+ int nl = 0, config_rc, rc;
const char *v;
char path[PATH_MAX];
bool matched, config_any;
@@ -359,9 +359,12 @@ int shirudo_tree_selector_matches(const struct shirudo_tree_selector *s)
}
}
if (s->n_labels) {
- if (read_config_file("/etc/shirudo/node.labels", labels, &nl,
- ARRAY_SIZE(labels), false))
+ rc = read_config_file("/etc/shirudo/node.labels", labels, &nl,
+ ARRAY_SIZE(labels), false);
+ if (rc == -ENOENT)
return 0;
+ if (rc)
+ return rc;
for (int i = 0; i < s->n_labels; i++) {
v = kv_value(labels, nl, s->labels[i].key);
if (!v || !selector_values_match(&s->labels[i], v))