8000 Validate device-name output lengths before native access by RicheyWorks · Pull Request #62 · jcuda/jcuda · GitHub
[go: up one dir, main page]

Skip to content

Validate device-name output lengths before native access - #62

Draft
RicheyWorks wants to merge 1 commit into
jcuda:masterfrom
RicheyWorks:fix/device-name-output-bounds
Draft

RicheyWorks wants to merge 1 commit into
jcuda:masterfrom
RicheyWorks:fix/device-name-output-bounds

Conversation

@RicheyWorks
Copy link
Copy Markdown

cuDeviceGetName forwards len to CUDA without checking the Java output array's actual size. An excessive length lets the native call write beyond the array storage; a negative length is also forwarded instead of rejected at the Java boundary.

After the existing null checks and before acquiring critical array storage, reject len < 0 or len > name.length with IllegalArgumentException. Document this exception. Preserve existing null handling, valid partial/exact output lengths and native handling of zero length. Signatures and valid-output copy-back are unchanged. Valid calls retain native result-code behavior; invalid Java output lengths now throw rather than being forwarded.

Six isolated child-JVM tests cover negative/oversized lengths, exact/partial valid lengths and null name/device arguments. Children enable JNI checking, capture diagnostics and have a 30-second timeout so a broken JNI build cannot terminate JUnit. Invalid-length cases require the exception and untouched sentinel bytes; valid cases check CUDA success and untouched bytes beyond len.

Verification on Windows x86_64, RTX 4090/driver 617.42, Temurin JDK 22/JUnit 4.13.1:

  • Published 12.6.0 DLL: six tests, two failures. Excessive length triggers FATAL ERROR ... failed bounds check in the isolated child; negative length lacks the validation exception. Four controls pass.
  • Driver rebuilt with only this bounds guard and pristine jcuda-common 9d41fb5: all six pass, zero failures/errors/skips. A separately logged oversized-length run confirms the rebuilt DLL and successful rejection. No JNI warnings on the fixed path.
  • Existing MSVC/CMake, checksum-verified official CUDA 12.6 workspace headers/import library; Java uses proposed parent Target Java 8 in the parent compiler configuration jcuda-parent#2 installed normally. No software installation or global environment change.
  • Existing Preserve device identity array outputs when JNI copies storage #61 fixes copy-back for valid identity output, not this missing input bound. This independent branch does not include Preserve device identity array outputs when JNI copies storage #61; its complete patch also passes git apply --check over this guard. Combined runtime behavior was not tested. No other matching length-check contribution found.
  • No GPU data allocation, context creation, transfer, kernel, reset or ingestion pause. Driver initialization/device-name queries only. No full CUDA suite, other platforms/JVMs or generalized bounds audit of other wrappers is claimed.

CUDA contract: device-name query.

mvn -f JCudaJava/pom.xml -Dtest=JCudaDeviceNameBoundsTest "-DargLine=-Djava.library.path=<rebuilt-driver-directory>" test

The regression itself enables JNI checking in every child and propagates the selected library path.

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.

1 participant

0