| Title | ggml-org llama.cpp up to 0.6.0 (fixed in 0.7.0 / commit 8ae386707bed05f02354dbfc6fa Out-of-bounds Write |
|---|
| Description | A heap-based out-of-bounds write vulnerability was found in ggml-org llama.cpp up to version 0.6.0.
The ggml_acc() API and its internal implementation ggml_acc_impl() in ggml/src/ggml.c accept the element offset as a
64-bit size_t. In versions up to 0.6.0 the offset was packed into the operation parameters as a 32-bit value without a
range check: int32_t params[] = { nb1, nb2, nb3, offset, inplace ? 1 : 0 };. An offset whose 32-bit truncation is
negative, for example 0xFFFFFFFFFFFFFFFC which becomes -4, is therefore stored as a negative int32_t. The compute
kernel ggml_compute_forward_acc_f32() in ggml/src/ggml-cpu/ops.cpp loads the field back with size_t offset = ((int32_t
*) dst->op_params)[3]; and the sign extension turns -4 back into the huge 64-bit value 0xFFFFFFFFFFFFFFFC.
The kernel's bounds assertion uses modular unsigned arithmetic:
GGML_ASSERT(offset + (ne10 == 0 ? 0 : ne10-1)*nb0 + (ne11 == 0 ? 0 : ne11-1)*nb1 + ... < ggml_nbytes(dst));
Because offset is close to SIZE_MAX, adding the small index terms wraps around and the comparison can pass. The
pointer expression dst->data + i1*nb1 + i2*nb2 + i3*nb3 + offset then wraps to an address before the destination
buffer. An ASan build reports a heap-buffer-overflow (WRITE and READ of size 4) four bytes before the dst allocation
when the forward pass runs with op_params[3] = -4. This corrupts heap memory and can crash the process; depending on
the heap layout it may be usable for further memory corruption.
The issue is fixed by commit 8ae386707bed05f02354dbfc6fa5ee0cf58e5f0f (PR #30135), which adds GGML_ASSERT(offset <
(size_t)(1 << 30)); to ggml_acc_impl() before the offset is narrowed. The equivalent check already existed in
ggml_set_impl(); the set_f32 and set_i32 kernels use the same signed-to-unsigned conversion and are only protected
through their constructor. Version 0.7.0 is the first release containing the fix.
Classification: CWE-197 (Numeric Truncation Error) leading to CWE-787 (Out-of-bounds Write). Triggering requires an
application that calls ggml_acc() with an offset value that truncates to a negative 32-bit integer; no remote attack
path in llama.cpp's server components was demonstrated.
Advisory: https://github.com/ggml-org/llama.cpp/pull/30135
Credit: Wanpeng Li (University of Liverpool), Zhi Wang (Nankai University),Dongbing Gang (Nankai University), |
|---|
| Source | ⚠️ https://github.com/ggml-org/llama.cpp/pull/30135 |
|---|
| User | Jasmine-tim (UID 101909) |
|---|
| Submission | 11/03/2026 13:08 (24 days ago) |
|---|
| Moderation | 11/27/2026 21:27 (24 days later) |
|---|
| Status | Accepted |
|---|
| VulDB entry | 445011 [ggml-org llama.cpp up to 0.6.0 ggml ggml/src/ggml.c ggml_acc_impl numeric truncation error] |
|---|
| Points | 20 |
|---|