security(core,cli): pin CSI-deserialiser DoS-resistance + ADR-172 (clean-with-evidence) (#1091)

* test(core,cli): pin DoS-resistance of CSI deserialisers (ADR-127 security review)

Beyond-SOTA security review of wifi-densepose-core + wifi-densepose-cli.
Load-bearing-question verdict: the NaN-state-poisoning bug class does NOT
originate in core — core exposes no stateful accumulator (no Welford,
von-Mises, IIR, voxel grid, running mean); each downstream crate rolls its
own, so each fix is correctly local. Both crates confirmed clean on every
reviewed dimension (panic-on-adversarial-input, NaN handling, unbounded
memory, path traversal, secrets) — no production code changed.

Adds 4 regression pins locking in two existing-but-untested DoS guards:
- core: from_canonical_bytes shape guard (Vec::with_capacity bound) — proven
  to fail with `capacity overflow` when the saturating-mul guard is removed.
- core: canonical decoder never panics on arbitrary/truncated bytes.
- cli: parse_csi_packet rejects an oversized n_antennas*n_subcarriers claim
  before Array2 allocation (33 MB claim in a 2 KB datagram -> None).
- cli: parse_csi_packet never panics on arbitrary UDP bytes.

core: 35 -> 37 lib tests; cli: 24 -> 26 tests; 0 failed. Python proof
unchanged (f8e76f21…46f7a — off the signal path).

Co-Authored-By: claude-flow <ruv@ruv.net>

* docs(adr): ADR-172 — wifi-densepose-cli + core CSI-deserialiser security review

Records the clean-with-evidence verdict + 4 DoS-resistance regression pins
(test-only, committed in a1051607d). Documents the load-bearing finding:
the NaN-state-poisoning bug class does NOT originate in a shared core
primitive (core exposes no stateful accumulator — MEASURED via grep), so
the 3 prior downstream-local fixes are complete. Gives the wifi-densepose-cli
review its own ADR slot (core portion cross-refs ADR-127 §9).

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
rUv
2026-06-14 23:58:09 -04:00
committed by GitHub
parent 71e8756051
commit cfd0ad76cf
4 changed files with 227 additions and 0 deletions
@@ -471,6 +471,54 @@ mod tests {
assert!(ht.record(&f).is_err());
}
/// Security pin (review 2026-06, ADR-127): the UDP parser is the CLI's
/// widest attack surface — `calibrate` / `enroll` / `room-watch` bind it to
/// 0.0.0.0 by default, so any host on the LAN can send arbitrary bytes. A
/// header that *claims* a huge `n_antennas * n_subcarriers` must be rejected
/// by the length check BEFORE the `Array2::zeros` allocation, so a single
/// small datagram can never trigger a multi-MB allocation (unbounded-memory
/// DoS). The largest possible claim (255 × 65535 pairs ≈ 33 MB of IQ) inside
/// a RECV_BUF-sized (2048-byte) datagram parses to `None`, never OOMs.
#[test]
fn test_parse_csi_packet_oversized_claim_is_rejected_not_allocated() {
let mut buf = vec![0u8; RECV_BUF];
buf[0..4].copy_from_slice(&0xC511_0001u32.to_le_bytes());
buf[4] = 1; // node_id
buf[5] = 255; // n_antennas (max)
buf[6..8].copy_from_slice(&65535u16.to_le_bytes()); // n_subcarriers (max)
buf[8..12].copy_from_slice(&2432u32.to_le_bytes());
// n_pairs = 255 * 65535 = 16_711_425 → needs ~33 MB of IQ bytes that a
// 2048-byte datagram cannot carry → length check fails → None.
assert!(parse_csi_packet(&buf, "ht20").is_none());
}
/// Security pin (review 2026-06): the parser must never panic on ANY byte
/// string — truncated headers, lying length fields, odd sizes. IQ-loop
/// indexing is guarded by the length check; this sweeps a spread of
/// adversarial inputs to lock in panic-on-adversarial-input = 0.
#[test]
fn test_parse_csi_packet_never_panics_on_arbitrary_bytes() {
let mut st = 0x1234_5678u64;
let mut next = move || {
st = st
.wrapping_mul(6_364_136_223_846_793_005)
.wrapping_add(1_442_695_040_888_963_407);
(st >> 33) as u8
};
for len in 0..600usize {
let buf: Vec<u8> = (0..len).map(|_| next()).collect();
for tier in ["ht20", "he20", "garbage"] {
let _ = parse_csi_packet(&buf, tier);
}
}
// Valid magic, lying n_subcarriers, no payload → None (not a panic).
let mut buf = vec![0u8; 20];
buf[0..4].copy_from_slice(&0xC511_0001u32.to_le_bytes());
buf[5] = 3;
buf[6..8].copy_from_slice(&500u16.to_le_bytes());
assert!(parse_csi_packet(&buf, "ht20").is_none());
}
#[test]
fn test_freq_to_channel_24ghz() {
assert_eq!(freq_mhz_to_channel(2437), 6);