strawberry/fuzz/fuzz_governor_parsers.cpp
trvon a1d77dda9a
governor: fail-safe host pressure, diagnostic diskstats, capped scan buffers
Host pressure stays fail-safe: any of CPU/I/O/memory PSI above its profile
threshold, or low MemAvailable, still defers background work and can degrade
the exec guard. That is deliberate — global I/O PSI also counts waits with no
block-device counter (FUSE/network-backed I/O, display page flips), so idle
disks never prove pressure is benign. An audit of an earlier version that
vetoed I/O PSI below 5% block utilization rejected it on exactly that basis.

/proc/diskstats is therefore diagnostic telemetry only, exposed as
host.block_io_util_pct. It is keyed by major:minor so a reused device name
cannot compare unrelated counters, and reports unknown (-1) for the first
sample, a new/replaced/reset device, or an oversized read, instead of a false
0%.

scan_buffer_budget() now derives from the same effective budget that pressure
uses — the configured/profile budget capped by cgroup memory.max — with the
existing 32 MiB floor, so a cgroup-capped daemon cannot be granted scan
buffers larger than its own limit. Lock order stays mutex_ -> buffer_mutex_.

Tests: deterministic fail-safe cases across every diskstat value, the
new-device regression, scanner budget under a 100 MiB cgroup cap, and a seeded
property asserting severe I/O PSI always holds work whatever diskstats says.
2026-11-17 13:45:07 -07:00

27 lines
1.2 KiB
C++

// /proc, PSI and cgroup text parsers used by the resource governor.
#include "strawberry/resource_governor.hpp"
#include <cstdint>
#include <cstdlib>
#include <string_view>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
const std::string_view text(reinterpret_cast<const char*>(data), size);
using namespace strawberry;
if (auto v = parse_psi_some_avg10(text); v && (*v < 0 || *v > 100)) std::abort();
if (auto v = parse_loadavg_1m(text); v && *v < 0) std::abort();
if (auto m = parse_meminfo(text); m && m->total_bytes == 0) std::abort();
if (auto c = parse_proc_stat(text); c && c->online_cpus == 0) std::abort();
if (auto d = parse_proc_diskstats(text)) {
if (d->empty()) std::abort();
for (const auto& entry : *d) {
if (entry.name.empty()) std::abort();
}
}
(void) parse_self_stat_cpu(text);
(void) parse_status_rss(text);
if (auto p = parse_cgroup_v2_path(text); p && (p->empty() || p->front() != '/' || p->find("..") != std::string::npos)) std::abort();
if (auto m = parse_cgroup_memory_max(text); m && *m == 0) std::abort();
if (auto c = parse_cgroup_cpu_max(text); c && *c <= 0) std::abort();
return 0;
}