Skip to content

fix: address CRIT security findings (CRIT-01 to CRIT-04)#7

Open
manni07 wants to merge 1 commit intomaderix:mainfrom
manni07:fix/crit-security-findings
Open

fix: address CRIT security findings (CRIT-01 to CRIT-04)#7
manni07 wants to merge 1 commit intomaderix:mainfrom
manni07:fix/crit-security-findings

Conversation

@manni07
Copy link

@manni07 manni07 commented Mar 2, 2026

Summary

  • CRIT-01 (ane_runtime.h, stories_config.h): dlopen() Return-Check; NSClassFromString() Validierung; neue g_ane_ok/g_ane_ok_large Flags (nur true wenn alle 4 Private-Classes geladen); stories_config.h erhält Re-Entry-Guard (g_ane_init_done)
  • CRIT-02 (ane_runtime.h, stories_io.h): g_ane_ok-Guard am Anfang von ane_compile() und compile_kern_mil_w(); NULL-Check für inMemoryModel nach inMemoryModelWithDescriptor: (verhindert Crash bei hexStringIdentifier)
  • CRIT-03 (model.h, train_large.m): fread() Return-Check für kritische Config/Header-Reads als Gatekeeper vor malloc(); fopen() NULL-Check in save_checkpoint(); Designentscheid dokumentiert
  • CRIT-04 (stories_io.h, model.h): intsize_t in allen build_blob* Funktionen; calloc() NULL-Checks; (size_t)-Cast in malloc()-Größen verhindert UB durch signed integer overflow

Test plan

  • make train und make train_large ohne neue Warnings/Errors
  • make verify-flags — Security-Flags weiterhin aktiv
  • Truncated model file → "model: config read failed" auf stderr
  • save_checkpoint auf read-only path → "save_checkpoint: cannot open" auf stderr
  • Build mit CFLAGS_DEBUG (AddressSanitizer) für Laufzeit-Validierung

- 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
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad119aed46

ℹ️ 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".

LayerWeights *lw, LayerAdam *la, float *rms_final, AdamState *arms_final,
float *embed, AdamState *aembed) {
FILE *f = fopen(path, "wb");
if (!f) { fprintf(stderr, "save_checkpoint: cannot open %s\n", path); return; } // CRIT-03

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate checkpoint open failures before restart

save_checkpoint now returns early when fopen fails, but the training loop still unconditionally restarts with --resume after calling it. In environments where the checkpoint path is unwritable (read-only path, full disk, permission issue), this means the process restarts without a fresh checkpoint and then resumes from stale or missing state, which can repeat work or loop from step 0 indefinitely. Return a success flag here and block the restart path when checkpoint creation fails.

Useful? React with 👍 / 👎.

dev-erik added a commit to dev-erik/ANE that referenced this pull request Mar 3, 2026
…rotector-strong, format-security flags, NULL guards on ane_compile/fread/fopen, tokenize.py input validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant