Skip to content

[BUG]: cudaGraphGetEdges() suffers use-after-free for cudaGraphEdgeData #1804

@galv

Description

@galv

Is this a duplicate?

Type of Bug

Silent Failure

Component

cuda.bindings

Describe the bug

Take a look here:

https://github.com/NVIDIA/cuda-python/blob/346afc808db7f7573f9b7a7c2d297868ea7e4894/cuda_bindings/cuda/bindings/runtime.pyx.in#L35898-L35901

We are creating a python cudaGraphEdgeData object via a pointer to the underlying C cudaGraphEdgeData struct.

That underlying constructor https://github.com/galv/cuda-python/blob/346afc808db7f7573f9b7a7c2d297868ea7e4894/cuda_bindings/cuda/bindings/runtime.pyx.in#L18241 just saves that pointer, rather doing a deep copy. Thus, it relies upon that underlying pointer staying alive.

Then, cudaGraphGetEdges() immediately frees the underlying pointer that the python objects reference, https://github.com/NVIDIA/cuda-python/blob/346afc808db7f7573f9b7a7c2d297868ea7e4894/cuda_bindings/cuda/bindings/runtime.pyx.in#L35901, and returns the list of python objects which are now backed by dead pointers.

Thus, the cudaGraphEdgeData returned by cudaGraphGetEdges() always suffers a use-after-free. You need to do a deep-copy.

The driver code suffers from the same issue.

Please fix this.

How to Reproduce

I don't think you need a repro to see the problem in this case.

Expected behavior

Do a deep copy of the underlying data.

Operating System

No response

nvidia-smi output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions