Open
file: CDF 目录名未 NUL 终止导致栈越界读(待 backport 上游 029e5bae) #29
liu-haodong142Add on  10 days ago
liu-haodong142
liu-haodong142
10 days ago Create

问题描述

src/readcdf.c 的 cdf_check_summary_info() 将 CDF(OLE2)目录项名称(最多 32 个 UTF-16 字符)逐字符拷贝到 char name[__arraycount(d->d_name)](32 字节)栈缓冲区,未写入结尾 NUL,随后把该缓冲区传入 cdf_app_to_mime()。该函数使用 strcasestr() 对目录名做子串匹配,会越过 32 字节缓冲区继续读取,造成栈越界读(CWE-125 / CWE-170)。file/libmagic 常用于扫描不受信任文件,恶意 CDF 文件可触发该问题。

影响范围

  • 受影响版本:file 5.48(openEuler master 当前为 5.48-1,未含修复)
  • 触发条件:解析含 SummaryInformation 流的 CDF 文件,且目录项名称长度达到 32 个 UTF-16 字符(无 NUL);需要进入 MIME 类型判定路径(如 file --mime-type)

复现

基于 file 5.48 官方 tarball 使用 ASan 构建,构造 5632 字节 PoC CDF(目录项名称由 32 个 A 的 UTF-16 编码组成且无 NUL,SummaryInformation 流属性类型为 CDF_NULL),执行:

file --mime-type -m magic/magic.mgc poc.cdf

修复前 ASan 报告:

ERROR: AddressSanitizer: stack-buffer-overflow
READ of size 73
    #0 __interceptor_...
    #1 strcasestr
    #2 cdf_app_to_mime src/readcdf.c:130
    #3 cdf_check_summary_info src/readcdf.c:416
    #4 file_trycdf src/readcdf.c:655

修复

回移上游提交,将栈缓冲区扩大 1 字节并在拷贝后显式写入 '\0',确保传给 strcasestr() 的字符串以 NUL 结尾。

上游提交:https://github.com/file/file/commit/029e5bae7362e71671b3e1f316d4f3936d8a7819

修复后行为:同一 PoC 不再触发 ASan,输出 application/vnd.ms-office;正常文件类型识别结果与修复前一致。

openEuler 侧进展

已按 backport 规范生成补丁 backport-cdf-name-nul-terminate.patch,在 master 分支(5.48-2)验证并推送,PR 随后提交。

上游未为此分配 CVE,属普通缺陷修复。

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
10 days ago Assign VICTORY2017、mszjaas、swf504、liuzhiqiang26、louhongxiang、kouwq、dragon1147e3、liu-haodong142 as responsible person
openeuler-ci-botopeneuler-ci-botCollaborators
10 days ago Added label: sig/Storage
openeuler-ci-bot
openeuler-ci-botCollaborators
10 days ago Comments:

Welcome To openEuler Community

Hey @liu-haodong142 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: Storage ,
and any of the maintainers: @VICTORY2017, @dragon1147e3, @kouwq, @liuzhiqiang26, @louhongxiang, @mszjaas, @swf504 ,

likedislike
liu-haodong142liu-haodong142
10 days ago Associated pull request
liu-haodong142liu-haodong142
10 days ago Associated pull request
liu-haodong142liu-haodong142
10 days ago Associated pull request
huijing_zhanghuijing_zhang
4 days ago Associated pull request
huijing_zhang
huijing_zhang
4 days ago Comments:

已确认该问题并提交修复 PR:https://atomgit.com/src-openeuler/file/pull/96(目标 openEuler-26.09)。

问题确认:在 file 5.45 上用 ASan 复现成功,栈越界读位置与报告一致:

  • AddressSanitizer: stack-buffer-overflow READ of size 37
  • 栈:strcasestr <- cdf_app_to_mime (readcdf.c:130) <- cdf_check_summary_info (readcdf.c:411) <- file_trycdf

根因:cdf_check_summary_info() 把 CDF 目录名拷入 32 字节栈缓冲(无 NUL 空间)后传给 cdf_app_to_mime(),后者用 strcasestr() 扫描,未终止的 32 字符目录名导致越界读。

修复:缓冲区扩为 33 字节、拷贝上限减一、末尾置 NUL(backport 上游 commit 029e5bae)。

验证:修复后 PoC 无 ASan 报错(输出 application/vnd.ms-office);合法目录名(WordDocument)样本修复前后输出一致;上游测试套件 71 例无新增差异。

likedislike