- stories_mil.h: get_mask_blob() mask calloc now guarded with abort()
on NULL before immediate array write
ref: docs/reports/security-audit-2026-03-02.md HIGH-04
- 7 additional raw malloc/calloc calls replaced with xmf()/xcf() helpers
- cross_entropy_loss buf cast to (size_t) to prevent int overflow
ref: docs/reports/security-audit-2026-03-02.md HIGH-04
- stories_config.h: add xmf(n)/xcf(n) static inline helpers that abort()
with diagnostic on OOM — replaces all unchecked malloc/calloc
- stories_config.h: replace all (float*)malloc(X*4) -> xmf(X) and
(float*)calloc(X,4) -> xcf(X) in all 5 alloc functions
- train_large.m: same replacement for direct alloc calls (embed, rms_final,
grads, per-iteration temporaries — 31 call sites total)
ref: docs/reports/security-audit-2026-03-02.md HIGH-04
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- munmap(token_data) + close(data_fd) before execl() prevents FD/mmap
leak across process boundary
- realpath(argv[0]) resolves binary path to prevent exec of wrong binary
when invoked via relative path
ref: docs/reports/security-audit-2026-03-02.md HIGH-03
- train_large.m: realpath() guard for DATA_PATH before open() provides
clear error message when run from wrong directory
- train_large.m: realpath() audit log in load_pretrained() for model path
ref: docs/reports/security-audit-2026-03-02.md HIGH-02
- train_large.m: early exit if n_tokens < SEQ+1 prevents arithmetic
underflow and downstream index corruption
- stories_cpu_ops.h: clamp tok >= VOCAB to 0 in embed_lookup() to
prevent heap-buffer-overflow
ref: docs/reports/security-audit-2026-03-02.md HIGH-01
Simulation plan for HIGH-01 to HIGH-05 with 5-criteria scoring.
Overall avg: 95.76% (all criteria >=95%).
ref: docs/reports/security-audit-2026-03-02.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Key findings from running all 4 probes on Apple M5:
- Weight reload (unload+load after file overwrite) does NOT work — weights
are baked at compile time, output is identical regardless of file changes
- weightsBuffer IOSurface parameter also does not override compiled weights
- All QoS values 0-63 work, no measurable latency difference (~0.07ms/eval)
- _ANEPerformanceStats has hwExecutionTime (ns) + perfCounterData
- _ANEChainingRequest supports loopback execution (output→input chaining)
- _ANEClient has real-time eval path and chaining preparation methods
- procedureIndex 0-15 all succeed on single-procedure models
Fixed probe tests to use fp32 I/O with cast (matching inmem_peak pattern)
and 64+ channel kernels (ANE minimum size requirement).
Full analysis in training/m5result.md.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Four standalone probe tests to characterize the M5 ANE:
- test_weight_reload: Can weights be hot-swapped via unload+load without recompilation?
- test_perf_stats: Enumerate _ANEPerformanceStats methods/properties and hardware counters
- test_qos_sweep: Measure compile/load/eval latency across QoS 0-63
- test_ane_advanced: Probe SharedEvents, weightsBuffer IOSurface, procedureIndex, VirtualClient
Training telemetry (train_large.m):
- JSON lines to stderr with per-step timing breakdown and per-batch TFLOPS metrics
- Enables external monitoring tools to visualize ANE utilization in real-time
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>