Closed
[Bug-Report|缺陷反馈]: AscendRequant 输入 shape 校验缺少 rank 前置判断,存在越界读/写风险(质量加固) #8164
renshuojianAdd on  16 days agoClosed at  16 days ago
renshuojian
renshuojianCollaborators
16 days ago Create

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

  • ValidateBroadcastShape 逐维按下标 xShape[xRank - scaleRank + i] 取 x 的对应维,但函数自身未校验 scaleRank <= xRank,也未对空 shape 做保护。函数声明在 op_host/arch35/ascend_requant_tiling_arch35.h,属于 public_api,头文件未声明该前置条件。
  • 当前唯一调用路径(op_host/arch35/ascend_requant_tiling_arch35.cpp 的 ValidateInputs → ValidateDimensions → ValidateBroadcastShape)中 ValidateDimensions 已先拦截 scaleRank > xRank,因此现网不构成可达缺陷;但该保护完全依赖调用方顺序,一旦后续被复用(新增调用点、UT 直调、其它 tiling 借用)即退化为真实的越界读 UB。
  • op_host/ascend_requant_infershape.cpp 的逐维广播检查是同样的右对齐写法,同样未在函数内部自校验秩关系。

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

950

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

  • 两个文件按仓库 build/compile_commands.json 中的编译参数执行 -fsyntax-only 检查,均通过(rc=0),无新增告警。
  • 修复后 scaleRank > xRank 与空 xShape 均在函数入口返回失败,不再进入下标计算。
  • 建议补一条 tiling UT:x=[1,4]、req_scale 秩大于 x 秩,断言返回 GRAPH_FAILED,锁住该防御分支。

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

infershape、tiling能够有效拦截异常输入。

验证ok

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

likedislike
renshuojianrenshuojianCollaborators
16 days ago Added label: bug-report
CANN-robotCANN-robotCollaborators
16 days ago Close issue
CANN-robotCANN-robotCollaborators
16 days ago Added label: resolved
chenjiayi_chenjiayi_Collaborators
8 days ago Assign chenjiayi_ as responsible person
CANN-robotCANN-robotCollaborators
8 days ago changed custom state from 进行中 to 已完成
chenjiayi_
chenjiayi_Collaborators
8 days ago Comments:

补充说明本问题的处理结果:

已修复并合入 master。AscendRequant 增加 rank 前置判断、广播形状校验与元素总数溢出校验。

修复内容(文件/函数):

  • quant/ascend_requant/op_host/ascend_requant_infershape.cpp:新增 ValidateBroadcastShape 与 ValidateTotalElements,在 infershape 与 tiling 流程拒绝广播放大、输出 shape 偏离 x、rank 越界与元素总数/步长溢出。
  • quant/ascend_requant/op_host/arch35/ascend_requant_tiling_arch35.cpp:分块与步长计算改用 __int128 累计并透传错误码。
  • quant/ascend_requant/op_kernel/arch35/ascend_requant_kernel.h:同步边界防护。

验证:

  • PR 记录 obp、david 冒烟通过。
  • UT 新增 119 行覆盖 rank、广播、输出 shape 与溢出边界。

说明:本次修改限于输入校验与边界计算,正常 shape 的计算路径保持原样。

该 issue 已关闭,修复已由 PR !13098 合入 master。

MR 链接:PR#13098

likedislike
chenjiayi_chenjiayi_Collaborators
11 hours ago Removed responsible person chenjiayi_