Skip to content

ggml: fix size wrap in allocator and gguf alignment read - #26318

Closed
Ghost-Silver wants to merge 1 commit into
ggml-org:masterfrom
Ghost-Silver:security-fix-allocator-gguf-20260730
Closed

Ghost-Silver wants to merge 1 commit into
ggml-org:masterfrom
Ghost-Silver:security-fix-allocator-gguf-20260730

Conversation

@Ghost-Silver

@Ghost-Silver Ghost-Silver commented Jul 30, 2026 •

Copy link
Copy Markdown

Overview

我在 fuzzing GGUF 加载器时发现一个问题:分配器返回成功,但后续写入会覆盖相邻 tensor 的数据。

追查后发现是 里的 宏在做 __TEXT __DATA __OBJC others dec hex 时溢出了。当 size 接近最大值时,加法回绕成很小的数,导致分配了太小的 buffer,但 tensor 元数据仍以为 size 很大,结果越界。

这个和之前修过的 GHSA-vgg9 不是同一个问题——那个在 GGUF 解析层,这个在更底层的分配器 ,所以之前的补丁没覆盖到。

我的改法:

  1. 在 之前加一个溢出检查,如果会溢出就返回错误(不 abort)。
  2. 同时拒绝 size=0 的分配,并校验 alignment 必须是非零 2 的幂。
  3. 添加回归测试 ,所有现有测试均通过。

(注:原先提交中顺带处理的 类型校验已在上游通过 #25596 独立合入,本次 rebase 后已尊重上游实现,本 PR 聚焦解决尚未被上游覆盖的 整数溢出缺陷)

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES(仅用AI讨论过技术思路,PR描述由本人独立撰写。)

@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning labels Jul 30, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

Hi @Ghost-Silver, thanks for your contribution!

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

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.

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

@Ghost-Silver

Copy link
Copy Markdown
Author

Hi @Ghost-Silver, thanks for your contribution!

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

  • AI-generated content: While code is allowed to be generated by AI, please write the PR description and commit messages on your own without the help of AI.

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

@ggml-gh-bot 感谢提醒。
我的 PR 描述是我自己用中文独立撰写的,没有使用 AI 来生成或改写内容。
我在 AI usage disclosure 中已经说明,AI 仅用于和我讨论技术思路(例如分析调用栈、讨论修复方向),但描述和 commit 消息的文字都由我本人直接输入。
如果还有哪里不符合要求,请指出,我会配合修改。

@Ghost-Silver

Copy link
Copy Markdown
Author

Subject: Request to create private Security Advisory and coordinate CVE for allocator overflow (PR #26318)

Hello maintainers — I discovered an integer wrap in ggml_tallocr_alloc that can cause out-of-bounds writes when loading crafted GGUF data. I have opened PR #26318 which includes fixes and two regression tests; PoC and tests are available.

Summary of impact:

A size wrap in the allocator can lead to allocations smaller than intended and subsequent out-of-bounds writes when processing specially crafted GGUF files. This affects the allocator code in the repository and may be exploitable when processing untrusted model files.
Request

Could the maintainers please create a private GitHub Security Advisory for this issue and coordinate CVE allocation on behalf of the project (or advise the preferred route)?
I am willing to provide any additional PoC or test artifacts privately if needed.
I request an embargo window to allow maintainers to prepare a release and security notice; please advise a target disclosure date (I propose up to 90 days or whatever the project prefers).
Please reply within 7 days to confirm whether you will create a private advisory or prefer another disclosure route.
Relevant links

PR: #26318
PoC: I can provide it privately upon request.
Contact Ghost-Silver
E-mail: cyf31415@yeah.net (or 1113109729@qq.com)

Thank you, and please let me know how you wish to proceed.

- ggml-alloc: validate that alignment is a non-zero power of two before
  using GGML_PAD, preventing undefined behavior if assertions are
  disabled or the allocator is misconfigured.
- ggml-alloc: check for allocation size overflow before GGML_PAD and
  reject zero-size allocations, returning GGML_STATUS_FAILED instead
  of aborting. Prevents heap out-of-bounds writes from malformed
  tensor dimensions.
- test-alloc: add regression test test_tallocr_alloc_overflow.
@Ghost-Silver
Ghost-Silver force-pushed the security-fix-allocator-gguf-20260730 branch from 4e8102e to 25add14 Compare October 5, 2026 02:41
@JohannesGaessler

Copy link
Copy Markdown
Contributor

English only and any GGUF issues should be caught in gguf.cpp if at all possible. Recently there was some work regarding alignment there, only open a new PR if it's still possible to craft bad GGUF files on the latest master version.

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 testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants