# Verification of `audit-results-opus-4.8-max.md` against source Reviewer pass: Opus 4.8 (max effort). Each finding below was traced end-to-end in the current source tree. Verdicts: **REAL** (true positive), **FALSE POSITIVE**, or **UNCONFIRMED** (plausible, no demonstrated trigger). Threat model honored as stated in `README-AUDIT.md`: protected client VM untrusted; local `user`/root in `sys-snitch`, dom0, qrexec policy, and manual YAML trusted. Confirmed environment facts used by all three findings: * `templates/etc/systemd/system/qubes-snitchd.service:21` — `Restart=no`. * `qubes-snitchd.service:20` + `stop-post.sh` — every daemon exit re-runs `nft -f .../fail-closed.nft`, so any crash leaves the VM permanently fail-closed (no auto-recovery) until a manual restart. Verified `stop-post.sh` re-applies fail-closed and notifies `-u critical` on non-success. * `qubes-snitchd.py:6-10` and `daemon_runtime.main()` (160-176) — `main()` has no top-level `try/except`; an unhandled exception on the main thread ends the process. --- ## Finding 1 — uppercase `A`/`R` decision can crash the daemon on DNS variance — **REAL (True Positive)** **Mechanism fully confirmed.** Trace: 1. CLI `qubes-snitch.py:ask()` (58-83) returns `"allow-dns"` on key `A` and `"reject-dns"` on key `R`, gated on `_resolved_dests` being present, which `add_hostname_choices()` (44-55) sets only when its *own* live `resolve_hostname_ips()` (31-41, `lifetime=3.0`) returns `len(ips) > 1 and request["dst"] in ips`. So the trigger is reachable exactly as described. 2. Daemon accepts `allow-dns`/`reject-dns` (`queue.py:145`) and calls `save_pending_decision()` (149). 3. `save_pending_decision()` (`queue.py:114-116`) calls `prepare_hostname_decision()` **before** taking `policy_lock`. 4. `prepare_hostname_decision()` (`queue.py:83-94`) runs a **second, fresh** live `config.resolve_dest_dns("prompt", hostname)` (91), then requires `len(resolved) > 1 and request["dst"] in resolved` (92-93). 5. `resolve_dest_dns()` (`config.py:257-276`) raises **`SystemExit`** on any resolver exception (261-262), on a non-IPv4 answer (271), and on empty result (274-275); `prepare_hostname_decision()` itself raises `SystemExit` (93) when the fresh set is `<= 1` or no longer contains `dst`. 6. That `SystemExit` (a `BaseException`) is not caught in `queue.py`; it propagates to `daemon_runtime.handle_cli_connection` (99-103) whose `except BaseException` → `alerts_runtime.fatal_security_alert()` → `fail_daemon()` (`alerts_runtime.py:120-124`). Because `cli_server` runs on a **daemon worker thread** (`daemon_runtime.py:172`), `fail_daemon` takes the `os._exit(1)` branch and kills the whole process. Result: whole-daemon death → `Restart=no` + `ExecStopPost` fail-closed → all downstream VMs lose network until manual restart. Confirmed. **Assessment of the trigger realism (audit is correct):** there are now effectively *two* independent 3-second resolutions — the CLI's at display time and the daemon's at decision time — separated by human reaction latency. For a round-robin / short-TTL CDN (the README's own worked example is `updates.signal.org`), the decision-time set can legitimately shrink to one IP, rotate `dst` out, or transiently SERVFAIL/time out. The `reject` (`R`) case is genuinely perverse: pressing `R` to *block* a suspicious multi-IP host takes the firewall offline if the resolver is momentarily slow. The design intent elsewhere is clearly the opposite of "crash": `queue.handle_cli_connection` already keeps the prompt pending for invalid answers (145-148) and socket `OSError` (142-144). The `prepare_hostname_decision` `SystemExit` simply escapes that non-fatal contract. **Nuances / corrections:** * Attacker amplification is real but **user-interaction-gated and probabilistic**, not deterministic: the crash still requires the trusted user to press `A`/`R`, and the attacker cannot time DNS flapping to the exact keypress (only raise the odds by making an allowed attacker-domain flap). The audit states this fairly ("user-interaction-gated but attacker-influenced"). It also fires with no attacker under ordinary jitter. * Severity **High is defensible** given impact (persistent whole-VM fail-closed, manual recovery). The one mitigating factor to keep in mind is that it is not passive/remote — it needs the user to exercise the opt-in uppercase feature. Remediation in the audit (catch `SystemExit` around `prepare_hostname_decision` and keep the prompt pending, or give the decision path a non-fatal resolver variant) is correct and matches the existing "keep pending" contract. --- ## Finding 2 — any saved `dest_dns` rule bricks the daemon on next start — **REAL (True Positive); the strongest of the three** **Mechanism fully confirmed, and it is deterministic.** Trace: 1. Startup order in `daemon_runtime.main()`: * `policy_runtime.load_policy_without_sources()` at **line 170** → `config.load_rules()`. * `sources_runtime.refresh_sources_required()` at **line 173** → `load_nft()` (the first Python-installed runtime table). Line 173 is strictly after line 170, and no runtime table is installed before it — `main()` relies on systemd's `ExecStartPre=/usr/sbin/nft -f .../fail-closed.nft` (service:15) and the boot-time `qubes-snitch-fail-closed.service` for the only table active during step 1. 2. `load_rules()` (`config.py:400-422`) collects every `dest_dns` qname (415-417) and calls `resolve_dest_dns_names()` (418) **unconditionally at load time**. `resolve_dest_dns_names()` (279-287) submits `resolve_dest_dns` per qname and reads `future.result()`, which re-raises the worker's `SystemExit`. 3. The only table live during step 1 is `fail-closed.nft`, whose `chain output` is `policy drop` + `meta nfproto ipv4 ... reject` (template lines 10-14). That rejects **all** locally-originated IPv4, including the daemon's own UDP/53 to the Qubes resolvers. Confirmed intentional by `render_runtime_host_chains` (`nft.py:205-221`), which has to *re-add* `ip daddr { 10.139.1.1, 10.139.1.2 } udp dport 53 accept` in the **runtime** table — proof the daemon's DNS goes through the output hook and is blocked until that runtime table exists (installed only at line 173). 4. Therefore `dns.resolver.resolve(qname, "A", lifetime=3.0)` cannot succeed during `load_rules`; `resolve_dest_dns` converts the failure to `SystemExit` (config.py:262) → `load_rules` → `load_policy_without_sources` → `main()` aborts **before** any runtime policy is installed. `Restart=no` + `ExecStopPost` → permanent fail-closed on every boot and every `systemctl restart`. `dest_dns` rules are first-class and documented: they are exactly what the uppercase-`A` feature persists (`policy.append_flow_rule` 79-83 writes `dest_dns` and no `dest`; README lines 25, 78-84). So Finding 1's feature plants the rule that Finding 2 detonates on the next restart. **Correction that strengthens, not weakens, the finding:** the audit's attacker framing ("get the user to approve a hostname-backed rule … then let that domain lapse/NXDOMAIN, makes the brick certain") is **redundant** — the brick is certain for *any* `dest_dns` rule regardless of whether the domain still resolves, because fail-closed blocks the daemon's DNS at load time even for a perfectly healthy domain. No attacker and no domain lapse are required. A single `dest_dns` entry is sufficient because `resolve_dest_dns_names` raises on the first failing `future.result()`. Severity **High, borderline Critical is correct** — arguably Critical: deterministic, permanent, self-inflicted by a documented feature, cutting network for every downstream VM. Root cause is shared with Finding 1 (`resolve_dest_dns` using `SystemExit` for an expected DNS-not-answering condition); the audit's remediation (defer `dest_dns` resolution until after the runtime table exists, or make load-time resolution non-fatal/lazy) is sound. --- ## Finding 3 — check-then-act race on `SOURCES_BY_IP` in the NFQUEUE callback → KeyError → lock-out — **REAL (True Positive); narrow window, high impact** **Mechanism confirmed.** In `packet_handlers.add_runtime_request_fields()` (41-62): * Presence is checked under `POLICY_LOCK` at 43-44, then the lock is **released**. * Known-at-44 path: lines 45 and 54 (`if not known`) are both skipped, then line 56 re-acquires the lock and line **57 indexes `ctx.SOURCES_BY_IP[request["src"]]`**. The read is under the lock, but the presence guarantee came from the *previously released* lock at 44. `sources_runtime.refresh_sources_and_nft()` (40-61) **rebinds** `ctx.SOURCES_BY_IP` to a brand-new dict under `POLICY_LOCK` (line 56 there) on any QubesDB event via the `qubesdb_source_watcher` thread (daemon_runtime:174). If that rebind (dropping a VM that shut down / changed NetVM) lands between line 44 and line 56, line 57 raises `KeyError` despite holding the lock — because it holds it on the *new* dict. * Source-refresh sub-path: line **50** indexes `ctx.SOURCES_BY_IP[request["src"]]` **entirely outside** the lock (the lock at 47-48 covers only the `known = …` check and is released before line 50), so a rebind between 48 and 50 also raises `KeyError`. (Minor precision note: line 48 re-checks presence under lock one statement earlier, so this window is also tiny — the audit's "worse" wording overstates the size difference, but the read at 50 is genuinely unlocked and the race is real.) Because rebinding (not in-place mutation) is used, even a lock-held read can observe a map that never contained `src`. A `KeyError` here is uncaught: it propagates from `add_runtime_request_fields` → `handle_packet` (186) → `NetfilterQueue.run()` → `run_queues()` → `main()` on the **main thread**, ending the process → `Restart=no` + `ExecStopPost` fail-closed. Confirmed. **Assessment:** the window (line 44→57 or 48→50, a handful of bytecodes) is narrow and requires a source-removal refresh to fire in exactly that window, so trigger probability is low — the audit already labels it "High impact, low trigger probability," which is fair. It can fire by accident during ordinary VM start/stop churn and an untrusted VM can raise the odds (flood, then self-teardown / NetVM-flip), retrying across restarts. The proposed fix — do the presence check and read under a single `POLICY_LOCK` acquisition and use `.get()` (treat a vanished source as "drop this packet", not crash) — is the correct shape. Not pre-excluded by `README-AUDIT.md`. --- ## Closing note (§ "Reviewed…") — `dns_reject_payload` guarded only by `except OSError` — **UNCONFIRMED (valid hardening observation, no demonstrated trigger)** The narrowness is real: `answer_rejected_dns` (`packet_handlers.py:86-95`) wraps `send_dns_refused` in `try/except OSError` only, while `dns_reject_payload` (`dns.py:97-121`) can raise `dns.exception.DNSException` (from `from_wire` / `make_response` / `to_wire`) or `ValueError` (from `udp_checksum` / `struct.pack`). Such an exception would escape to the main NFQUEUE thread and crash the daemon like Findings 2/3. However, **no concrete crashing input is demonstrated**, and the auditor correctly declines to claim it as a finding (consistent with `README-AUDIT.md`'s dnspython-delegation note). Every path into `send_dns_refused` first passes `add_dns_query_fields` (dns.py:144-200), where `dns.message.from_wire` already succeeded and the query is heavily constrained (≤1232 bytes, one question, EDNS version 0, restricted flags/qtypes). `make_response` + `to_wire` of a tiny REFUSED echo over such a query is robust in practice, and the IP/port fields fed to `udp_checksum`/`struct` are pre-validated IPv4 and in-range ports. So this is a legitimate defense-in-depth improvement (broaden the `except` to also catch `dns.exception.DNSException` and `ValueError`), not a verified bug. The audit's own framing ("worth a dnspython-backed test to close out") is appropriate. --- ## Summary | # | Claim | Verdict | Severity assessment | |---|-------|---------|---------------------| | 1 | Uppercase `A`/`R` decision → live re-resolve → `SystemExit` → `os._exit` daemon crash | **REAL** | High (user-gated but fires on legit CDNs; whole-VM fail-closed lockout) | | 2 | Any `dest_dns` rule → load-time resolve while fail-closed blocks DNS → `SystemExit` → daemon never starts | **REAL** | High→Critical (deterministic, permanent, documented-feature-triggered, no attacker needed) | | 3 | Check-then-act race on `SOURCES_BY_IP` → `KeyError` on NFQUEUE thread → crash | **REAL** | High impact / low probability (narrow race) | | — | `dns_reject_payload` only caught by `except OSError` | **UNCONFIRMED** | Valid hardening; no demonstrated trigger (auditor did not claim it) | **Bottom line:** all three numbered findings are true positives, correctly traced against the source. Findings 1 and 2 share a root cause — `config.resolve_dest_dns()` using `SystemExit` as control flow for an expected, environment-dependent condition (DNS not answering), which both the decision path and the load path route into daemon-fatal handlers. Finding 2 is the most serious (deterministic, self-inflicted brick via a documented feature) and should be prioritized. The closing `dns_reject_payload` note is a reasonable, correctly-hedged hardening suggestion rather than a confirmed defect.