Skip to content

Harden worker/buffer pools, DGC0 scratch dims, and PJRT shape/HBM accounting against overflow and partial-publish leaks - #49

Open
saariuslystoned wants to merge 1 commit into
mainfrom
fix/state-machine-freetpu-runtime-guards
Open

saariuslystoned wants to merge 1 commit into
mainfrom
fix/state-machine-freetpu-runtime-guards

Conversation

@saariuslystoned

Copy link
Copy Markdown
Collaborator

Summary

Fixes 6 integer-overflow, wraparound, HBM-accounting, and partial-publish bugs across untouched libopenbuenos and llama-cpp-cloudtpu runtime code (zero overlap with PRs #15, #45, #46, #47, #48):

  1. libopenbuenos/src/ob_worker_pool.cpp: uint32_t fetch_add wraparound could reissue work ranges when total approached UINT32_MAX; replaced with saturating CAS claim publishing total.
  2. libopenbuenos/src/ob_buffer_pool.cpp: ob_buffer_alloc(SIZE_MAX - 100) page-alignment wrapped to a 0-byte slab and returned success; now returns OB_ERR_OVERFLOW.
  3. libopenbuenos/src/ob_dgc0.cpp: DGC0 scratch dimensions (e.g., 65536^4) wrapped to 0 and parsed as success; now returns OB_ERR_OVERFLOW while valid dims ({4, 5}) continue to yield 20.
  4. llama-cpp-cloudtpu/pjrt_runtime.cpp (shape/byte overflow & negative dim leak): Checked overflow in num_elements, pjrt_dtype_nbytes, and pjrt_host_nbytes (preventing f32 {(1<<62)+1} allocating 4 bytes, {1<<40, 1<<40} reporting 0 elements, and dim -1 throwing mid-allocation and leaking HBM); now fails cleanly with PjrtError and leaves HBM accounting unchanged.
  5. llama-cpp-cloudtpu/pjrt_runtime.cpp (device-id HBM accounting): Scrambled tpu7x-1t device maps previously charged a device-0 constant tensor to device 1; counters are now keyed by hardware device ID.
  6. llama-cpp-cloudtpu/pjrt_runtime.cpp (atomic Execute output publication): An Execute returning one valid tensor and one missing SSA name previously published the first buffer before throwing, leaking HBM; outputs are now staged and published atomically with counter rollback on failure.

Proof (Offline Host Verification)

  • Base fail -> Head pass: Against origin/main, openbuenos_pool_guards_test failed 4 checks and pjrt_runtime_guards_test failed 8 checks. On HEAD both compile cleanly with -fsanitize=address,undefined -Werror and PASS.
  • Existing host suites: make -C libopenbuenos test (27/27 + quant-unpack PASS); test_cloudtpu_host (OVERALL ALL PASSED, 0 failures).
  • Hygiene: git diff --check clean; single trailing newline on all 6 files; clean-room public check clean; TruffleHog verified_secrets=0, unverified_secrets=0.
  • Scope/Limits: Offline host/mock verification only (zero live TPU hardware touched).

…ounting against overflow and partial-publish leaks
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