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.
This is a issue of the
rpc-server
that I started working on around December last year, the vulnerability derives from the fact thatggml_backend_cpu_buffer_cpy_tensor
in./ggml/src/ggml-backend.cpp
'scpy_tensor
action, registered usually as.cpy_tensor
:The
ggml_backend_cpu_buffer_cpy_tensor
operation seemed secure since the implementation of the strict boundary checks (really strick) indeserialize_tensor()
afterGHSA-wcr5-566p-9cwj
,GHSA-5vm9-p64x-gqw9j
,GHSA-mqp6-7pv6-fqjf
. Which madebuf->data
pointer manipulation andwrite-what-where
andread-what-where
impossible. However, this tiny leftover from the last patch that can cause RCE from sophisticated exploitation that plays with partial-writing andggml
's unique memory management (I wrote a 10k word writeup for it very interesting). The major issue here is howggml_nbytes
is depends on aTensor
'snb[]
/ne[]
. This allows out-of-bound writing (or copying) whensrc
applied for a larger context wheresrc->data
can be in range and passesdeserialize_tensor
checks, but copies overdst->data
when we try to manipulateggml_nbytes(src)
something larger thanggml_backend_buffer_get_size(tensor->buffer);
(which is the actual size of the buffer)To mitigate this, checks are added in
rpc_server::copy_tensor
, beforedst
andsrc
being pass intodst_buf->iface.cpy_tensor
afterdeserialize_tensor
checks;Here
dst_data
(dst->data
) +src_size
(ggml_nbytes(src)
) is compared todst_base
(thedst
context,ggml_backend_buffer_get_base(dst->buffer);
) +dst_buf_sz
(realdst
buffer size,ggml_backend_buffer_get_size(dst->buffer);
). Prevents thememcpy
inggml_backend_cpu_buffer_cpy_tensor
(the actual sink) from copyingggml_nbytes(src)
(size) ofsrc->data
todst->data
, with size that's larger than thedst->data
+dst->size
(the actualdst
buffer size). Preventing the overflow (out-of-bound write) from happening, and eliminating the chance of any furthermore exploitations