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:
@@ -10,6 +10,7 @@
|
||||
#include "evo/server/region_sessions.hpp"
|
||||
#include "fixtures/fake_handoff_world.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <expected>
|
||||
@@ -944,6 +945,262 @@ void durable_control(const Files& f) {
|
||||
return std::ranges::find(ledger.released, alice_generation) != ledger.released.end();
|
||||
}));
|
||||
}
|
||||
|
||||
// M10.9c (ADR-0097): abuse against one region while an honest session is measured. Each
|
||||
// round is one 50 ms tick: the abuse acts, the honest client sends one intention, and the
|
||||
// server replicates. The honest session must keep at least 90 % of its snapshots and
|
||||
// receipts, and the server's connections and retained state must stay bounded.
|
||||
struct Service {
|
||||
std::uint64_t ticks{}, views{}, sent{}, receipts{};
|
||||
};
|
||||
Service serve(Harness& h, RegionSessionClient& honest, std::size_t rounds,
|
||||
const std::function<void(std::size_t)>& abuse) {
|
||||
Service out;
|
||||
std::uint64_t last_view = honest.view() ? honest.view()->tick : 0;
|
||||
for (std::size_t round = 0; round < rounds; ++round) {
|
||||
++h.tick;
|
||||
++out.ticks;
|
||||
abuse(round);
|
||||
if (honest.send_intention(h.tick + 2, 100, 0))
|
||||
++out.sent;
|
||||
const auto end = Clock::now() + std::chrono::milliseconds{50};
|
||||
while (Clock::now() < end) {
|
||||
h.pump();
|
||||
for (const auto& r : honest.take_intention_receipts())
|
||||
out.receipts += r.status == AdmitStatus::admitted;
|
||||
if (const auto* v = honest.view(); v && v->tick != last_view) {
|
||||
last_view = v->tick;
|
||||
++out.views;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds{1});
|
||||
}
|
||||
}
|
||||
std::printf(
|
||||
"abuse service ticks=%llu views=%llu sent=%llu admitted=%llu\n",
|
||||
static_cast<unsigned long long>(out.ticks), static_cast<unsigned long long>(out.views),
|
||||
static_cast<unsigned long long>(out.sent), static_cast<unsigned long long>(out.receipts));
|
||||
return out;
|
||||
}
|
||||
bool served(const Service& s) {
|
||||
return s.views * 10 >= s.ticks * 9 && s.sent * 10 >= s.ticks * 9 &&
|
||||
s.receipts * 10 >= s.sent * 9;
|
||||
}
|
||||
std::unique_ptr<RegionSessionClient> honest_session(Harness& h) {
|
||||
h.source = [&h](const SessionInterest&) {
|
||||
ReplicationSource s;
|
||||
s.identity = world_id;
|
||||
s.field_revision = h.tick;
|
||||
s.mask = (1U << 0) | (1U << 1) | (1U << 7);
|
||||
for (std::int64_t x = -3; x <= 3; ++x)
|
||||
for (std::int64_t y = -3; y <= 3; ++y)
|
||||
s.environment.push_back(grid_cell(x, y, 30 + (h.tick % 7)));
|
||||
return s;
|
||||
};
|
||||
h.server->set_default_interest({0, 0, -7, 7});
|
||||
auto c = h.connect(h.issuer.grant(account(0xA0), 1));
|
||||
CHECK(h.settled(*c) && c->state() == RegionSessionState::established);
|
||||
// Wait for the datagram channel and the first snapshot.
|
||||
CHECK(h.until([&] {
|
||||
++h.tick;
|
||||
return c->view() != nullptr && c->send_intention(h.tick + 2, 0, 0).has_value();
|
||||
}));
|
||||
return c;
|
||||
}
|
||||
|
||||
// Handshake and Hello floods: many connections that send garbage, forged or no Hello. They
|
||||
// are closed (protocol, unauthenticated, timeout) or refused at the connection limit; the
|
||||
// region's connections never exceed the transport bound; the honest session is served.
|
||||
void hello_flood(const Files& f) {
|
||||
Harness h{f, 4, 64};
|
||||
auto honest = honest_session(h);
|
||||
// A key the region does not trust (key id 7): its well-formed grants are refused.
|
||||
const auto stranger = *GrantSigningKey::import(DeploymentEnvironment::dev, 7, [] {
|
||||
std::array<std::uint8_t, grant_private_key_bytes> s{};
|
||||
s.back() = 0x2B;
|
||||
return s;
|
||||
}());
|
||||
// Every peer is polled each round and acts once connected: 0 sends garbage, 1 a
|
||||
// well-formed Hello whose grant no trusted key signed, 2 stays silent until the deadline.
|
||||
struct Peer {
|
||||
std::unique_ptr<quic::Endpoint> endpoint;
|
||||
std::size_t kind{};
|
||||
};
|
||||
std::vector<Peer> peers;
|
||||
std::size_t most_connections = 0;
|
||||
std::array<unsigned, 3> acted{};
|
||||
unsigned sent = 0;
|
||||
const auto service = serve(h, *honest, 60, [&](std::size_t round) {
|
||||
if (round < 40)
|
||||
for (std::size_t k = 0; k < 4; ++k)
|
||||
peers.push_back({h.raw(), (round * 4 + k) % 3});
|
||||
for (auto& peer : peers)
|
||||
for (auto& e : peer.endpoint->poll()) {
|
||||
if (e.kind != quic::EventKind::connected)
|
||||
continue;
|
||||
++acted.at(peer.kind);
|
||||
if (peer.kind == 0)
|
||||
sent += peer.endpoint
|
||||
->send_message(e.connection, std::vector<std::uint8_t>{9, 9, 9, 9})
|
||||
.has_value();
|
||||
if (peer.kind == 1) {
|
||||
GrantClaims c;
|
||||
c.grant_id = 9000 + round;
|
||||
c.account = account(0xF0);
|
||||
c.serial = 1;
|
||||
c.world = world_id;
|
||||
c.region = region;
|
||||
c.issued_at = start;
|
||||
c.expires_at = start + 60;
|
||||
sent += peer.endpoint
|
||||
->send_message(e.connection,
|
||||
encode_session(SessionHello{0, *stranger.sign(c)}))
|
||||
.has_value();
|
||||
}
|
||||
}
|
||||
most_connections = std::max(most_connections, h.server->connections());
|
||||
});
|
||||
std::printf("abuse hello_flood peers=%zu most_connections=%zu connected garbage=%u "
|
||||
"forged=%u silent=%u\n",
|
||||
peers.size(), most_connections, acted[0], acted[1], acted[2]);
|
||||
CHECK(sent == acted[0] + acted[1]); // Every garbage and forged message went out.
|
||||
CHECK(served(service) && honest->state() == RegionSessionState::established);
|
||||
CHECK(most_connections <= server::RegionSessionsConfig{}.transport.limits.max_connections);
|
||||
peers.clear();
|
||||
CHECK(h.until([&] { return h.server->connections() == 1; }));
|
||||
std::map<unsigned, unsigned> reasons;
|
||||
for (const auto& e : h.events)
|
||||
if (e.kind == RegionSessionEvent::Kind::refused)
|
||||
++reasons[static_cast<unsigned>(e.reason)];
|
||||
for (const auto& [why, n] : reasons)
|
||||
std::printf("abuse hello_flood refused reason=%u count=%u\n", why, n);
|
||||
CHECK(h.has_event(RegionSessionEvent::Kind::refused, Reason::protocol) &&
|
||||
h.has_event(RegionSessionEvent::Kind::refused, Reason::unauthenticated) &&
|
||||
h.has_event(RegionSessionEvent::Kind::refused, Reason::timeout));
|
||||
}
|
||||
|
||||
// Datagram flood from an authenticated peer: hundreds of intentions per tick for any tick
|
||||
// (throttled per session: one per tick), then garbage, which closes it (protocol). The
|
||||
// honest session keeps its receipts and snapshots.
|
||||
void datagram_flood(const Files& f) {
|
||||
Harness h{f, 4, 64};
|
||||
auto honest = honest_session(h);
|
||||
auto peer = h.raw();
|
||||
quic::ConnectionId id = 0;
|
||||
bool welcomed = false, closed = false;
|
||||
std::optional<Reason> reason;
|
||||
std::uint64_t flood = 0, refused = 0, garbage = 0;
|
||||
const auto drain = [&] {
|
||||
for (auto& e : peer->poll()) {
|
||||
if (e.kind == quic::EventKind::connected) {
|
||||
id = e.connection;
|
||||
CHECK(peer->send_message(
|
||||
id, encode_session(SessionHello{0, h.issuer.grant(account(0xB0), 1)}))
|
||||
.has_value());
|
||||
} else if (e.kind == quic::EventKind::message || e.kind == quic::EventKind::datagram) {
|
||||
const auto m = decode_session(e.bytes);
|
||||
if (m && std::holds_alternative<SessionWelcome>(*m))
|
||||
welcomed = true;
|
||||
if (m && std::holds_alternative<IntentionReceipt>(*m))
|
||||
refused += std::get<IntentionReceipt>(*m).status != AdmitStatus::admitted;
|
||||
if (m && std::holds_alternative<SessionClose>(*m))
|
||||
reason = std::get<SessionClose>(*m).reason;
|
||||
} else if (e.kind == quic::EventKind::closed) {
|
||||
closed = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
CHECK(h.until([&] {
|
||||
drain();
|
||||
return welcomed;
|
||||
}));
|
||||
std::uint64_t sequence = 0;
|
||||
const auto service = serve(h, *honest, 40, [&](std::size_t round) {
|
||||
drain();
|
||||
if (round < 30)
|
||||
for (int k = 0; k < 400; ++k) {
|
||||
SessionIntention in;
|
||||
in.sequence = ++sequence;
|
||||
in.tick = h.tick + 1 + static_cast<std::uint64_t>(k % 8);
|
||||
in.move_x = 100;
|
||||
flood += peer->send_datagram(id, encode_session(in)).has_value();
|
||||
}
|
||||
if (round == 30)
|
||||
for (int k = 0; k < 50; ++k)
|
||||
garbage += peer->send_datagram(id, std::vector<std::uint8_t>(64, 0xEE)).has_value();
|
||||
});
|
||||
CHECK(h.until([&] {
|
||||
drain();
|
||||
return closed || reason.has_value();
|
||||
}));
|
||||
std::printf("abuse datagram_flood sent=%llu refused_receipts=%llu close=%u\n",
|
||||
static_cast<unsigned long long>(flood), static_cast<unsigned long long>(refused),
|
||||
static_cast<unsigned>(reason.value_or(Reason::connection_lost)));
|
||||
CHECK(served(service) && honest->state() == RegionSessionState::established);
|
||||
CHECK(flood > 1000 && garbage > 0 && reason == Reason::protocol);
|
||||
}
|
||||
|
||||
// A slow peer: established, then never polled (it reads nothing and acknowledges no
|
||||
// snapshot). The server keeps at most its baselines for it and stays bounded; the honest
|
||||
// session is served throughout.
|
||||
void slow_peer(const Files& f) {
|
||||
Harness h{f, 4, 64};
|
||||
auto honest = honest_session(h);
|
||||
auto slow = h.connect(h.issuer.grant(account(0xC0), 1));
|
||||
CHECK(h.settled(*slow) && slow->state() == RegionSessionState::established);
|
||||
CHECK(slow->set_interest({0, 0, -7, 7}));
|
||||
h.forget(slow.get()); // From now on nobody polls it.
|
||||
std::size_t most_retained = 0;
|
||||
const auto service = serve(h, *honest, 80, [&](std::size_t) {
|
||||
most_retained = std::max(most_retained, h.server->replication_stats().retained_entities);
|
||||
});
|
||||
std::printf("abuse slow_peer most_retained_entities=%zu sessions=%zu\n", most_retained,
|
||||
h.server->sessions());
|
||||
CHECK(served(service) && honest->state() == RegionSessionState::established);
|
||||
// Two sessions, 49 cells each, at most 4 baselines (ADR-0089) plus the working state.
|
||||
CHECK(most_retained <= std::size_t{2} * 49 * 5);
|
||||
slow.reset();
|
||||
CHECK(h.until([&] { return h.server->sessions() == 1; }, std::chrono::milliseconds{15000}));
|
||||
}
|
||||
|
||||
// Connect/disconnect storm: 120 logins across 12 accounts, each closed politely or dropped
|
||||
// mid-session; the region returns to the honest session alone, which is served throughout.
|
||||
void storm(const Files& f) {
|
||||
Harness h{f, 8, 1024};
|
||||
auto honest = honest_session(h);
|
||||
std::vector<std::unique_ptr<RegionSessionClient>> live;
|
||||
std::array<std::uint64_t, 12> serials{};
|
||||
std::uint64_t opened = 0;
|
||||
const auto service = serve(h, *honest, 60, [&](std::size_t round) {
|
||||
if (round >= 40)
|
||||
return;
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
const auto who = (round * 3 + static_cast<std::size_t>(k)) % serials.size();
|
||||
auto c = h.connect(
|
||||
h.issuer.grant(account(static_cast<std::uint8_t>(0xD0 + who)), ++serials.at(who)));
|
||||
live.push_back(std::move(c));
|
||||
}
|
||||
// Older ones leave: politely, or by vanishing (the transport notices).
|
||||
while (live.size() > 6) {
|
||||
auto& c = live.front();
|
||||
opened += c->state() == RegionSessionState::established;
|
||||
if (opened % 2 == 0)
|
||||
c->close();
|
||||
h.forget(c.get());
|
||||
live.erase(live.begin());
|
||||
}
|
||||
});
|
||||
for (auto& c : live) {
|
||||
h.forget(c.get());
|
||||
c->close();
|
||||
}
|
||||
live.clear();
|
||||
std::printf("abuse storm logins=120 established_seen=%llu\n",
|
||||
static_cast<unsigned long long>(opened));
|
||||
CHECK(served(service) && honest->state() == RegionSessionState::established);
|
||||
CHECK(opened > 20);
|
||||
CHECK(h.until([&] { return h.server->sessions() == 1 && h.server->connections() == 1; },
|
||||
std::chrono::milliseconds{15000}));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
@@ -955,6 +1212,10 @@ int main() try {
|
||||
snapshots_over_quic(files);
|
||||
ticket_login(files);
|
||||
two_region_handoff(files);
|
||||
hello_flood(files);
|
||||
datagram_flood(files);
|
||||
slow_peer(files);
|
||||
storm(files);
|
||||
std::filesystem::remove_all(files.dir);
|
||||
std::puts("quic session tests passed");
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user