eBPF-based security platform
bpm: refuse a tree selector the Beefile reader cannot see
Daniel Borkmann67f923122f0a
diff --git a/Documentation/upatches/publish/beefile.rst b/Documentation/upatches/publish/beefile.rstindex ceddc885..2c057c51 100644--- a/Documentation/upatches/publish/beefile.rst+++ b/Documentation/upatches/publish/beefile.rst@@ -332,8 +332,13 @@ Unknown keys and tables* - an unknown table under ``upatches.tree``- refused, because a selector the builder cannot read would widenthe rollout+ * - a table name with quotes, or blanks around its dots, such as+ ``[upatches ."tree".selector]``+ - refused, for the same reason* - an unknown key in ``[upatches.tree]``- - ignored, as metadata for newer publishers+ - ignored, as metadata for newer publishers, unless it is+ ``selector``, quoted or dotted, such as+ ``selector.architecture = ["aarch64"]``, which is refused* - a key before the first table, or in a table with any other name- ignoreddiff --git a/testing/functional/bpm/t7005-bpm-publish.sh b/testing/functional/bpm/t7005-bpm-publish.shindex 8c854510..aff25d82 100644--- a/testing/functional/bpm/t7005-bpm-publish.sh+++ b/testing/functional/bpm/t7005-bpm-publish.sh@@ -97,6 +97,32 @@ test_expect_success 'bpm build packages the upatch with its tree metadata' ''[ -s "$WORK/t7005-1.0.0.bee" ] || test_done+# TOML spells the selector these ways too; read as unknown metadata or an+# unknown table, each left the operation without one, for every node.+for n in 1 2 3 4; do+ mkdir -p "$WORK/spelled/$n" &&+ cp "$WORK/pkg/t7005.bpf.c" "$WORK/spelled/$n/" &&+ printf '[package]\nname = "t7005"\n\n[[upatches]]\nsource = "t7005.bpf.c"\n\n' \+ >"$WORK/spelled/$n/Beefile"+done+printf '[upatches.tree]\nid = "t7005"\nselector.architecture = ["aarch64"]\n' \+ >>"$WORK/spelled/1/Beefile"+printf '[upatches.tree]\nid = "t7005"\nselector = { architecture = ["aarch64"] }\n' \+ >>"$WORK/spelled/2/Beefile"+printf '[upatches.tree]\nid = "t7005"\n\n[upatches .tree.selector]\narchitecture = ["aarch64"]\n' \+ >>"$WORK/spelled/3/Beefile"+printf '[upatches.tree]\nid = "t7005"\n\n["upatches".tree.selector]\narchitecture = ["aarch64"]\n' \+ >>"$WORK/spelled/4/Beefile"++test_expect_success 'bpm build refuses a tree selector spelled another way' '+ for n in 1 2 3 4; do+ ( cd "$WORK" && ! "$S" bpm build spelled/$n --version 9.0.$n \+ --keys-dir "$WORK/keys" ) 2>"$WORK/spelled/$n.err" &&+ grep -q "is not a valid Beefile" "$WORK/spelled/$n.err" &&+ ! test -e "$WORK/t7005-9.0.$n.bee" || return 1+ done+'+PORT=$(python3 -c 'import socket; s = socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')REG="$WORK/registry"python3 ./helper/test-oci-registry.py --root "$REG" --port "$PORT" --writable \diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.cindex 0f7d14b2..c2ab75ad 100644--- a/tools/shirudo-build/bpm-build.c+++ b/tools/shirudo-build/bpm-build.c@@ -358,6 +358,22 @@ static int build_default_targets(struct bpm_build_upatch *u)static int build_target_ok(const char *target);+/* A TOML bare key, or with dots a dotted one of bare keys alone. */+static bool build_bare_key(const char *key, bool dots)+{+ bool part = false;++ for (; *key; key++) {+ if (isalnum((__u8)*key) || *key == '_' || *key == '-')+ part = true;+ else if (dots && *key == '.' && part)+ part = false;+ else+ return false;+ }+ return part;+}+static int build_parse_spec(struct bpm_build_spec *spec, char *body){struct bpm_build_upatch *upatch = NULL, *tree_owner = NULL;@@ -392,6 +408,13 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)s = build_trim(section);if (s != section)memmove(section, s, strlen(s) + 1);+ /*+ * TOML spells [upatches.tree] with blanks or quotes+ * around its parts too: such a header could name a+ * tree table this reader would pass over.+ */+ if (!build_bare_key(section, true))+ return -EINVAL;file = NULL;upatch = NULL;rodata = NULL;@@ -568,7 +591,13 @@ static int build_parse_spec(struct bpm_build_spec *spec, char *body)char *dst = NULL;size_t cap = 0;- /* Unknown tree keys are additive metadata for newer publishers. */+ /*+ * Unknown tree keys are additive metadata for newer+ * publishers, but a dotted key or an inline table+ * would be the selector spelled another way.+ */+ if (!build_bare_key(key, false) || !strcmp(key, "selector"))+ return -EINVAL;if (!strcmp(key, "id")) {dst = t->id;cap = sizeof(t->id);