Closed
[Bug-Report|缺陷反馈]: aclnnMaxPool2dWithIndicesBackward 未校验 indices 取值越界,A2 Scatter 路径越界写显存(msSanitizer: illegal write) #7068
liuhanwen8Add on Oct 21Closed at 3 days ago
yuning_chen
Oct 21 Comments:
Oct 21 Comments:
Oct 21 Assign duxinlei as responsible person
yuning_chen
Oct 22 Comments:
Oct 22 Comments:
您好,该问题已收到,当前问题 @duxinlei 处理中


17 days ago Removed responsible person duxinlei
17 days ago Assign cjz_ as responsible person
5 days ago Assign chenjiayi_ as responsible person
chenjiayi_
5 days ago Comments:
5 days ago Comments:
补充说明本问题的处理进展:
当前状态:
该 issue 当前指派给 cjz_,指派时间为 2026-11-04 17:29;关联 PR 记录为空,指派后评论区保持静止。
依据:
- 当前责任人:cjz_。
- 指派时间:2026-11-04 17:29。
- 指派后评论记录:静止。
- 关联 PR 记录:空。
后续:
请责任人补充修复计划或提交 PR;当前 master 行为核对后同步结论。


4 days ago Associated pull request
3 days ago changed custom state from 进行中 to 已完成
3 days ago Close issue
陈俊卓
3 days ago Comments:
3 days ago Comments:
已修改


3 days ago Added label: resolved
12 hours ago Removed responsible person chenjiayi_
问题描述
aclnnMaxPool2dWithIndicesBackward的资料 §约束说明 明确要求0 <= indices < H_in*W_in,但 aclnn 入口与内核都没有对这个取值范围做任何校验,A2 上按 kernel 大小分成两种后果:CMPMODE::EQ相等比较,越界值被静默丢弃:两段都返回 0,gradInput 全 0,结果错但不报错Scatter 内核(
pool_3d_common/op_kernel/arch22/max_pool3d_grad_scatter_unified.h:73,81):uint64_t outOffset = ncOffset + (uint64_t)argmaxUb.GetValue(ubOffset); // 索引直接当时偏移 DataCopyPad(this->yGm[outOffset], yUb, {1, sizeof(TGrad), 0, 0}); // 没有任何范围裁剪负的 int32 转
uint64_t后回绕,会写到缓冲区前面 4 字节;取2^30之类的大值会写到 4 GiB 之外,直接触发向量核异常507035(同流后续任务一起失败)。上游 arch35(950)内核有索引范围过滤(
op_kernel/arch35/max_pool3d_grad_with_argmax_simd.h:172-191的FilterMask3D,上下界比较 + And),arch22 缺这一层。复现环境
pooling/max_pool3d_grad_with_argmax复现步骤
基于仓内官方示例
examples/test_aclnn_max_pool2d_with_indices_backward.cpp,改三处(其余不动):// 1) 换成 Scatter 路径的形状:kernel/stride 都 16,self 64x64 → out 4x4 std::vector<int64_t> selfShape = {1, 1, 64, 64}; std::vector<int64_t> gradOutShape = {1, 1, 4, 4}; std::vector<int64_t> indicesShape = {1, 1, 4, 4}; std::vector<int64_t> gradInShape = {1, 1, 64, 64}; std::vector<int64_t> kernelSizeData = {16, 16}; std::vector<int64_t> strideData = {16, 16}; // 2) indices 全填 -1(同理可填 H*W=4096 或 2^30) std::vector<int32_t> indicesHostData = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; // 3) 用 msSanitizer 包住可执行文件 // mssanitizer --tool=memcheck -- ./demo实际结果
indices = 2^30时:aclrtSynchronizeStream返回 507035 = ACL_ERROR_RT_VECTOR_CORE_EXCEPTION。1x1x4x4、k2 s2、indices 全16=H*W 或全-1):两段都返回 0,gradInput 全 0,无任何报错。预期结果
两种后果都不该出现:
161002(ACLNN_ERR_PARAM_INVALID);FilterMask3D做范围裁剪,越界索引不参与写。备注
同目录的
aclnnMaxPool2dWithMaskBackward没有这个问题(它是 int8 位图,不走偏移寻址)。A2 上本接口实际下发的是 1 层深的 3D 池化
MaxPool3DGradWithArgmax(op_api/aclnn_max_pool2d_with_indices_backward.cpp:942),msan 日志里的 kernel 名即由此而来。