Skip to content

rpc : validate 2d tensor stride and catch allocation errors - #31322

Open
sohaibharraoui wants to merge 1 commit into
ggml-org:masterfrom
sohaibharraoui:fix/rpc-get-tensor-2d-validation
Open

sohaibharraoui wants to merge 1 commit into
ggml-org:masterfrom
sohaibharraoui:fix/rpc-get-tensor-2d-validation

Conversation

@sohaibharraoui

@sohaibharraoui sohaibharraoui commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This fixes a remotely triggerable crash of the RPC server through the GET_TENSOR_2D and SET_TENSOR_2D commands.

  • Validate stride >= size when n_copies > 1 in get_tensor_2d and set_tensor_2d. When stride < size (e.g. stride == 0), (n_copies - 1) * stride + size under-calculates the memory footprint, bypassing buffer/tensor bounds checks. In hardware backends like CUDA, it also breaks cudaMemcpy2DAsync (pitch >= width invariant), causing a CUDA_CHECK abort.
  • Catch std::exception around response.resize(...) in get_tensor_2d. If an allocation fails (std::bad_alloc or std::length_error), the server previously crashed the whole process via std::terminate(). It now logs the error and returns false, dropping only that client connection.

Additional information

  • Tested with a raw TCP client sending stride = 0 with n_copies = 0x8000000000000000. Unpatched server aborted (SIGABRT); patched server rejected the request cleanly and kept running.
  • The in-tree callers of ggml_backend_tensor_set_2d/get_2d (ggml-backend-meta.cpp) always pass stride >= size, so the new check does not reject legitimate requests from the RPC client.
  • Builds cleanly with -DGGML_RPC=ON.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - An AI assistant helped identify the issue and draft the patch; I reviewed every line and tested it manually with the reproducer.

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Oct 28, 2026
@sohaibharraoui
sohaibharraoui marked this pull request as ready for review October 28, 2026 16:17
@sohaibharraoui
sohaibharraoui requested a review from a team as a code owner October 28, 2026 16:17
@sohaibharraoui

Copy link
Copy Markdown
Contributor Author

Hi @am17an, this is a small follow-up in the same file that adds stride validation to get_tensor_2d and set_tensor_2d. I'd appreciate a review whenever you get the chance. Thanks

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

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant