Skip to content

eBPF-based security platform

proofs: refuse a upatch pair exactly when it cannot fit

Daniel Borkmann48a49874aba5
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 6d7eb1c3..4a4d5910 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -401,7 +401,10 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
- ``bpm_upatch_member()``, ``bpm_upatch_pair()``
- Lengths 0 to 18
- What install loads and uninstall unloads goes by the suffix alone;
- a pair is terminated, the other half, and pairs back to the name
+ a pair refused exactly for a name that is neither and for a room
+ short of what its kind needs, 8 bytes more than the name for a
+ load and 6 fewer for an unload; else terminated, the other half,
+ and pairing back to the name
* - ``bpm-tar-writer``
- ``tar_entry()``, ``tar_octal()``, ``tar_write()`` of
:src:`tools/shirudo-build/bpm-build.c`, against
diff --git a/testing/proofs/cbmc/bpm-upatch-member.c b/testing/proofs/cbmc/bpm-upatch-member.c
index 6b0608b1..47986cb8 100644
--- a/testing/proofs/cbmc/bpm-upatch-member.c
+++ b/testing/proofs/cbmc/bpm-upatch-member.c
@@ -4,7 +4,8 @@
*
* bpm_upatch_member() and bpm_upatch_pair() of util/bpm_package.c, which
* decide what install loads and uninstall unloads, on every name of LEN
- * bytes: the suffix alone decides, and a pair turns back into its name.
+ * bytes: the suffix alone decides, a pair is refused exactly when it does
+ * not fit, and a pair turns back into its name.
*/
#include <stdbool.h>
@@ -31,8 +32,9 @@ void harness(void)
enum bpm_upatch_member kind, back;
char out[LEN + 8], again[LEN + 8];
bool plain, unload, upatch;
- size_t cap, n;
+ size_t cap, room, n;
char *name;
+ int ret;
name = any_bytes(LEN);
kind = bpm_upatch_member(name, LEN);
@@ -44,11 +46,14 @@ void harness(void)
"the suffix alone decides");
__CPROVER_assume(cap <= sizeof(out));
- if (bpm_upatch_pair(name, LEN, out, cap)) {
- __CPROVER_assert(kind == BPM_UPATCH_OTHER ||
- cap <= LEN + 7, "refused only when it cannot fit");
+ /* The other half's name and its NUL: 7 bytes more, or 7 less. */
+ room = LEN + 8 - (kind == BPM_UPATCH_UNLOAD ? 14 : 0);
+ ret = bpm_upatch_pair(name, LEN, out, cap);
+ __CPROVER_assert(ret == (kind == BPM_UPATCH_OTHER ? -EINVAL :
+ cap < room ? -ENAMETOOLONG : 0),
+ "refused exactly when no pair or when it cannot fit");
+ if (ret)
return;
- }
n = strnlen(out, cap);
__CPROVER_assert(n < cap, "terminated");
back = bpm_upatch_member(out, n);