Skip to content

fix(core): reject mismatched UUID in register() even under -O - #2704

Open
waterWang wants to merge 1 commit into
NVIDIA:mainfrom
waterWang:fix-2697-register-uuid-assert
Open

fix(core): reject mismatched UUID in register() even under -O#2704
waterWang wants to merge 1 commit into
NVIDIA:mainfrom
waterWang:fix-2697-register-uuid-assert

Conversation

@waterWang

Copy link
Copy Markdown

Description

closes #2697

DeviceMemoryResource.register() and PinnedMemoryResource.register()
validated the supplied UUID against the resource's own with a bare
assert in MP_register (cuda_core/cuda/core/_memory/_ipc.pyx).
Since CPython strips assertions when run with -O, the check silently
disappears in optimized interpreters: the resource is registered under
a foreign key and its own UUID is rewritten to the attacker-
controlled value (mr.uuid reports the new value from then on).

Changes

  • _ipc.pyx MP_register: replace assert self.uuid is None or self.uuid == uuid with an explicit ValueError when the supplied
    UUID does not match the resource's own.
  • _ipc.pyx MP_from_allocation_handle: convert the internal
    assert registered is self to an explicit RuntimeError, matching
    the maintainer direction to remove bare asserts from the library
    (they are behavioral no-ops under -O).
  • cuda_core/tests/memory_ipc/test_errors.py: add
    test_register_rejects_mismatched_uuid covering the rejection and
    verifying the resource's UUID is not rewritten on failure.

Checklist

  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

…#2697)

DeviceMemoryResource.register() and PinnedMemoryResource.register()
validated the supplied UUID against the resource's own with a bare
`assert`, which CPython removes under `-O`. A mismatched UUID was then
accepted, registered as a foreign registry key, and rewritten into the
resource's own UUID, silently corrupting the IPC registry.

Replace the assertion with an explicit ValueError so the check is
enforced regardless of the interpreter's assertion mode, and convert
the internal register() result check in MP_from_allocation_handle to
an explicit RuntimeError as well.

Signed-off-by: waterWang <waterWang@users.noreply.github.com>
@copy-pr-bot

copy-pr-bot Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: register() accepts a mismatched UUID under python -O

1 participant