Skip to content

rpc : fix UAF in graph_recompute leading to remote code execution - #24292

Merged
ggerganov merged 1 commit into
ggml-org:masterfrom
y198nt:fix/rpc-graph-recompute-uaf
Sep 16, 2026
Merged

ggerganov merged 1 commit into
ggml-org:masterfrom
y198nt:fix/rpc-graph-recompute-uaf

Conversation

@y198nt

@y198nt y198nt commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

The server caches the most recent compute graph per device so that GRAPH_RECOMPUTE can re-execute it without resending tensor data. The cached graph nodes hold direct pointers to backend buffers that were live at graph_compute() time. If any of those buffers is later released via FREE_BUFFER, the next GRAPH_RECOMPUTE re-executes the cached graph through the dangling pointers (use-after-free).

The bug is reachable by an unauthenticated remote client. The dangling pointers point into chunks an attacker can reshape via subsequent ALLOC_BUFFER/SET_TENSOR commands, and the resulting read/write through the cached graph is sufficient to leak libc addresses and hijack the buffer iface vtable used by BUFFER_CLEAR, yielding remote code execution.

Track the set of backend buffers each cached graph references, and drop the cached graph in free_buffer() when one of its buffers is released. The existing null-check in graph_recompute() then rejects the request and the client falls back to GRAPH_COMPUTE on the next call.

No protocol or API change.

This was previously reported via private security advisory GHSA-2phh-px2f-2qmx on 2026-04-30. Per maintainer reply on that advisory, the patch is being submitted publicly here.

@y198nt
y198nt requested a review from a team as a code owner June 8, 2026 07:17
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Jun 8, 2026

@rgerganov rgerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. I'd prefer a simpler fix where the cache is discarded on every free_buffer call.

Comment thread ggml/src/ggml-rpc/ggml-rpc.cpp Outdated
@@ -844,6 +844,7 @@ class rpc_server {
struct stored_graph {
std::vector<uint8_t> buffer;
ggml_cgraph * graph;
std::unordered_set<ggml_backend_buffer_t> buffer_refs;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for this, we can simply discard the cache whenever free_buffer is called

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, simplified as suggested, discarding all cached graphs in free_buffer() unconditionally. Re-tested locally with the same ALLOC/COMPUTE/FREE/RECOMPUTE sequence, behavior unchanged (RECOMPUTE now rejects the request, server stays alive).

The server caches the most recent compute graph per device so that
GRAPH_RECOMPUTE can re-execute it without resending tensor data. The
cached graph nodes hold direct pointers to backend buffers that were
live at graph_compute() time. If any of those buffers is later
released via FREE_BUFFER, the next GRAPH_RECOMPUTE re-executes the
cached graph through the dangling pointers (use-after-free).

The bug is reachable by an unauthenticated remote client. The
dangling pointers point into chunks an attacker can reshape via
subsequent ALLOC_BUFFER/SET_TENSOR commands, and the resulting
read/write through the cached graph is sufficient to leak libc
addresses and hijack the buffer iface vtable used by BUFFER_CLEAR,
yielding remote code execution.

Discard all cached graphs in free_buffer(). The existing null-check
in graph_recompute() then rejects the request and the client falls
back to GRAPH_COMPUTE on the next call.

No protocol or API change.
@y198nt
y198nt force-pushed the fix/rpc-graph-recompute-uaf branch from 748adaf to cd41aa1 Compare June 9, 2026 03:36
@rgerganov
rgerganov requested a review from ggerganov June 10, 2026 04:58
@y198nt

y198nt commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

any update for this PR?

@ggerganov
ggerganov merged commit 6019933 into ggml-org:master Sep 16, 2026
25 of 26 checks passed
quimmedes pushed a commit to quimmedes/cafe-llama.cpp that referenced this pull request Sep 16, 2026
…ed (ggml-org#24292)

The server caches the most recent compute graph per device so that
GRAPH_RECOMPUTE can re-execute it without resending tensor data. The
cached graph nodes hold direct pointers to backend buffers that were
live at graph_compute() time. If any of those buffers is later
released via FREE_BUFFER, the next GRAPH_RECOMPUTE re-executes the
cached graph through the dangling pointers (use-after-free).

The bug is reachable by an unauthenticated remote client. The
dangling pointers point into chunks an attacker can reshape via
subsequent ALLOC_BUFFER/SET_TENSOR commands, and the resulting
read/write through the cached graph is sufficient to leak libc
addresses and hijack the buffer iface vtable used by BUFFER_CLEAR,
yielding remote code execution.

Discard all cached graphs in free_buffer(). The existing null-check
in graph_recompute() then rejects the request and the client falls
back to GRAPH_COMPUTE on the next call.

No protocol or API change.
@BrewTestBot BrewTestBot mentioned this pull request Sep 23, 2026
1 task done
Cinderella-Man added a commit to Cinderella-Man/miner-llama that referenced this pull request Nov 24, 2026
…BUFFER (C929)

Since upstream ggml-org#24292 the server drops every graph it caches, on all of its devices, when a buffer is freed, and
rejects a GRAPH_RECOMPUTE for any of them. The client kept their uids, so the next reuse of such a graph sent a
GRAPH_RECOMPUTE: the server closed the connection and the client aborted ("Remote RPC server crashed or returned
malformed response"). A scheduler that grows a compute buffer frees the old one, so any re-plan on a server while
another scheduler's graphs are cached there triggers it (a context's pipe slots on two RPC devices did, C901).

The client now keeps each uid with a flag, true while the server holds the graph. rpc_dispatcher::free_buffer marks
every uid of that server dropped and queues the FREE_BUFFER under graph_mutex, so no GRAPH_RECOMPUTE decided before the
marking is queued after the free; graph_compute sends a dropped graph whole again. The entries stay, as on the server,
so both sides keep clearing their caches at the same point (GRAPH_CACHE_MAX). Nothing changes without RPC.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants