fix: address MED security findings (MED-01 to MED-06)#8
Open
manni07 wants to merge 4 commits intomaderix:mainfrom
Open
fix: address MED security findings (MED-01 to MED-06)#8manni07 wants to merge 4 commits intomaderix:mainfrom
manni07 wants to merge 4 commits intomaderix:mainfrom
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- CRIT-01: dlopen() return check + NSClassFromString validation in ane_init()
(ane_runtime.h + stories_config.h); g_ane_ok / g_ane_ok_large flag
only set when all private classes load successfully; stories_config.h
gets re-entry guard (g_ane_init_done) that was previously missing
- CRIT-02: g_ane_ok guard in ane_compile() and compile_kern_mil_w(); NULL check
for inMemoryModel after inMemoryModelWithDescriptor: — prevents crash
when API call returns nil (ane_runtime.h, stories_io.h)
- CRIT-03: Validate fread() return for critical config/header reads to prevent
garbage malloc() sizes; fopen() NULL check in save_checkpoint();
design decision documented (model.h, train_large.m)
- CRIT-04: int -> size_t in build_blob*/build_blob_t/build_blob_fp16; calloc()
NULL checks added; (size_t) cast in malloc() size calculations to
prevent signed integer overflow UB (stories_io.h, model.h)
Simulation: 3 iterations, overall score 96.15% (all criteria >= 95%)
ref: docs/reports/security-audit-2026-03-02.md
- MED-01: IOSurfaceLock() return checked in all 6 I/O functions; early return
on failure prevents data race (stories_io.h, ane_runtime.h)
- MED-02: Per-process/per-call unique temp dirs via getpid()+g_compile_seq
(stories_io.h, ane_runtime.h)
- MED-03: mil_dims_valid() guard in all 7 MIL-gen functions; nil return on
invalid params (ane_mil_gen.h)
- MED-04: CkptHdr.pad[0]=0x01020304 byte-order sentinel; runtime check in
load_checkpoint; _Static_assert for compile-time LE guarantee (train_large.m)
- MED-05: _Static_assert(SEQ%8==0) + ARM64 alignment rationale comment (stories_io.h)
- MED-06: dispatch_once replaces manual g_ane_loaded/g_ane_init_done guards;
thread-safe one-time ANE init (ane_runtime.h, stories_config.h)
ref: docs/reports/security-audit-2026-03-02.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7c67e78306
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IOSurfaceLock()return value checked in all 6 I/O functions (io_write_fp16,io_read_fp16,io_copy,io_write_fp16_at,ane_write_input,ane_read_output); early return on failure prevents data race on stale surfacesANE_<pid>_<seq>_<hash>format usinggetpid()+ atomic sequence counter; prevents TOCTOU race when two threads/processes compile the same modelmil_dims_valid(int a, int b)helper guards all 7 MIL-gen functions (mil_build_weight_blob,mil_gen_matmul,mil_gen_conv,mil_gen_qkv,mil_build_qkv_weight_blob,mil_build_ffn_up_weight_blob,mil_gen_ffn_up); returnsnilon invalid dimsCkptHdr.pad[0] = 0x01020304byte-order sentinel written on save; runtime check on load rejects big-endian checkpoints;_Static_assertfor compile-time LE guarantee; legacy checkpoints (pad[0]=0) still load correctly_Static_assert(SEQ % 8 == 0, ...)provides compile-time proof that all NEON offsets are 16-byte aligned; ARM64 hardware alignment tolerance documenteddispatch_oncereplaces manualg_ane_loaded/g_ane_init_doneguards in bothane_runtime.handstories_config.h; eliminates Check-Then-Act race; 2 global variablesSimulation Results
All 6 fixes were validated through iterative simulation against 5 criteria (Fix-Vollständigkeit, Rückwärtskompatibilität, Code-Qualität, Verifikationsmöglichkeit, Projektkonsistenz). Overall average: 95.93% (all individual scores ≥ 95%).
Test plan
cd training && make train_large— no new warnings or errorsstderroutput expected, no crashxxd ane_stories110M_ckpt.bin | headshows04 03 02 01at offset 56 (LE representation of0x01020304)_Static_assert(256 % 8 == 0)— compile passes with currentSEQ=256make CFLAGS_DEBUG="-fsanitize=thread" train_large— no TSan race reports