GGML: Fix leak of backend buffer memory address in RPC #14882
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The RPC server sends back raw memory addresses for backend buffers via RPC in fields named
remote_ptr
. Some backends allocate this memory in the host process which can be used to defeat Address Space Layout Randomization (ASLR), an important exploit mitigation, and make it easier to exploit other vulnerabilities in the server. This change swaps out the existingunordered_map
for storing buffers in therpc_server
class for anunordered_map<uint64_t, ggml_backend_buffer_t>
. This new data structures will store an opaque random ID as a handle the client can send in future commands that the server can use to lookup the corresponding backend buffer.Note that there are other ASLR leaks in the server implementation. I haven't attempted to fix them in this PR.
Local testing with
llama-bench
and loading Llama-3-8b via RPC with both CPU and Metal backends. I cannot test other backends at this time but theoretically they should all just work given these changes are local to the RPC server.