Skip to content

BUG: Fix use-after-free in _HelperInputVoidPtr properties - #1629

Merged
mdboom merged 4 commits into
NVIDIA:mainfrom
mdboom:fix-dangling-ref-helper-input-void-ptr
Feb 17, 2026
Merged

BUG: Fix use-after-free in _HelperInputVoidPtr properties#1629
mdboom merged 4 commits into
NVIDIA:mainfrom
mdboom:fix-dangling-ref-helper-input-void-ptr

Conversation

@mdboom

@mdboommdboom commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

While working on #1616, I discovered a use-after-free bug in how void * properties are handled by one of our generators (affecting driver/runtime/nvrtc).

If a void * property value is set to a Python buffer, the reference to that buffer is not held, so if the buffer is independently free'd elsewhere, the pointer becomes dangling. The new unit test here hopefully illustrates the problem.

There is a related bug in _HelperInputVoidPtrPtr that references to each of the individual buffers are not held so could also get freed early. That bug is less critical since we don't currently use them as properties, only as variables within function calls, so it's actually hard to trigger that bug from the outside. But I thought we should fix it while we are here so it isn't a latent bug if we ever do add support for void ** properties.

@copy-pr-bot

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboommdboom added bug Something isn't working P0 High priority - Must do! cuda.bindings Everything related to the cuda.bindings module labels Feb 17, 2026
@github-actions

This comment has been minimized.

@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test


cdef class _InputVoidPtrPtrHelper:
def __cinit__(self, lst):
self._references = lst

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be worth a comment if possible, so that humans and bots don't think this code is dead code.

@mdboommdboom self-assigned this Feb 17, 2026
@rparolinrparolin added this to the cuda.bindings 13.1.2 & 12.9.6 milestone Feb 17, 2026
Comment threadcuda_bindings/cuda/bindings/_lib/utils.pxi.in
@mdboom
mdboom enabled auto-merge (squash) February 17, 2026 20:39
@mdboom

Copy link
Copy Markdown
ContributorAuthor

/ok to test

@mdboom
mdboom merged commit 0a00e4c into NVIDIA:mainFeb 17, 2026
86 checks passed
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

@leofangleofang modified the milestones: cuda.bindings 13.1.2 & 12.9.6, cuda.bindings nextFeb 17, 2026
@mdboommdboom added the to-be-backported Trigger the bot to raise a backport PR upon merge label Feb 18, 2026
@github-actions

Copy link
Copy Markdown

Backport failed for 12.9.x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin 12.9.x
git worktree add -d .worktree/backport-1629-to-12.9.x origin/12.9.x
cd .worktree/backport-1629-to-12.9.x
git switch --create backport-1629-to-12.9.x
git cherry-pick -x 0a00e4cb02e2f98d8463aa241346e4e32f5270e4

mdboom added a commit to mdboom/cuda-python that referenced this pull request Feb 18, 2026
* BUG: Fix use-after-free in _HelperInputVoidPtr properties
* Revert cptr ref
* Apply suggestion from @mdboom
mdboom added a commit that referenced this pull request Feb 19, 2026
* BUG: Fix use-after-free in _HelperInputVoidPtr properties (#1629)
* BUG: Fix use-after-free in _HelperInputVoidPtr properties
* Revert cptr ref
* Apply suggestion from @mdboom
* Add fix
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't workingcuda.bindingsEverything related to the cuda.bindings moduleP0High priority - Must do!to-be-backportedTrigger the bot to raise a backport PR upon merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@mdboom@cpcloud@rparolin@leofang