nx_adversarial_pattern_audit.nx
buildroot/runtime/nx_adversarial_pattern_audit.nx
about
nx_adversarial_pattern_audit.nx -- scans for adversarial-exploit patterns.
module: nishi-core.security.adversarial_pattern_audit
depends: nishi-core.security.threat_model,
nishi-core.audit.wired_status,
nishi-core.audit.claim_audit,
nishi-core.io.syscalls
disk_kb: 6
capability: CRYPTO
wired_status: FULLY_WIRED
(Honest: substrate STRUCTURE + the FALSE_OK_RETURN-class
heuristic counter are wired AND smoke-verified via
runtime/nx_adversarial_pattern_audit_test.nx PASS on qemu-rv64.
The counter is a substring-based observation primitive that
counts `_STUB_NOT_WIRED` markers + `wired_status:` headers per
file; smoke asserts known counts on three runtime files. The
FALSE_OK_RETURN substring detector is the WIRED kernel today;
other 13 pattern-detectors in the 14-class taxonomy remain
HEURISTIC_QUEUED. Per-file tree-walking via nx_dir is queued
pending syscall-module unification -- nx_dir imports
`syscalls.nx` while threat_model+wired_status+claim_audit import
`nx_syscalls.nx`, and both define `sys_read_file` so they cannot
link together. Caller passes pre-read bytes for now.)
license_tier: PUBLIC_NISHI_SUBSTRATE
genealogy_id: nishi_racing_crew_team_honesty_threat_aware_cardinal +
cert_secure_coding_standards +
misra_c_2012_safety_critical_rules +
nasa_jpl_power_of_10
Per cardinal [[feedback-racing-crew-team-honesty-threat-aware]]:
substrate scanner extends nx_claim_audit with patterns specifically
dangerous when an adversary (especially AI-class) can read the
substrate code looking for exploitable false-OK paths.
Catches the exact failure pattern that triggered the no-false-OK
cardinal:
- function declares "fetch resource X" + returns *_OK from
uninitialized verdict field → AI adversary writes caller code
dependencies 3 imports · 1 importers
imports: nx_syscalls.nxnx_threat_model.nxnx_wired_status.nx
imported by: nx_adversarial_pattern_audit_test.nx
structs
| 131 | struct AdversarialFinding |
| 180 | struct AdversarialScanReport |
| 275 | struct ApaFileScanCounts |
consts
| 59 | const NX_APA_OK: i64 = 1 |
| 60 | const NX_APA_PATTERN_DETECTED: i64 = 2 |
| 61 | const NX_APA_CRITICAL_VULNERABILITY: i64 = 3 |
| 62 | const NX_APA_SCAN_FAIL: i64 = 4 |
| 63 | const NX_APA_STUB_NOT_WIRED: i64 = -7777 // honest stub-variant per cardinal |
| 76 | const NX_APA_PATTERN_FALSE_OK_RETURN: i64 = 1 // function returns *_OK from no-op body |
| 77 | const NX_APA_PATTERN_MISSING_STUB_VARIANT: i64 = 2 // sealed enum lacks *_STUB_NOT_WIRED |
| 78 | const NX_APA_PATTERN_UNINITIALIZED_VERDICT: i64 = 3 // verdict field reads OK by default-init |
| 79 | const NX_APA_PATTERN_SILENT_ERROR_SWALLOW: i64 = 4 // catch + ignore error |
| 80 | const NX_APA_PATTERN_CLAIM_BODY_MISMATCH: i64 = 5 // header claims X; body does Y |
| 81 | const NX_APA_PATTERN_TLS_DOWNGRADE_PATH: i64 = 6 // fallback to plaintext possible |
| 82 | const NX_APA_PATTERN_AUTH_BYPASS_PATH: i64 = 7 // codepath skips auth check |
| 83 | const NX_APA_PATTERN_TIMING_LEAK: i64 = 8 // variable-time crypto compare |
| 84 | const NX_APA_PATTERN_INTEGER_OVERFLOW: i64 = 9 // unchecked arithmetic |
| 85 | const NX_APA_PATTERN_UNBOUNDED_LOOP: i64 = 10 // violates JPL Rule 2 |
| 86 | const NX_APA_PATTERN_DESERIALIZE_UNTRUSTED: i64 = 11 // parses untrusted data without bounds |
| 87 | const NX_APA_PATTERN_PROMPT_INJECTION_TRUST: i64 = 12 // executes instructions from ingested data |
| 88 | const NX_APA_PATTERN_HARDCODED_CREDENTIAL: i64 = 13 // API key / secret in source |
| 89 | const NX_APA_PATTERN_THIRD_PARTY_SAAS_LEAK: i64 = 14 // new external SaaS dep detected |
| 144 | const NX_ADV_FINDING_BYTES: i64 = 80 // 10 fields * 8 bytes |
| 150 | const NX_APA_MAX_FINDINGS_PER_FILE: i64 = 1024 |
| 193 | const NX_ADV_SCAN_REPORT_BYTES: i64 = 80 // 10 fields * 8 bytes |
| 199 | const NX_APA_ACTION_FIX_IMMEDIATELY: i64 = 1 // critical; block commits |
| 200 | const NX_APA_ACTION_FIX_THIS_SESSION: i64 = 2 // high; on session backlog |
| 201 | const NX_APA_ACTION_QUEUE_FIX: i64 = 3 // medium; queued |
| 202 | const NX_APA_ACTION_DOCUMENT_AS_RESIDUAL: i64 = 4 // low; document the residual risk |
| 203 | const NX_APA_ACTION_ACCEPT_RISK: i64 = 5 // not applicable to substrate's threat model |
| 229 | const NX_APA_MAX_SCAN_BYTES: i64 = 8388608 // 8 MiB / file ceiling |
| 290 | const NX_APA_FILE_SCAN_COUNTS_BYTES: i64 = 104 // 13 fields * 8 bytes |
| 416 | const NX_APA_CONSISTENCY_NOT_VERIFIED: i64 = 0 |
| 417 | const NX_APA_CONSISTENCY_CONSISTENT: i64 = 1 |
| 418 | const NX_APA_CONSISTENCY_OVERSTATED: i64 = 2 |
| 419 | const NX_APA_CONSISTENCY_UNDERSTATED: i64 = 3 |
| 433 | const NX_APA_STUB_USAGE_THRESHOLD: i64 = 3 |
functions
| 65 | func nx_apa_verdict_name(v: i64) -> *u8 |
| 91 | func nx_apa_pattern_name(p: i64) -> *u8 |
| 111 | func nx_apa_pattern_severity_min_threat_tier(p: i64) -> i64 |
| 152 | func nx_adversarial_scan_file( |
| 205 | func nx_apa_action_for_severity(severity_tier: i64) -> i64 |
| 212 | func nx_apa_action_name(a: i64) -> *u8 |
| 231 | func nx_apa_count_substring( |
| 296 | func nx_apa_make_needle_stub(out: *u8) called by 1: nx_apa_scan_file_returns |
| 304 | func nx_apa_make_needle_partial(out: *u8) called by 1: nx_apa_scan_file_returns |
| 315 | func nx_apa_make_needle_fully(out: *u8) called by 1: nx_apa_scan_file_returns |
| 326 | func nx_apa_make_needle_honest(out: *u8) called by 1: nx_apa_scan_file_returns |
| 337 | func nx_apa_make_needle_funcdecl(out: *u8) called by 1: nx_apa_scan_file_returns |
| 343 | func nx_apa_make_needle_return_nx(out: *u8) called by 1: nx_apa_scan_file_returns |
| 352 | func nx_apa_scan_file_returns( |
| 421 | func nx_apa_consistency_name(c: i64) -> *u8 |
| 435 | func nx_apa_judge_file_consistency(s: *ApaFileScanCounts) -> i64 called by 1: main |