Skip to content

fix: bound multi-slot backend allocations - #9

Merged
parkjinman98 merged 2 commits into
mainfrom
codex/propose-fix-for-max_batch_size-vulnerability
Sep 22, 2026
Merged

parkjinman98 merged 2 commits into
mainfrom
codex/propose-fix-for-max_batch_size-vulnerability

Conversation

@parkjinman98

Copy link
Copy Markdown
Contributor

Motivation

  • The multi-slot NPU backend accepted arbitrary max_batch_size values and converted them into unbounded native Model allocations, allowing attackers who control configuration to cause excessive synchronous allocations and temporary resource exhaustion.
  • The only prior normalization was max(1, max_batch_size), which allowed booleans, floats, extremely large integers, and inf to reach the allocation arithmetic and bypass rollback paths.
  • The change's intent is to validate admission-time inputs and impose a deterministic, documented cap on derived native slot allocations before performing costly native work.

Description

  • Introduced MAX_BATCH_SIZE = 1024 and MAX_MODEL_SLOTS = 64 and documented them in the public API and README.
  • Enforced strict constructor/deserialization validation so max_batch_size must be a non-boolean int in 1..MAX_BATCH_SIZE and exported the new constants from the package.
  • Replaced the math.ceil float-based computation with integer ceiling arithmetic after probing K, and capped the derived n_models to MAX_MODEL_SLOTS; if exceeded, the code disposes slot 0, clears state, and raises a ValueError before further native allocations.
  • Updated docs and agent guidance (README.md, AGENTS.md, .agents/skills/mblt-npu/SKILL.md) and added regression tests that verify constructor and from_dict() validation and post-probe rollback behavior.

Testing

  • Ran the full test suite with python -m pytest -q, which completed successfully with 94 passed and included the newly added tests: test_max_batch_size_rejects_non_integer_values, test_max_batch_size_rejects_values_outside_safe_range, test_from_dict_validates_max_batch_size, and test_create_rejects_excessive_derived_slots_and_rolls_back.
  • Ran linting with python -m ruff check mblt_npu/npu_backend.py mblt_npu/__init__.py tests/test_npu_backend_multi_slot.py, which passed after an unused-import fix.
  • Ran git diff --check to ensure no whitespace or diff issues, which reported no problems.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T08:57:37.597572Z d152208 Manual request
🔒 Security Review ✅ Completed 2026-09-22T09:01:42.218172Z d152208 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: e376161744

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

Comment thread mblt_npu/npu_backend.py
@parkjinman98 parkjinman98 self-assigned this Sep 22, 2026
@parkjinman98

Copy link
Copy Markdown
Contributor Author

@codex review

The prior P2 is addressed in d152208. Please follow the create() path from its first executable statement: _validate_max_batch_size(self.max_batch_size) now runs before _unique_devs_from_targets(), Accelerator(...), path resolution, or Model(...). Verify post-construction assignments of True, 0, and MAX_BATCH_SIZE + 1 all raise while stub_qbruntime.models and backend.accs remain empty. The public attribute stays directly writable (rather than becoming property-backed) to preserve the existing object/serialization state shape; valid values such as 65 still reach the separate 64-slot post-probe rollback guard.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: d152208b39

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

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: d152208b39

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@parkjinman98
parkjinman98 merged commit fd4b350 into main Sep 22, 2026
6 checks passed
@parkjinman98
parkjinman98 deleted the codex/propose-fix-for-max_batch_size-vulnerability branch September 22, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants