eBPF-based security platform
otel, shirudo-build: look for a byte of a set without strpbrk()
Daniel Borkmann673f0749ba65
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.listindex b5ce0f95..69b2acc4 100644--- a/testing/proofs/cbmc/proofs.list+++ b/testing/proofs/cbmc/proofs.list@@ -126,7 +126,7 @@ upatch-writer-sections --memory-leak-check --max-field-sensitivity-array-size 51upatch-writer-load --max-field-sensitivity-array-size 8192 --unwind 2 --unwindset compose_signed_data.0:5,compose_signed_data.1:5,parse_signed_sections.0:5,parse_decoders.0:2,parse_policy_labels.0:2 LEN=1upatch-writer-decoders --memory-leak-check --max-field-sensitivity-array-size 512 --unwind 3 --unwindset strnlen.0:65,memchr.0:65,copy_bytes.0:65,viewed.0:4 LEN=0-2upatch-writer-prog-specs --refine-arithmetic --memory-leak-check --max-field-sensitivity-array-size 512 --object-bits 12 --unwind 4 --unwindset strlen.0:161,strcmp.0:161,strncmp.0:21,strchr.0:161,strrchr.0:161,strnlen.0:161,memchr.0:129,memcmp.0:129,parse_base.0:21,parse_base.1:21,digits.0:21,default_attach_section.0:8,uprobe_section_target.0:9,text.0:161,decimal.0:5,resolve.1:65 LEN=0-21-upatch-writer-kprobes --refine-arithmetic --memory-leak-check --max-field-sensitivity-array-size 512 --object-bits 12 --unwind 4 --unwindset strlen.0:161,strcmp.0:161,strncmp.0:21,strchr.0:161,strrchr.0:161,strnlen.0:161,memchr.0:129,memcmp.0:129,parse_base.0:21,parse_base.1:21,digits.0:21,default_attach_section.0:8,uprobe_section_target.0:9,text.0:161,decimal.0:5,resolve.1:65,strpbrk.0:5,parse_uprobe_targets.0:2,parse_uprobe_targets.1:2,parse_kprobe_targets.0:3,parse_kprobe_syms.0:3,kprobe_sym_valid.0:2 LEN=0-22+upatch-writer-kprobes --refine-arithmetic --memory-leak-check --max-field-sensitivity-array-size 512 --object-bits 12 --unwind 4 --unwindset strlen.0:161,strcmp.0:161,strncmp.0:21,strchr.0:161,strrchr.0:161,strnlen.0:161,memchr.0:129,memcmp.0:129,parse_base.0:21,parse_base.1:21,digits.0:21,default_attach_section.0:8,uprobe_section_target.0:9,text.0:161,decimal.0:5,resolve.1:65,parse_uprobe_targets.0:2,parse_uprobe_targets.1:2,parse_kprobe_targets.0:3,parse_kprobe_syms.0:3,kprobe_sym_valid.0:2 LEN=0-22upatch-writer-xdp --refine-arithmetic --memory-leak-check --max-field-sensitivity-array-size 512 --object-bits 12 --unwind 4 --unwindset strlen.0:161,strcmp.0:161,strncmp.0:21,strchr.0:161,strrchr.0:161,strnlen.0:161,memchr.0:129,memcmp.0:129,parse_base.0:21,parse_base.1:21,digits.0:21,default_attach_section.0:8,uprobe_section_target.0:9,text.0:161,decimal.0:5,resolve.1:65,parse_uprobe_targets.0:0,parse_uprobe_targets.1:0,parse_kprobe_targets.0:0,parse_kprobe_syms.0:0,kprobe_sym_valid.0:0 LEN=0-8upatch-writer-uprobes --refine-arithmetic --memory-leak-check --max-field-sensitivity-array-size 512 --object-bits 12 --unwind 4 --unwindset strlen.0:161,strcmp.0:161,strncmp.0:21,strchr.0:161,strrchr.0:161,strnlen.0:161,memchr.0:129,memcmp.0:129,parse_base.0:21,parse_base.1:21,digits.0:21,default_attach_section.0:8,uprobe_section_target.0:9,text.0:161,decimal.0:5,resolve.1:65 LEN=0-21vouch-payload --malloc-may-fail --malloc-fail-null --unwind 3 --unwindset memcmp.0:33,harness.0:5 LEN=0-2diff --git a/testing/proofs/cbmc/upatch-writer-prog-specs.c b/testing/proofs/cbmc/upatch-writer-prog-specs.cindex a4a68400..a0c9f19c 100644--- a/testing/proofs/cbmc/upatch-writer-prog-specs.c+++ b/testing/proofs/cbmc/upatch-writer-prog-specs.c@@ -288,15 +288,6 @@ void pr_err(const char *fmt, ...){}-/* A body for strpbrk(), which proof.h does not give, as it does strnlen(). */-char *strpbrk(const char *s, const char *accept)-{- for (; *s; s++)- if (strchr(accept, *s))- return (char *)s;- return NULL;-}-/* CBMC models no qsort(); the writer sorts at most two names here. */void qsort(void *base, size_t nmemb, size_t size,int (*compare)(const void *, const void *))diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.cindex 9a02871c..d6699b54 100644--- a/tools/shirudo-build/package.c+++ b/tools/shirudo-build/package.c@@ -1028,7 +1028,7 @@ static int split_kprobe_multi_target(const char *list, struct build_kprobe_targechar *buf, *name;int ret = -EINVAL;- if (strpbrk(list, "*?"))+ if (strchr(list, '*') || strchr(list, '?'))return -EOPNOTSUPP;for (comma = strchr(list, ','); comma; comma = strchr(comma + 1, ','))if (++nr_syms > UPATCH_KPROBE_SYMS_MAX)diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.cindex 57987698..3de3e0de 100644--- a/util/upatch_maps_otel.c+++ b/util/upatch_maps_otel.c@@ -635,17 +635,15 @@ static int append_signal_path(const char *base, enum otel_signal signal,{size_t prefix_len;const char *slash;- const char *tail;if (!base || !base[0])return -EINVAL;- tail = strpbrk(base, "?#");- prefix_len = tail ? (size_t)(tail - base) : strlen(base);+ prefix_len = span_until(base, strlen(base), "?#");if (prefix_len == 0)return -EINVAL;slash = base[prefix_len - 1] == '/' ? "" : "/";return strsprintf(out, out_sz, "%.*s%s%s%s", (int)prefix_len, base,- slash, signal_path(signal), tail ? tail : "") < 0 ?+ slash, signal_path(signal), base + prefix_len) < 0 ?-ENAMETOOLONG : 0;}@@ -819,6 +817,13 @@ static bool header_name_ok(const char *s)return true;}+static bool holds_any(const char *s, const char *set)+{+ size_t len = strlen(s);++ return span_until(s, len, set) < len;+}+/* RFC 9110, 5.5: a field value holds no control character but tab. */static bool header_value_ok(const char *s){@@ -1721,7 +1726,7 @@ static int parse_s3_spec(struct otel_s3_state *st, const char *spec)access = getenv("AWS_ACCESS_KEY_ID");secret = getenv("AWS_SECRET_ACCESS_KEY");if (!access || !access[0] || !secret || !secret[0] ||- strpbrk(access, "\r\n:") || strpbrk(secret, "\r\n"))+ holds_any(access, "\r\n:") || holds_any(secret, "\r\n"))return -EACCES;if (check_add_overflow(strlen(access), strlen(secret),&credentials_len) ||@@ -1736,7 +1741,7 @@ static int parse_s3_spec(struct otel_s3_state *st, const char *spec)return -E2BIG;st->session_token = getenv("AWS_SESSION_TOKEN");if (st->session_token &&- (!st->session_token[0] || strpbrk(st->session_token, "\r\n")))+ (!st->session_token[0] || holds_any(st->session_token, "\r\n")))return -EINVAL;st->ca_file = getenv("AWS_CA_BUNDLE");if (st->ca_file && !st->ca_file[0])