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 ,


缺陷分析反馈:
【问题确认】file 5.45(openEuler-26.09 分支)存在该越界读缺陷。do_core_note() 处理 FreeBSD 风格 NT_PRPSINFO note 时,以 file_printf(ms, ", from '%.80s'", nbuf + doff + argoff) 读取 81 字节程序名(argoff=33,ELFCLASS64),未校验 note 描述区边界。
【根因】issue 描述准确:当 note 的 doff + argoff 超出 size(如 descsz=0 且 doff==size)时,%.80s 读取越过 note 数据(以及栈上 nbuf[BUFSIZ] 缓冲)。
【本地验证】(file 5.45,gcc -fsanitize=address,构造 PoC:ELF64 core,PT_NOTE 段末尾放 FreeBSD NT_PRPSINFO note,namesz=8/descsz=0):
- 修复前:
AddressSanitizer: stack-buffer-overflow READ of size 4,调用栈do_core_note (src/readelf.c:812) <- donote <- dophn_core <- file_tryelf - 修复后:同一 PoC 无 ASan 报告,输出
ELF 64-bit LSB core file, x86-64, version 1 (SYSV), FreeBSD-style - 回归:合法 FreeBSD core(descsz=128,pr_fname="hello",pid=4242)修复前后输出一致
【修复】已回移植上游 commit 6bb1b445d5ed9127a0c5d73f1c7973fca4442b3f 到 5.45(file_printf 版本代码、行号上下文已适配),提交 PR #93 到 openEuler-26.09 分支,欢迎评审。


问题描述
src/readelf.c的do_core_note()在解析 FreeBSD 风格 ELF core 文件的NT_PRPSINFOnote 时,直接读取nbuf + doff + argoff开始的 81 字节参数名,但没有先确认 note description 是否包含该范围。构造 description 长度不足的 ELF core 文件时,file/libmagic会越过 note 数据读取相邻栈内容,造成越界读(CWE-125),并可能泄漏栈信息。影响范围
e_type == ET_CORE、含 FreeBSD 风格NT_PRPSINFOnote 且 description 长度小于argoff + 81的 ELF core 文件复现
基于 file 5.45 源码构建基线,构造 12288 字节 PoC:PT_NOTE 段长 8192 字节,末尾放入
namesz=8, descsz=0, type=NT_PRPSINFO的FreeBSDnote,使doff == size == 8192。执行:修复前输出包含:
修复后同一 PoC 不再输出
from,仅保留FreeBSD-style;构造 description 足够长的正常 FreeBSD core 文件仍输出from 'hello', pid=0,无回归。修复
回移上游提交,在读取参数名前增加
doff + argoff + 81 <= size边界检查。上游提交:https://github.com/file/file/commit/6bb1b445d5ed9127a0c5d73f1c7973fca4442b3f
openEuler 侧进展
已按 backport 规范生成
backport-elf-core-note-bounds.patch,在openEuler-24.03-LTS-SP3的 Patch1/Patch2 之后干净应用,并完成构建、PoC 对比和上游测试套件验证;PR 随后提交。上游未为此分配 CVE,属普通缺陷修复。