Skip to content

eBPF-based security platform

proofs: reach the copy of a Retry-After value in otel-retry-after

Daniel Borkmann16c9d13ebb1a
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 41739aa4..b64b2c01 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -797,9 +797,12 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
each ``%XX`` decoded, a stray ``%`` and ``%00`` refused
* - ``otel-retry-after``
- ``otel_retry_after()``, ``response_header()``
- - Headers up to 32 bytes, dates modelled
+ - Headers up to 32 bytes, dates modelled; lines of 139 to 142
+ bytes whose value is 122 to 130 bytes once trimmed, around the
+ 128-byte buffer it is copied into
- A delay is at most 30 seconds, the value itself when shorter; a
- header line read only within itself
+ header line read only within itself, its value copied only when
+ it fits
* - ``tpm-reader``
- The TPM reader primitives of :src:`util/tpm_wire.c`: ``get8()``
to ``get64()``, ``get2b()``, ``get2b_fixed()``, ``get_name()``
diff --git a/testing/proofs/cbmc/otel-retry-after.c b/testing/proofs/cbmc/otel-retry-after.c
index ce6acbb4..939224e0 100644
--- a/testing/proofs/cbmc/otel-retry-after.c
+++ b/testing/proofs/cbmc/otel-retry-after.c
@@ -6,6 +6,7 @@
* of up to LEN bytes and every value it holds: a delay of digits is read
* exactly, up to 30 seconds, and whatever date strptime() makes of the
* rest, the wait is at most 30 seconds and nothing past the line is read.
+ * A LEN past 32 runs a line as long as the copy of its value instead.
*/
#include "proof.h"
@@ -95,8 +96,37 @@ static void header_line(void)
"a wait of at most 30 seconds");
}
+/*
+ * A line whose value is cut to about the 128 bytes the callback copies it
+ * into: the name, two bytes of any value, digits, and three bytes of any
+ * value at the end, so that the blanks trimmed off leave 122 to 130.
+ */
+static void long_line(void)
+{
+ static const char name[] = "Retry-After:";
+ struct otel_response *r;
+ size_t n, i;
+ char *line;
+
+ r = any_bytes(sizeof(*r));
+ r->retry_after_valid = false;
+ line = any_bytes(LEN);
+ memcpy(line, name, sizeof(name) - 1);
+ for (i = sizeof(name) + 1; i < LEN - 3; i++)
+ line[i] = '7';
+ __CPROVER_assume(n >= LEN - 3 && n <= LEN);
+ __CPROVER_assert(response_header(line, 1, n, r) == n,
+ "the whole line taken");
+ __CPROVER_assert(!r->retry_after_valid || r->retry_after <= 30,
+ "a wait of at most 30 seconds");
+}
+
void harness(void)
{
+ if (LEN > 32) {
+ long_line();
+ return;
+ }
delay();
header_line();
}
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 29ab4cf7..03a5fa33 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -64,7 +64,7 @@ json-string --unwind 5 --unwindset json_string.0:7,parse_string.0:5,parse_strin
json-escape --unwind 5 --unwindset parse_string.0:4,memcmp.0:9
json-roundtrip --unwind 1 --unwindset put_string_n.0:5,put_string_n.1:5,put_raw.0:7,vsnprintf.2:4,vsnprintf.0:2,format_number.0:3,format_number.2:5,format_number.3:3,parse_string.1:6,parse_string.0:4,hex4.0:5,utf8_width.0:4,memcmp.0:5 LEN=0-4
otel-header-fields -D__NO_CTYPE --unwind 34 --unwindset strchr.0:17 LEN=32
-otel-retry-after -D__NO_CTYPE --unwind 1 --unwindset response_header.0:33,response_header.1:33,otel_retry_after.0:33,otel_retry_after.1:33,delay.0:33,strlen.0:34,strncasecmp.0:13 LEN=32
+otel-retry-after -D__NO_CTYPE --unwind 1 --unwindset response_header.0:33,response_header.1:33,otel_retry_after.0:131,otel_retry_after.1:131,delay.0:33,strlen.0:131,strncasecmp.0:13,long_line.0:143 LEN=32,142
json-walk -DJSON_MAX_DEPTH=2 --unwind 3 --unwindset string_end.0:2,code_unit.0:0,hex4.0:0,parse_string.0:1,parse_string.1:2,literal_end.0:4,json_text.0:3,json_text.1:3,utf8_width.0:1,parse_array.0:1,parse_object.0:1,parse_object.1:1,digits_end.0:3,digits.0:3,skip_ws.0:3,strlen.0:6,memcmp.0:1,memchr.0:3,strnlen.0:4 LEN=0-2
json-limits -DJSON_MAX_DEPTH=2 -DJSON_MAX_BYTES=24 --unwind 8
json-field --unwind 1 --unwindset digits_end.0:7,decimal.0:7,harness.0:7,skip_ws.0:7,parse_string.1:7,parse_string.0:4,hex4.0:0,utf8_width.0:4,parse_base.0:7,parse_base.1:7,digits.0:7,strnlen.0:4,strlen.0:6,memcmp.0:6 LEN=0-6