Add M10.9c-1 session fuzzing and in-process abuse tests
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Successful in 17s
Foundation / checks (ecs) (push) Successful in 12s
Foundation / checks (client) (push) Successful in 1m47s
Foundation / checks (tsan) (push) Successful in 5m44s
Foundation / checks (network) (push) Successful in 13m29s
Foundation / checks (postgres) (push) Successful in 44m22s
Foundation / server-image (push) Successful in 31s
Foundation / postgres-tools (push) Successful in 1m34s
Foundation / image (push) Successful in 2m37s
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Successful in 17s
Foundation / checks (ecs) (push) Successful in 12s
Foundation / checks (client) (push) Successful in 1m47s
Foundation / checks (tsan) (push) Successful in 5m44s
Foundation / checks (network) (push) Successful in 13m29s
Foundation / checks (postgres) (push) Successful in 44m22s
Foundation / server-image (push) Successful in 31s
Foundation / postgres-tools (push) Successful in 1m34s
Foundation / image (push) Successful in 2m37s
ADR-0097. A libFuzzer target for session protocol v4, grants, tickets and snapshot assembly (canonical re-encoding, verifiers always refuse, a completed snapshot is applied), with the code under test compiled in, and a seeded smoke CTest of the same target on every platform. Four quic-sessions abuse tests measure an honest session tick by tick under a Hello flood (garbage, untrusted grants, silence), a datagram flood, a slow peer and a connect/disconnect storm; it keeps every snapshot and receipt while connections and retained state stay bounded. evo-session-probe run --grants FILE [--grant N] logs in from an existing bundle (a dev renewal's) without an issuer key. client_lifecycle uses SDL_getenv (MSVC rejected std::getenv). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
// M10.9c (ADR-0097) session protocol v4 fuzz target. Any input:
|
||||
// - decoding never crashes, and an accepted message has a stable canonical form
|
||||
// (decode, encode, decode, encode gives the same bytes: no field is silently dropped);
|
||||
// - an accepted snapshot chunk reaches the client's assembler without crashing;
|
||||
// - grant and ticket verification refuse it (no claim byte is trusted before the
|
||||
// signature: a fuzzer cannot forge ECDSA), also for the grant slot of a decoded Hello.
|
||||
// Built as a libFuzzer target with EVO_BUILD_FUZZER (Linux Clang) and as a seeded smoke
|
||||
// test everywhere (tests/fuzz/session_fuzz_smoke.cpp).
|
||||
#include "evo/network/handoff_ticket.hpp"
|
||||
#include "evo/network/replication.hpp"
|
||||
#include "evo/network/session_grant.hpp"
|
||||
#include "evo/network/session_protocol.hpp"
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace evo::network;
|
||||
constexpr evo::world::WorldIdentity world{9, 2};
|
||||
constexpr std::uint64_t region = 21;
|
||||
constexpr std::uint64_t now = 1'000'000;
|
||||
|
||||
// Verifiers holding one fixed, valid key each (the fuzzer never has its private half).
|
||||
struct Verifiers {
|
||||
std::optional<GrantVerifier> grants;
|
||||
std::optional<HandoffVerifier> tickets;
|
||||
Verifiers() {
|
||||
std::array<std::uint8_t, grant_private_key_bytes> scalar{};
|
||||
scalar.back() = 0x2A;
|
||||
const auto issuer = GrantSigningKey::import(DeploymentEnvironment::dev, 1, scalar);
|
||||
auto g = GrantVerifier::create(DeploymentEnvironment::dev);
|
||||
if (!issuer || !g || !g->add_key(1, *issuer->public_key()))
|
||||
std::abort();
|
||||
grants.emplace(std::move(*g));
|
||||
const auto source = HandoffSigningKey::import(DeploymentEnvironment::dev, 4, scalar);
|
||||
auto t = HandoffVerifier::create(DeploymentEnvironment::dev, world, region);
|
||||
if (!source || !t || !t->add_key(4, 4, *source->public_key()))
|
||||
std::abort();
|
||||
tickets.emplace(std::move(*t));
|
||||
}
|
||||
};
|
||||
const Verifiers& verifiers() {
|
||||
static const Verifiers v;
|
||||
return v;
|
||||
}
|
||||
void refused(std::span<const std::uint8_t> bytes) {
|
||||
const auto& v = verifiers();
|
||||
if (!v.grants || !v.tickets || v.grants->verify(bytes) || v.tickets->verify(bytes, now))
|
||||
std::abort();
|
||||
(void)looks_like_handoff_ticket(bytes);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size) {
|
||||
const std::span<const std::uint8_t> bytes{data, size};
|
||||
refused(bytes);
|
||||
const auto decoded = decode_session(bytes);
|
||||
if (!decoded)
|
||||
return 0;
|
||||
const auto canonical = encode_session(*decoded);
|
||||
const auto again = decode_session(canonical);
|
||||
if (!again || encode_session(*again) != canonical)
|
||||
std::abort();
|
||||
if (const auto* hello = std::get_if<SessionHello>(&*decoded))
|
||||
refused(hello->grant);
|
||||
if (const auto* chunk = std::get_if<SnapshotChunk>(&*decoded)) {
|
||||
SnapshotAssembler client{world, chunk->epoch};
|
||||
if (const auto accepted = client.accept(*chunk);
|
||||
accepted && *accepted && client.latest() == nullptr)
|
||||
std::abort(); // A completed snapshot must be applied.
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// Seeded smoke run of the session fuzz target (tests/fuzz/session_fuzz.cpp) on every
|
||||
// platform: random inputs, and mutations (bit flips, truncation, extension, byte
|
||||
// overwrites) of a valid encoding of every v4 message type.
|
||||
#include "evo/core/random.hpp"
|
||||
#include "evo/network/session_protocol.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t*, std::size_t);
|
||||
|
||||
namespace {
|
||||
using namespace evo::network;
|
||||
template <std::size_t... I>
|
||||
std::vector<std::vector<std::uint8_t>> seeds(std::index_sequence<I...>) {
|
||||
return {encode_session(SessionMessage{std::in_place_index<I>})...};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
auto corpus = seeds(std::make_index_sequence<std::variant_size_v<SessionMessage>>{});
|
||||
std::size_t decodable = 0;
|
||||
for (const auto& s : corpus)
|
||||
decodable += decode_session(s).has_value();
|
||||
evo::Random random{20261007};
|
||||
const auto next = [&](std::size_t below) {
|
||||
return static_cast<std::size_t>(random.next() % std::max<std::size_t>(below, 1));
|
||||
};
|
||||
std::size_t inputs = 0;
|
||||
for (int round = 0; round < 4000; ++round) {
|
||||
for (const auto& seed : corpus) {
|
||||
auto input = seed;
|
||||
switch (next(5)) {
|
||||
case 0: // Flip bits.
|
||||
for (std::size_t k = 0, n = 1 + next(4); k < n && !input.empty(); ++k)
|
||||
input[next(input.size())] ^= static_cast<std::uint8_t>(1U << next(8));
|
||||
break;
|
||||
case 1: // Truncate.
|
||||
input.resize(next(input.size() + 1));
|
||||
break;
|
||||
case 2: // Extend.
|
||||
for (std::size_t k = 0, n = 1 + next(32); k < n; ++k)
|
||||
input.push_back(static_cast<std::uint8_t>(next(256)));
|
||||
break;
|
||||
case 3: // Overwrite a byte with an edge value.
|
||||
if (!input.empty())
|
||||
input[next(input.size())] =
|
||||
std::array<std::uint8_t, 4>{0, 1, 0x7F, 0xFF}[next(4)];
|
||||
break;
|
||||
default: // Random bytes.
|
||||
input.assign(next(300), 0);
|
||||
for (auto& b : input)
|
||||
b = static_cast<std::uint8_t>(next(256));
|
||||
}
|
||||
if (LLVMFuzzerTestOneInput(input.data(), input.size()) != 0)
|
||||
return 1;
|
||||
++inputs;
|
||||
}
|
||||
}
|
||||
std::printf("session fuzz smoke inputs=%zu seeds=%zu decodable_seeds=%zu\n", inputs,
|
||||
corpus.size(), decodable);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user