Closed
[Bug-Report|缺陷反馈]: GatherV2 AICPU 负索引缺少下界检查,可能导致越界读 #8948
ayuemoonAdd on 4 days agoClosed at 4 days ago
4 days ago Added label: bug-report
ayuemoon
4 days ago Comments:
4 days ago Comments:
/assign


4 days ago Assign ayuemoon as responsible person
4 days ago Close issue
4 days ago changed custom state from 待办的 to 已完成
4 days ago Added label: resolved
Describe the current behavior / 问题描述
index/gather_v2/op_kernel_aicpu/gather_v2_aicpu.cpp中,CopyGatherV2Data对负索引加一次gather_dim_size后仅检查上界,缺少下界检查。例如
gather_dim_size=10、索引为-11时,归一化结果为-1,仍通过原有上界检查。该值随后进入params_idx,可能使BiggerMemCpy从 params 缓冲区之前读取数据,存在信息泄露或进程崩溃风险。Environment Information / 环境信息
d7c2c99a826604ada5bdf9c258500bed5d377740。Steps to reproduce the issue / 重现步骤
以下为修复前源码中的触发条件:
[-11],axis 为0,batch_dims 为0。-11归一化为-1,检查-1 < 10后继续计算源地址。params_idx为负数,形成非法源地址。极端负值-100、INT64_MIN也需要在地址计算前拦截。Describe the expected behavior / 预期结果
在归一化和源地址计算前检查原始索引范围
[-gather_dim_size, gather_dim_size)。非法索引返回KERNEL_STATUS_PARAM_INVALID,保持 AICPU 现有上界越界报错行为;合法负索引仍可正常归一化。维度为 10 时,
-10、-1、9合法,-11、-100、INT64_MIN、10非法。Related log / screenshot / 日志 / 截图
修复后已执行:
测试输出:
新增用例覆盖合法负索引边界,以及 double、complex64、complex128 对应的
-11、-100、INT64_MIN非法索引。ASan 运行未报告内存越界错误。Special notes for this issue / 备注
修复 PR:https://gitcode.com/cann/ops-nn/pull/14527
修复通过归一化前的双界检查阻止非法负索引进入地址计算。主机常量折叠与设备 AICPU 使用同一份 kernel 源码,但本次测试结果仅覆盖主机 kernel UT。