Merged
[Fix][9.2.0] Fix the coredump bug caused by AICPU cache release #1126
FengHaozhanAdd on 22 days ago
[Fix][9.2.0] Fix the coredump bug caused by AICPU cache release #1126
Merged
FengHaozhanAdd on 22 days ago
FengHaozhan
FengHaozhan
22 days ago

描述

修复 AICPU 算子反复切流导致的 coredump 问题,问题及原因见 Issue。

修复方案:当 AICPU 算子缓存命中时,持有 context 的同时持有 nodedef proto,避免 FIFO 缓存队列压满后队首算子的 nodedef proto 内存被释放,从而消除异步执行期间的 UAF 窗口。

关联的Issue

#486

测试

  • cmake --build build --target aicpu_context_host -j8 通过
  • cmake --build build/device_build --target aicpu_context aicpu_cust_log -j8 通过
  • git diff --check 通过

文档更新

不涉及

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for FengHaozhan's contribution.)
FengHaozhanFengHaozhan
22 days ago Created pull request, commit b46e93d5
FengHaozhanFengHaozhan
22 days ago Associated issue: [Bug-Report|缺陷反馈]: 算子复用cache执行期没有强持有proto内存,存在UAF窗口
atomgit-bot
atomgit-bot
22 days ago Comments:

变更摘要

该 PR 为修复 AICPU 算子反复切流场景下 CpuKernelCache 缓存释放引发的 coredump(Issue #486):根因是异步执行期间 FIFO 缓存队列压满后队首算子的 nodedef proto 内存被释放,形成 UAF 窗口。改动通过在缓存命中时同时持有 context 与 nodedef proto,并将异步路径改为以 shared_ptr 值捕获相关对象,使 lambda 回调执行期间相关对象生命周期得以延长。

主要改动

  • DispatchCpuKernel 接口签名调整: cpu_kernel_cache.h 中将参数由 CpuKernelContext&、ExtInfoMsg& 引用改为 const std::shared_ptr<CpuKernelContext>&、const std::shared_ptr<ExtInfoMsg>&,并新增 const std::shared_ptr<NodeDef>& nodedef_proto 参数,以便在调度链路中传递并延长 nodedef proto 的生命周期。
  • 异步回调改为值捕获共享指针: 异步分支的 cb lambda 由捕获栈上引用改为按值捕获 ctx、ext_info_msg、nodedef_proto,回调内部以 UpdateFWKOutputShape(*ext_info_msg, *ctx) 解引用,并通过 (void)nodedef_proto; 保留该 proto 的持有,避免回调执行期间对象已被释放。
  • 缓存命中时同步取出 nodedef proto: GetCpuKernelContext 的缓存命中分支新增 nodedef_proto = cache->proto;,在返回 cache->context 的同时持有对应的 nodedef proto。
  • Block 路径同步相同处理: GetCpuKernelContextWithBlock 的缓存命中分支同样新增 nodedef_proto = cache->proto;,保证带 Block 的调用路径具备一致的生命周期保护。
  • 调用点适配新签名: RunKernel 与 RunCpuKernelWithBlock 中改为以 DispatchCpuKernel(ctx, ext_info_msg, node_def_proto) 调用,同步/异步执行分支统一通过解引用后的 *ctx、ext_info_msg->... 访问参数。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
22 days ago Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
22 days ago Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
22 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
22 days ago Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
9.2.0 ✅ Andy-lb, 刘伟 (2/2) ✅ Andy-lb (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

FengHaozhan, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
22 days ago Set pengjiahao96,FelixTang7,zhou-qilong,wangrui_,rxtfeng,loov1,TianXL,jia0liang,zl_hw,liu-wei,LiWei79,songkai111,jiangtao_rts,gitcode-chenjiao,hanxiaolong,pingchuantang,llimwang,gubaocheng,gcw_kUomxQ2l,Andy-lb as approver
CANN-robotCANN-robotCollaborators
22 days ago Set TianXL,jiangtao_rts,gitcode-chenjiao,hanxiaolong,gcw_kUomxQ2l,Andy-lb as approver
FengHaozhanFengHaozhan
22 days ago Change title to "[Fix][9.2.0] Fix the coredump bug caused by AICPU cache release", originally titled "[fix][fix-core-9.2.0] Fix the coredump bug caused by AICPU cache release".
FengHaozhan
FengHaozhan
22 days ago Comments:

compile

likedislike
FengHaozhanFengHaozhan
22 days ago Pre merge succeeded (commit_id: 7c54194635610088f07706e4489f182aa8f53108)
CANN-robot
CANN-robotCollaborators
22 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
22 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
22 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
22 days ago Added label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
21 days ago Added label: SC-SUCC
CANN-robotCANN-robotCollaborators
21 days ago Added label: BUILD-SUCC
Andy-lb
Andy-lbCollaborators
21 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
21 days ago Added label: approved
liu-wei
liu-weiCollaborators
21 days ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
21 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
21 days ago Merged pull request