Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / macos (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
A promoted model (promoted.sbm, written only by `model promote` after the gate) can now request real inspections. Only two, both additive: - memory_scan: through the daemon's memory-scan queue; - deep_rescan: the root's image re-scanned on demand; new matches are recorded as indicators of kind model_inspection (findings titled "YARA match found by a deeper rescan the inspection model requested") and positive labels. watch_subtree has no mechanism and rescan_on_next_rules is the retro-hunt's job, so both are masked out of acting decisions (kExecutableActions), and replay's policy evaluation uses the same action set. Guardrails: - InspectionExecutor (bounded queue, one low-priority worker, submit() never blocks); WorkClass::model_inspect lets the governor defer it, and a deferred decision is dropped. - Each action rechecks that the promoted model is still active at the decision's generation (demoting or replacing it revokes queued work), that the root's node id and raw image path still match (decisions carry root_image, not the feature template), and skips protected processes. A deep rescan discards its result if the process, image or rules changed during the scan. - An acting decision is durably written before it is dispatched; every attempt becomes an inspection_outcome record (queued, scanned, skipped, deferred, revoked, queue_full, failed). - Source invariant R10: no file may couple learning types to the exec-guard, OpenSnitch or policy APIs (daemon_app.cpp and main.cpp, the wiring points, are reviewed by hand). Models never block, contain, kill or create findings directly. - Config model_act and model_lambda; status model block reports acting stats; timings.model_inspection. docs/evaluation/stage4-execution-gate.md amends the gate's method (not its thresholds): executable action set, greedy promoted decisions, budgets as estimated inspection seconds by scan profile. Also: TerminalSafeBuf's destructor no longer lets an exception escape; the health message clamps huge durations; replay timestamp overflow; the Docker test build runs with -j2. Tests: test_inspection_executor (every skip and execute path, revocation, queue limits); shadow and replay acting cases; R10 fixture; fault injection and invariant updates. Validation reported by the session that wrote it: 48/48 local, 46/46 Docker plus privileged live checks, 20 fuzz targets (9.5M runs), three paired KPI runs without regressions (no acting model was loaded, so active-inspection cost is not measured yet). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
4 KiB
C++
94 lines
4 KiB
C++
// Telemetry record decoders (exec, scan, rule match, label, generations, lifecycle, governor, behavior, file write, guard) over untrusted bytes:
|
|
// never crash; what they accept re-encodes and decodes to the same values.
|
|
|
|
#include "strawberry/telemetry.hpp"
|
|
#include "strawberry/learn/shadow.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
using namespace strawberry;
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|
const std::string_view in(reinterpret_cast<const char*>(data), size);
|
|
ProcessExecRecord e, e2;
|
|
if (decode_process_exec(in, e)) {
|
|
if (!decode_process_exec(encode_process_exec(e), e2)) __builtin_trap();
|
|
if (e2.pid != e.pid || e2.uid != e.uid || e2.comm != e.comm || e2.exe != e.exe || e2.sha256 != e.sha256 || e2.source != e.source ||
|
|
e2.cmdline != e.cmdline.substr(0, kMaxTelemetryCmdline)) {
|
|
__builtin_trap();
|
|
}
|
|
}
|
|
ScanResultRecord s, s2;
|
|
if (decode_scan_result(in, s)) {
|
|
if (!decode_scan_result(encode_scan_result(s), s2)) __builtin_trap();
|
|
if (s2.outcome != s.outcome || s2.rules != s.rules || s2.pid != s.pid) __builtin_trap();
|
|
}
|
|
RuleMatchRecord r, r2;
|
|
if (decode_rule_match(in, r)) {
|
|
if (!decode_rule_match(encode_rule_match(r), r2) || r2.strings != r.strings || r2.rule != r.rule ||
|
|
r2.pid != r.pid) {
|
|
__builtin_trap();
|
|
}
|
|
}
|
|
LabelRecord l, l2;
|
|
if (decode_label(in, l)) {
|
|
if (!decode_label(encode_label(l), l2) || l2.polarity != l.polarity || l2.uid != l.uid || l2.rule != l.rule) {
|
|
__builtin_trap();
|
|
}
|
|
}
|
|
RulesGenerationRecord rg, rg2;
|
|
if (decode_rules_generation(in, rg)) {
|
|
if (!decode_rules_generation(encode_rules_generation(rg), rg2) || rg2.sources != rg.sources) __builtin_trap();
|
|
}
|
|
PolicyGenerationRecord pg, pg2;
|
|
if (decode_policy_generation(in, pg)) {
|
|
if (!decode_policy_generation(encode_policy_generation(pg), pg2) || pg2.uid != pg.uid) __builtin_trap();
|
|
}
|
|
LifecycleRecord lc, lc2;
|
|
if (decode_lifecycle(in, lc)) {
|
|
if (!decode_lifecycle(encode_lifecycle(lc), lc2) || lc2.event != lc.event || lc2.pid != lc.pid) __builtin_trap();
|
|
}
|
|
GovernorSampleRecord gs, gs2;
|
|
if (decode_governor_sample(in, gs)) {
|
|
if (!decode_governor_sample(encode_governor_sample(gs), gs2) || gs2.admitted != gs.admitted ||
|
|
gs2.own_cpu_centi != gs.own_cpu_centi) {
|
|
__builtin_trap();
|
|
}
|
|
}
|
|
learn::InspectionDecision ia, ia2;
|
|
if (learn::decode_inspection_action(in, ia)) {
|
|
// Bytes, not values: fuzzed floats can be NaN.
|
|
const auto once = learn::encode_inspection_action(ia);
|
|
if (!learn::decode_inspection_action(once, ia2) || learn::encode_inspection_action(ia2) != once) {
|
|
__builtin_trap();
|
|
}
|
|
}
|
|
learn::InspectionOutcome outcome, outcome2;
|
|
if (learn::decode_inspection_outcome(in, outcome)) {
|
|
const auto once = learn::encode_inspection_outcome(outcome);
|
|
if (!learn::decode_inspection_outcome(once, outcome2) || learn::encode_inspection_outcome(outcome2) != once) {
|
|
__builtin_trap();
|
|
}
|
|
}
|
|
for (const auto type : {store::RecordType::connect, store::RecordType::ptrace, store::RecordType::module_load}) {
|
|
BehaviorEvent b, b2;
|
|
if (decode_behavior(type, in, b)) {
|
|
if (!decode_behavior(type, encode_behavior(b), b2)) __builtin_trap();
|
|
if (b2.pid != b.pid || b2.uid != b.uid || b2.timestamp_ns != b.timestamp_ns) __builtin_trap();
|
|
}
|
|
}
|
|
FileWriteEvent w, w2;
|
|
if (decode_file_write(in, w)) {
|
|
if (!decode_file_write(encode_file_write(w), w2) || w2.path != w.path || w2.pid != w.pid) __builtin_trap();
|
|
}
|
|
GuardObservation g, g2;
|
|
uint64_t t = 0, t2 = 0;
|
|
if (decode_guard_decision(in, g, t)) {
|
|
if (!decode_guard_decision(encode_guard_decision(g, t), g2, t2) || t2 != t || g2.verdict != g.verdict ||
|
|
g2.path != g.path) {
|
|
__builtin_trap();
|
|
}
|
|
}
|
|
return 0;
|
|
}
|