Skip to content

eBPF-based security platform

proofs: state what a DNS name is in config-hosts

Daniel Borkmannede985541f4e
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 24c1dc4f..84487067 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -1004,9 +1004,12 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
- A passphrase of up to 256 bytes as it stands; a longer one
refused, the value before kept
* - ``config-hosts``
- - ``tls_classical_hosts_valid()``
- - Values of 0 to 7 bytes
- - Empty, or DNS names apart by commas
+ - ``tls_classical_hosts_valid()``, ``dns_name_valid()``
+ - Values and names of 0 to 7 bytes
+ - A list exactly when empty or names apart by single commas; a name
+ exactly when labels of 1 to 63 letters, digits and hyphens apart
+ by single dots, none starting or ending with a hyphen, at most 253
+ bytes in all, not every label a number, decimal or ``0x`` and hex
* - ``config-update-follows``
- ``event_follows()`` and ``same_event()`` of :src:`util/config_update.c`
- Every record ``record_decode()`` accepts, and the zeroed one before
@@ -1683,7 +1686,9 @@ challenge on the target, or ``attest_challenge_make()`` and
``cert_describes()``, which read a target's evidence to make one.
Of the other files the proofs read in part, these functions have no
-proof: ``tpm_public_marshal()`` and ``tpm_writer_public()`` of
+proof: ``dns_name_valid()`` of :src:`util/string.c` at its limits of a
+63-byte label and a 253-byte name, as names that long take CBMC past
+8 GB; ``tpm_public_marshal()`` and ``tpm_writer_public()`` of
:src:`util/tpm_wire.c`, the first of which the ``tpm-wire`` fuzz target
round-trips; ``upatch_rodata_symbol_range()`` of
:src:`util/upatch_rodata.c`, the range of ``.rodata`` the builder
diff --git a/testing/proofs/cbmc/config-hosts.c b/testing/proofs/cbmc/config-hosts.c
index 89dea178..873c2a8a 100644
--- a/testing/proofs/cbmc/config-hosts.c
+++ b/testing/proofs/cbmc/config-hosts.c
@@ -2,9 +2,11 @@
/*
* Copyright (c) 2026 Authors of shirudo
*
- * tls_classical_hosts_valid() of util/config.c, the shirudo.conf reader, on
- * every tls.classical_hosts value of up to LEN bytes: what it passes is
- * empty or a comma-separated list of names dns_name_valid() takes.
+ * tls_classical_hosts_valid() of util/config.c, the shirudo.conf reader,
+ * and dns_name_valid() of util/string.c, which decides each of its names,
+ * on values and names of LEN bytes: a value passes exactly when it is
+ * empty or names apart by single commas, and a name is valid exactly as
+ * RFC 1123 spells a host name that is not a numeric address.
*/
#define PROOF_MEMCPY_BYTEWISE
@@ -13,11 +15,14 @@
#include "../../../util/hex.c"
#include "../../../util/config.c"
+#define LABEL_MAX 63
+#define NAME_MAX_LEN 253
+
void pr_warn(const char *fmt, ...)
{
}
-static char *any_string(void)
+static char *any_name(void)
{
char *s = any_bytes(LEN + 1);
@@ -25,20 +30,104 @@ static char *any_string(void)
return s;
}
-void harness(void)
+static bool decimal(char c)
+{
+ return c >= '0' && c <= '9';
+}
+
+static bool hex_digit(char c)
+{
+ return decimal(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+}
+
+static bool host_char(char c)
+{
+ return decimal(c) || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
+ c == '-';
+}
+
+/* A label an address parser takes for a number: decimal, or 0x and hex. */
+static bool numeric_label(const char *s, size_t n)
+{
+ bool dec = n, hex = n > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X');
+ size_t i;
+
+ for (i = 0; i < n; i++) {
+ dec = dec && decimal(s[i]);
+ hex = hex && (i < 2 || hex_digit(s[i]));
+ }
+ return dec || hex;
+}
+
+static bool label_valid(const char *s, size_t n)
+{
+ size_t i;
+
+ if (!n || n > LABEL_MAX || s[0] == '-' || s[n - 1] == '-')
+ return false;
+ for (i = 0; i < n; i++)
+ if (!host_char(s[i]))
+ return false;
+ return true;
+}
+
+/* Labels apart by single dots, not all of them numeric. */
+static bool name_valid(const char *s, size_t len)
{
- char *val = any_string();
- size_t start, i;
+ bool numeric = true;
+ size_t start = 0, i;
+
+ if (!len || len > NAME_MAX_LEN)
+ return false;
+ for (i = 0; i <= len; i++) {
+ if (i < len && s[i] != '.')
+ continue;
+ if (!label_valid(s + start, i - start))
+ return false;
+ numeric = numeric && numeric_label(s + start, i - start);
+ start = i + 1;
+ }
+ return !numeric;
+}
+
+static void names(void)
+{
+ char *name = any_name();
+
+ __CPROVER_assert(dns_name_valid(name) ==
+ name_valid(name, strlen(name)),
+ "a host name of labels, not a numeric address");
+}
- if (!tls_classical_hosts_valid(val) || !*val)
- return;
- for (start = 0; ; start = i + 1) {
- char name[LEN + 1] = {};
+/* Empty, or names of one byte or more apart by single commas. */
+static bool hosts_valid(const char *val, size_t len)
+{
+ size_t start = 0, i;
- for (i = start; val[i] && val[i] != ','; i++)
- name[i - start] = val[i];
- __CPROVER_assert(dns_name_valid(name), "DNS names");
- if (!val[i])
- break;
+ if (!len)
+ return true;
+ for (i = 0; i <= len; i++) {
+ if (i < len && val[i] != ',')
+ continue;
+ if (!name_valid(val + start, i - start))
+ return false;
+ start = i + 1;
}
+ return true;
+}
+
+static void hosts(void)
+{
+ char *val = any_bytes(LEN + 1);
+
+ val[LEN] = '\0';
+ __CPROVER_assert(tls_classical_hosts_valid(val) ==
+ hosts_valid(val, strlen(val)),
+ "empty, or names apart by single commas");
+}
+
+void harness(void)
+{
+ names();
+ hosts();
}