已关闭
[Bug]: converter_lite解析TFLITE模型时堆缓冲区溢出 #472
lizhixuan创建于 7 天前关闭于 6 天前
7 天前 关联分支 由 [] 改变为 [master]
7 天前 关联组件 由 [] 改变为 [B-SIG-Infer]
7 天前 问题后端类型 由 [] 改变为 [CPU]
lizhixuan
7 天前 评论:
7 天前 评论:
poc(MS-001_tflite_heap_buffer_overflow.poc):
8b993ad5934b4c09a39b58b499a27bcc.zip


7 天前 关联了pull request:fix: Tensor::shape()增加shape_size_合法性校验,修复恶意模型导致的堆缓冲区溢出
6 天前 关闭了 issue
6 天前 issue状态由 TODO 改变为 DONE
Checklist
🐞 问题详细描述
漏洞描述
converter_lite在将 TFLITE 模型转换到 MindSpore 格式时,常量折叠(constant folding)优化阶段存在堆缓冲区溢出漏洞,可被恶意构造的 TFLITE 模型文件触发。崩溃点位于
mindspore-lite/src/tensor.h:109的Tensor::shape():std::vector<int> shape() const { return std::vector<int>(tensor_c_.shape_, tensor_c_.shape_ + tensor_c_.shape_size_); }Tensor的shape元数据存储在定长C结构TensorC中(shape_是定长数组,MAX_SHAPE_SIZE = 16),shape_size_表示shape的元素个数。正常情况下shape_size_受Tensor构造函数和set_shape()中的shape.size() > MAX_SHAPE_SIZE防护限制(≤16)。恶意TFLITE模型导致某算子的中间 tensor 的
shape_size_被污染为巨大值(本PoC中为2^32,即4G个int,对应memmove READ 16GB)。shape()直接用shape_ + shape_size_构造std::vector<int>,从shape_(实际只分配了正常大小)越界读取4G个int,触发heap-buffer-overflow。根因是
Tensor::shape()在读取时未对shape_size_做合法性校验。虽然写侧(构造函数、set_shape)已有防护,但存在绕过写侧防护、直接污染tensor_c_的路径(如CopyTensor对整个TensorC做memcpy等),导致shape_size_巨大时shape()仍会越界读取。复现步骤
git clone --depth 1 https://atomgit.com/mindspore/mindspore-lite.git cd mindspore-lite git submodule update --init --depth 1 mindspore用官方
build.sh编译,开启 ASAN(-a on)和 Debug(-d),指定 clang 编译器:cd mindspore-lite export CC=clang CXX=clang++ LDFLAGS="-latomic" bash build.sh -I x86_64 -d -a on -S on -j$(nproc) -n off产物:
build/tools/converter/converter_lite/converter_lite# 触发 export ASAN_OPTIONS=abort_on_error=1:symbolize=1:allocator_may_return_null=1:detect_leaks=0:detect_odr_violation=0:detect_container_overflow=0 ./build/tools/converter/converter_lite/converter_lite \ --fmk=TFLITE \ --modelFile=MS-001_tflite_heap_buffer_overflow.poc \ --outputFile=/dev/nullASAN报错信息:
详细的环境信息描述
硬件:
操作系统:
软件工具链:
关键依赖库:
构建配置:
bash build.sh -I x86_64 -d -a on -S on -j$(nproc) -n offCC=clang CXX=clang++ LDFLAGS="-latomic"-a on启用(自动加-fsanitize=address -fno-omit-frame-pointer)其他辅助信息
版本信息
涉及两个仓库的master分支:
ae7d64408a7cf9c557dbb12d17083b7d0f31426678873729d699c64d0ee6d638e633edfd2df84e7eThanks for contributing 🎉!