已关闭
[Bug-Report|缺陷反馈]: MultiScaleDeformableAttn 输入 shape 不一致时可触发 GM 越界读 #5305
cuijie创建于  8月28日关闭于  9月11日
cuijie成员
8月28日 创建

Describe the current behavior / 问题描述 (Mandatory / 必填)

MultiScaleDeformableAttn 算子 host 侧 tiling 校验不完整,存在 GM 越界读风险:

  1. op_host tiling 仅对 value、spatial_shape、attn_weight 三个输入做空指针检查,未检查 level_start_index 与 sampling_location;且未校验各输入 level 维(spatialShape[0]、attnWeight 的 level 维、location 的 level 维、levelStartIndex[0])的一致性。当各输入 level 维不一致(尤其 GE 图直连 tiling 路径,绕过 op_api CheckShape 校验)时,kernel 内 GetValue/DataCopy 会越界读对应张量。
  2. 310P kernel 逐 level 处理时未校验 spatial_shapes 中读取的 H/W 合法性,H/W 为负或 H*W 超出 numKeys 预算时 valueOffset 会越界/回绕,导致越界读。

Environment / 环境信息 (Mandatory / 必填)

  • 硬件:昇腾 Atlas 推理/训练系列(310P 等涉及该算子的产品)
  • 软件:CANN(cann/ops-nn 仓 master 分支 multi_scale_deformable_attn_function 算子)

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 构造 MultiScaleDeformableAttn 输入,使 spatial_shape[0]、attn_weight 的 level 维、sampling_location 的 level 维、level_start_index 的 size 不一致(或 GE 图直连路径下传入非法组合);
  2. 或构造 spatial_shapes 中包含非法 H/W(负值或 H*W 总和超出 value 张量实际大小)的输入;
  3. 执行算子,观察 GM 访存行为。

Describe the expected behavior / 预期结果 (Mandatory / 必填)

  • host 侧 tiling 应对全部 5 个输入做空指针检查,并校验 level 维一致性,不一致时返回 GRAPH_FAILED 并打印明确错误日志;
  • 310P kernel 应逐 level 校验 H/W 合法性(H/W > 0 且 H*W 累计不超过 numKeys 上界),非法时打印诊断信息并 Trap 报错,不发生越界读。

构造非法 shape 用例验证:修复前 kernel 越界读;修复后 tiling 返回 GRAPH_FAILED / kernel Trap 报错,打印 numLevels 一致性或 H/W 合法性诊断日志。

Special notes for this issue/备注 (Optional / 选填)

关联修复 PR:https://gitcode.com/cann/ops-nn/pulls/9456

likedislike
Ccuijie成员
8月28日 添加了label:bug-report
Ccuijie成员
8月28日 将 cuijie25 设为负责人
cuijie成员
9月8日 评论:

/close

likedislike
CANN-robot
CANN-robot成员
9月8日 评论:

Notice

@cuijie25 , this issue is linked to an open PR. Please merge the PR before closing this issue.

likedislike
cuijie成员
9月8日 评论:

/close

likedislike
CANN-robot
CANN-robot成员
9月8日 评论:

Notice

@cuijie25 , this issue is linked to an open PR. Please merge the PR before closing this issue.

likedislike
Ccuijie成员
9月8日 删除了关联的pull request:fix(msda): 加固 multi_scale_deformable_attn 输入校验,封堵 GM 越界读
cuijie成员
9月8日 评论:

/close

likedislike
CANN-robotCANN-robot成员
9月8日 issue状态由 进行中 改变为 已完成
CANN-robotCANN-robot成员
9月8日 关闭了 issue
Ccuijie成员
9月11日 重新打开了 issue
CANN-robotCANN-robot成员
9月11日 关闭了 issue
CANN-robotCANN-robot成员
9月11日 添加了label:resolved
Ccuijie成员
25 天前 关联了pull request:fix(msda): 加固 multi_scale_deformable_attn 310P 输入校验,封堵 GM 越界读