Closed
[Bug-Report|缺陷反馈]: 算子复用cache执行期没有强持有proto内存,存在UAF窗口 #486
WBiXinAdd on Oct 8Closed at Oct 20
WBiXin
Oct 8 Comments:
Oct 8 Comments:
/assign @FengHaozhan


CANN-robot
Oct 8 Comments:
Oct 8 Comments:
FengHaozhan
Oct 8 Comments:
Oct 8 Comments:
/assign


Oct 8 Assign FengHaozhan as responsible person
Oct 20 Associated pull request
FengHaozhan
Oct 20 Comments:
Oct 20 Comments:
错误根因:
device 侧的 AICPU 算子上下文缓存(CpuKernelCache)存在bug——缓存命中路径只持有 context、不持有 NodeDef proto(生命周期漏洞),叠加 FIFO 式淘汰(命中不刷新位置) 和 Host 侧 Sort 算子多流切换导致每次切换都向这个全设备共享缓存灌入全新 kernelId(容量 1024,被灌爆进入永久淘汰风暴)。固定单流执行、每次都命中缓存的 Cumsum算子,其缓存条目老化到队尾后被一次并发的 Sort 插入淘汰,正在执行中的 Cumsum 的 proto 被 free,GetDimSizes() 读取已释放内存 → SIGSEGV(Use-After-Free)。


FengHaozhan
Oct 20 Comments:
Oct 20 Comments:
修复方案:
当aicpu算子缓存命中时,持有context的同时持有nodedef proto,避免FIFO缓存队列压满,导致队首算子nodedef proto内存释放。


Oct 20 Close issue
Oct 20 Added label: resolved
22 days ago Associated pull request
22 days ago Associated pull request
22 days ago Associated pull request
22 days ago Associated pull request
22 days ago Associated pull request
Describe the current behavior / 问题描述 (Mandatory / 必填)
cumsum aicpu算子执行时coredump,解析core文件发现访问算子的输出tensor的内存,访问该nodedef protobuf内存时挂掉。
在算子执行时,会根据kernel Id查找一个全局唯一的算子cache缓存,该cache是一个FIFO队列,该缓存持有了nodedef protobuf内存。
cumsum算子不更换流,自始至终复用同一个cache,由于sort算子交替执行,kernel Id不断增长(日志中增长了3000多),导致cache队列不断被刷新
当cumsum算子的cache刚好处于队首时,新入队一个sort算子的缓存,会释放cumsum算子的cache,导致nodedef protobuf内存被释放,如果此时刚好有cumsum算子正在执行并且访问该内存,就会coredump。
定位为aicpu算子复用cache执行期没有强持有proto内存,存在UAF窗口
Environment / 环境信息 (Mandatory / 必填)
硬件:910C
软件环境:CANN9.0.0,Pytorch 2.9
Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)
两个AICPU算子异步执行,一个频繁切流,一个固定在一条流上频繁执行
Describe the expected behavior / 预期结果 (Mandatory / 必填)
两个AICPU算子,一个频繁切流,一个固定在一条流上频繁执行且不会因为cache内存被释放而core dump
Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
[rank11]: E39999[PID: 5514] 2026-09-12-09:57:11.365.844 (E39999): The error from
[rank11]: device(chipId:5, dieId:1), serial number is 14, an exception occurred during
[rank11]: AICPU execution, stream_id:5, task_id:39255, errcode:0, msg:aicpu execute
[rank11]: failed.[FUNC:ProcessStarsAicpuErrorInfo][FILE:device_error_proc.cc][LINE:1644]
[rank11]: TraceBack (most recent call last):
[rank11]: Kernel task happen error, retCode=0x2a, [aicpu
[rank11]: exception].[FUNC:PreCheckTaskErr][FILE:davinci_kernel_task.cc][LINE:1729]
[rank11]: Aicpu kernel execute failed, device_id=11, stream_id=5, task_id=39255,
[rank11]: soName=libcpu_kernels.so, funcName=RunCpuKernel, kernelName=Cumsum,
[rank11]: errorCode=0x2a.[FUNC:PrintAicpuErrorInfo][FILE:davinci_kernel_task.cc][LINE:1435
[rank11]: ]
[rank11]: rtStreamSynchronizeWithTimeout execution failed, reason=aicpu
[rank11]: exception[FUNC:FuncErrorReason][FILE:error_message_manage.cc][LINE:65]
[rank11]: synchronize stream with timeout failed, runtime result =
[rank11]: 507018[FUNC:ReportCallError][FILE:log_inner.cpp][LINE:148]
Special notes for this issue/备注 (Optional / 选填)