eBPF-based security platform
proofs: refuse the signed sections of a directory with a bad entry
Daniel Borkmann05b8b2fe704a
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex aa05d634..e05be211 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -577,7 +577,8 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.- Data of 15, 16, 40 and 64 bytes- Sections kept only behind a valid trailer, the directory belowthe trailer, each section inside the data below the directory;- nothing kept on refusal+ none of a directory with a reserved word set or a tag unknown or+ repeated; nothing kept on refusal* - ``upatch-signed-name``- The ``NAME`` and ``DECODERS`` sections of``parse_signed_sections()``diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.listindex 6c4433b2..e6ad0d5f 100644--- a/testing/proofs/cbmc/proofs.list+++ b/testing/proofs/cbmc/proofs.list@@ -15,8 +15,8 @@ upatch-header --unwind 2 --unwindset memchr.0:257upatch-decoders --unwind 2 --unwindset memchr.0:65,parse_decoders.0:3,harness.0:3upatch-policy-labels --unwind 3 LEN=0,19,20,4187,4188,4189,8356upatch-name --unwind 33-upatch-signed-sections --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:4,parse_decoders.0:0,parse_policy_labels.0:0 LEN=15,16,40,64-upatch-signed-name --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:2,parse_decoders.0:2,parse_policy_labels.0:0 LEN=288+upatch-signed-sections --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:4,directory_broken.0:4,parse_decoders.0:0,parse_policy_labels.0:0 LEN=15,16,40,64+upatch-signed-name --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:2,directory_broken.0:2,parse_decoders.0:2,parse_policy_labels.0:0 LEN=288upatch-prog-specs --refine-arithmetic --memory-leak-check --malloc-may-fail --malloc-fail-null --unwind 3 --unwindset memchr.0:129,memcmp.0:129,strchr.0:129,strnlen.0:1,strlen.0:1,parse_uprobe_targets.0:0,parse_uprobe_targets.1:0,parse_kprobe_targets.0:0,parse_kprobe_syms.0:0,uprobe_valid.0:1,kprobe_multi_valid.0:1,strcmp.0:1 LEN=3,15,16,176upatch-prog-count --unwind 2 LEN=3,16,176,336upatch-prog-uprobes --refine-arithmetic --max-field-sensitivity-array-size 226 --memory-leak-check --malloc-may-fail --malloc-fail-null --unwind 2 --unwindset memchr.0:129,memcmp.0:129,strchr.0:129,strnlen.0:3,strlen.0:3,parse_uprobe_targets.0:3,parse_kprobe_targets.0:2,parse_kprobe_syms.0:0,kprobe_sym_valid.0:0,kprobe_multi_valid.0:0,strcmp.0:1 LEN=226diff --git a/testing/proofs/cbmc/upatch-signed-sections.c b/testing/proofs/cbmc/upatch-signed-sections.cindex d88b4d64..dbaf4091 100644--- a/testing/proofs/cbmc/upatch-signed-sections.c+++ b/testing/proofs/cbmc/upatch-signed-sections.c@@ -6,7 +6,8 @@* signature is checked, for data of LEN bytes, each length proofs.list* names, with one section where it can hold a name: util/upatch.c keeps* sections only behind a valid trailer, each inside the data and below the- * directory, the name terminated, and no length or count without them.+ * directory, the name terminated, none of a directory with a reserved word+ * set or a tag unknown or repeated, and no length or count without them.*/#define PROOF_MEMCHR_QUANTIFIED@@ -26,6 +27,46 @@ static bool below(const struct upatch *u, const void *p, size_t len,len <= (size_t)(u->map + dir_off - b);}+/* The bit of a tag the format knows, 0 for any other. */+static __u32 tag_bit(__u32 tag)+{+ switch (tag) {+ case UPATCH_SECTION_NAME:+ return 1;+ case UPATCH_SECTION_ATTACH:+ return 2;+ case UPATCH_SECTION_UNLOAD:+ return 4;+ case UPATCH_SECTION_DECODERS:+ return 8;+ case UPATCH_SECTION_POLICY_LABELS:+ return 16;+ case UPATCH_SECTION_TYPE:+ return 32;+ case UPATCH_SECTION_JAR:+ return 64;+ default:+ return 0;+ }+}++/* An entry with a reserved word set, a tag the format lacks or one seen before. */+static bool directory_broken(const struct upatch *u, __u32 dir_off, __u32 nr)+{+ __u32 seen = 0, i;++ for (i = 0; i < nr; i++) {+ const struct upatch_signed_section *s =+ (const void *)(u->map + dir_off + i * sizeof(*s));+ __u32 bit = tag_bit(get_le32(&s->tag));++ if (get_le32(&s->reserved) || !bit || (seen & bit))+ return true;+ seen |= bit;+ }+ return false;+}+static bool kept_any(const struct upatch *u){return u->signed_name || u->signed_attach ||@@ -78,6 +119,8 @@ void harness(void)__CPROVER_assert((__u64)dir_off + nr *sizeof(struct upatch_signed_section) <=len - sizeof(*tr), "the directory below the trailer");+ __CPROVER_assert(!directory_broken(&u, dir_off, nr),+ "nothing kept of a directory with a reserved word, unknown or repeated tag");__CPROVER_assert(!u.signed_name ||(below(&u, u.signed_name, UPATCH_NAME_MAX, dir_off) &&memchr(u.signed_name, '\0', UPATCH_NAME_MAX)),