Skip to content

ggml: fix OOB write in ggml_acc / ggml_set with negative offset - #30135

Merged
ggerganov merged 1 commit into
ggml-org:masterfrom
Jasmine-tim:fix-ggml-acc-set-negative-offset
Oct 9, 2026
Merged

ggerganov merged 1 commit into
ggml-org:masterfrom
Jasmine-tim:fix-ggml-acc-set-negative-offset

Conversation

@Jasmine-tim

Copy link
Copy Markdown

Overview

ggml_acc and ggml_set read the op offset from op_params[3] into a size_t.
op_params[3] is an int32_t. A negative value sign-extends to a huge size_t.
The existing bounds assertion then wraps around and passes. The write lands
before the dst buffer. This is an out-of-bounds write.

The fix reads the offset as int32_t, asserts it is non-negative, then casts
it to size_t. This applies to acc_f32, set_f32 and set_i32.

Additional information

The negative offset can come from the size_t to int32_t narrowing in
ggml_acc_impl and ggml_set_impl, or from the RPC GRAPH_COMPUTE path that
copies op_params from the wire without validation.

An ASan build reports heap-buffer-overflow (WRITE/READ of size 4) four bytes
before the dst buffer when the forward runs with op_params[3] = -4. With this
patch, the same input trips the GGML_ASSERT instead.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI assisted with drafting the description and locating the defect. A human reviewed and verified the fix.

ggml_acc_impl narrowed a size_t offset to int32_t without checking that it
fits, so a large offset could truncate to a negative int32_t. The forward
then sign-extended it to a huge size_t and the bounds assertion wrapped,
allowing an OOB write below the dst buffer. Check the offset before the
narrowing, matching the existing check in ggml_set_impl.
@ggml-gh-bot

ggml-gh-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

Hi @Jasmine-tim, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggerganov

Copy link
Copy Markdown
Member

The narrowing can still end up being non-negative, so albeit this fixes some cases there are still many more inputs that will not be detected.

@Jasmine-tim

Copy link
Copy Markdown
Author

I’ll figure out a better way.

@Jasmine-tim

Copy link
Copy Markdown
Author

Or do you have any ideas?

@ggerganov

Copy link
Copy Markdown
Member

Add asserts in ggml_acc_impl and ggml_set_impl.

@Jasmine-tim

Copy link
Copy Markdown
Author

Ok,i'll do that

@Jasmine-tim

Copy link
Copy Markdown
Author

Add asserts in ggml_acc_impl and ggml_set_impl.

I've finished the edits. Please review.

@Jasmine-tim

Copy link
Copy Markdown
Author

ggml_set_impl already has this check, so I added the sameGGML_ASSERT(offset < (size_t)(1 << 30)) to ggml_acc_impl and removed the forward-level assertion.

@Jasmine-tim

Copy link
Copy Markdown
Author

Add asserts in ggml_acc_impl and ggml_set_impl.

how can i get the otherone's review to merge this pr?

@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Oct 8, 2026
@ggerganov
ggerganov merged commit 8ae3867 into ggml-org:master Oct 9, 2026
1 check passed
@smkhastar2

Copy link
Copy Markdown

حالا بهتر شده . قبل از این پیج فایلهای ویندوز پر میشد ولی الان این مشکل حل شده و پایدارتر شده

ckti pushed a commit to ckti/llama.cpp-consolidated that referenced this pull request Oct 12, 2026
ggml_acc_impl narrowed a size_t offset to int32_t without checking that it
fits, so a large offset could truncate to a negative int32_t. The forward
then sign-extended it to a huge size_t and the bounds assertion wrapped,
allowing an OOB write below the dst buffer. Check the offset before the
narrowing, matching the existing check in ggml_set_impl.
@BrewTestBot BrewTestBot mentioned this pull request Oct 15, 2026
1 task done
Nathanw1014 pushed a commit to Nathanw1014/llama.cpp that referenced this pull request Oct 24, 2026
ggml_acc_impl narrowed a size_t offset to int32_t without checking that it
fits, so a large offset could truncate to a negative int32_t. The forward
then sign-extended it to a huge size_t and the bounds assertion wrapped,
allowing an OOB write below the dst buffer. Check the offset before the
narrowing, matching the existing check in ggml_set_impl.

(cherry picked from commit 8ae3867)
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 24, 2026
ggml_acc_impl narrowed a size_t offset to int32_t without checking that it
fits, so a large offset could truncate to a negative int32_t. The forward
then sign-extended it to a huge size_t and the bounds assertion wrapped,
allowing an OOB write below the dst buffer. Check the offset before the
narrowing, matching the existing check in ggml_set_impl.
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
ggml_acc_impl narrowed a size_t offset to int32_t without checking that it
fits, so a large offset could truncate to a negative int32_t. The forward
then sign-extended it to a huge size_t and the bounds assertion wrapped,
allowing an OOB write below the dst buffer. Check the offset before the
narrowing, matching the existing check in ggml_set_impl.
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