Skip to content

fix(cuda-core): return an error on interior NUL in module loading - #1492

Open
alejandro-soto-franco wants to merge 2 commits into
NVIDIA:mainfrom
alejandro-soto-franco:fix/cuda-core-interior-nul
Open

alejandro-soto-franco wants to merge 2 commits into
NVIDIA:mainfrom
alejandro-soto-franco:fix/cuda-core-interior-nul

Conversation

@alejandro-soto-franco

Copy link
Copy Markdown
Contributor

Eight module-loading paths in cuda-core call CString::new(..).unwrap() inside functions that return Result<_, DriverError>. A PTX source, file path or symbol name with an interior NUL byte panics in the caller where the signature promises an error.

  • Adds error::c_string, which maps NulError to CUDA_ERROR_INVALID_VALUE.
  • Uses it in CudaContext::load_module_from_ptx_src, load_module_from_file, CudaModule::load_function and get_global.
  • Uses it in Device::load_module_from_ptx_src and the cudarc_shim::module helpers.
  • Runs the conversion before the context is bound.
  • Replaces the "Panics" doc sections with "Errors" sections.
  • Adds a table-driven unit test for c_string, a driver-free test for the shim helpers, and a GPU test in tests/simt_module_interior_nul.rs covering the four CudaContext and CudaModule methods.

Test: cargo test -p cuda-core passes (48 unit tests, 3 new integration tests, all other suites) on an RTX 5060 Laptop. The three integration tests fail with a panic at the old unwrap sites without the change. cargo fmt --check and cargo clippy --workspace --all-targets -- -D warnings are clean.

Eight module-loading paths called CString::new(..).unwrap() in
functions that return Result<_, DriverError>. A PTX source, path or
symbol name with an interior NUL byte aborted the caller with a panic.

Add error::c_string, which maps NulError to CUDA_ERROR_INVALID_VALUE,
and use it in CudaContext::load_module_from_ptx_src,
load_module_from_file, CudaModule::load_function and get_global, in
Device::load_module_from_ptx_src, and in the cudarc_shim module
helpers. The conversion runs before the context is bound. The "Panics"
sections become "Errors" sections.

Signed-off-by: Alejandro Soto Franco <sotofranco.eng@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 11, 2026

Copy link
Copy Markdown

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.

c_string drops one NUL in the final byte. PTX read back from NVRTC with
its terminator now loads. Any other NUL still returns INVALID_VALUE.

Device::load_module_from_file converts the name before it binds the
context. Every other entry point already did. module::load takes a &CStr.

The full input table lives in the error.rs unit test. The shim and GPU
tests check one bad string per call site. The GPU test also loads a
terminated source and resolves terminated names.

This branch has not been deployed

No deployments
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.

2 participants