已合并
[fix] AlltoAll入口在访问DATATYPE_SIZE_TABLE前校验sendType合法性,修复数组越界 #3136
ccs创建于 9月15日
[fix] AlltoAll入口在访问DATATYPE_SIZE_TABLE前校验sendType合法性,修复数组越界 #3136
已合并
ccs创建于 9月15日
ccs
ccs成员
9月15日

描述

HcclAlltoAll 的参数校验函数 CheckAlltoAllInputPara 中存在数组越界风险:

校验流程中,溢出检查语句在确认 sendType 是否为合法 HcclDataType 之前,
就使用 sendType 作为下标访问 DATATYPE_SIZE_TABLE:

CHK_PRT_RET(sendCount > UINT64_MAX / DATATYPE_SIZE_TABLE[sendType], ...);

DATATYPE_SIZE_TABLE 数组长度为 HCCL_DATA_TYPE_RESERVED,合法下标范围是
0 ~ HCCL_DATA_TYPE_RESERVED - 1。当外部传入 sendType = recvType =
HCCL_DATA_TYPE_RESERVED 时:

  1. 类型相等性检查(sendType != recvType)通过,无法拦截;
  2. 随后 DATATYPE_SIZE_TABLE[HCCL_DATA_TYPE_RESERVED] 下标等于数组长度,
    构成 one-past-the-end 越界访问;
  3. 外层 CheckDataType 在 CheckAlltoAllInputPara 之后才调用,无法提前拦截。

修改方案

在溢出检查访问 DATATYPE_SIZE_TABLE 之前,新增 sendType 合法性校验,
不合法时直接返回 HCCL_E_PARA:

关联的Issue

https://gitcode.com/cann/hccl/issues/674

测试

RDV

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 ccs 的贡献)
ccsccs成员
9月15日 创建了 pull request,commit d4649af6
atomgit-bot
atomgit-bot
9月15日 评论:

变更摘要

本 PR 针对 Issue #674,在 HcclAlltoAllV 的参数校验函数 CheckAlltoAllInputPara(位于 src/ops/all_to_all_v/all_to_all_v.cc)中新增了对 sendType 数据类型的合法性校验:当 sendType >= HCCL_DATA_TYPE_RESERVED 时判定为非法参数,记录错误日志并返回 HCCL_E_PARA,从而在原有空指针、缓冲区相同、大小溢出等校验基础上补齐了数据类型的边界检查,避免非法数据类型进入后续处理流程。

主要改动

  • 新增 sendType 合法性校验: 在 CheckAlltoAllInputPara 中增加 CHK_PRT_RET 检查,当 sendType 大于等于 HCCL_DATA_TYPE_RESERVED 时输出 "sendType[%u] is invalid" 错误并返回 HCCL_E_PARA,将非法数据类型在入口处拦截。
  • 错误码与返回路径统一: 新增校验沿用既有的 HCCL_ERROR 日志与 HCCL_E_PARA 参数错误码约定,与同函数内其他参数校验(如空指针、sendBuf/recvBuf 相同、大小溢出)保持一致的处理方式。
likedislike
不准确?
atomgit-bot
atomgit-bot
9月15日 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
9月15日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
9月15日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
src ✅ 李标智, 陈毅 (2/2) ✅ 李标智 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

cuishuang1, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robot成员
9月15日 将adum,leabclove,weixin_43960572,yanglianxiang2,linyf950,yanzhenghang,chenliang267,yanyefeng,zhongyu1,chenhao_,songmingyang,wenxuemin,yangshaohua,bz_lee,chenyia,zhangxp1030,silencesirius设为评审人
此处折叠了6条事件消息 查看更多
CANN-robotCANN-robot成员
9月16日 添加了label:cann-cla/yes
ccs
ccs成员
9月16日 评论:

/compile

likedislike
ccsccs成员
9月16日 预合并成功(commit_id: 2f187c52790d913a10e30906e1336934c3d1b92a)
CANN-robot
CANN-robot成员
9月16日 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
9月16日 添加了label:ci-pipeline-running
此处折叠了9条事件消息 查看更多
ccsccs成员
9月17日 关联了issue:【2026 HCCL通信库创新大赛-东北赛区】【这是什么地方汪汪汪汪汪汪】 HcclAlltoAll 在校验数据类型前访问 DATATYPE_SIZE_TABLE
bz_lee成员9月17日进行代码检视3
src/ops/all_to_all_v/all_to_all_v.cc
已过期
@@ -503,6 +503,7 @@ HcclResult CheckAlltoAllInputPara(
503503 std::vector<std::string>({"HcclAlltoAllV", "nullptr", "stream", "non-null pointer"}));
504504 CHK_PTR_NULL(stream);
505505 CHK_PRT_RET(sendBuf == recvBuf, HCCL_ERROR("[HcclAlltoAll] sendBuf and recvBuf cannot be same."), HCCL_E_PARA);
506+ CHK_PRT_RET(sendType >= HCCL_DATA_TYPE_RESERVED, HCCL_ERROR("sendType[%u] is invalid", sendType), HCCL_E_PARA);
bz_lee9月17日评论:

下标 ≥ 18 即会读到无意义的 0 值(非越界,但语义错误);下标 ≥ 255 才是真正的数组越界。
当255> sendType≥18 时,会返回0,那么下面sendCount > UINT64_MAX / DATATYPE_SIZE_TABLE[sendType]会有除0风险

likedislike
System
系统消息系统
9月17日 评论:

changed this line on c048eb1e view diff detail

ccs
ccs成员
9月17日 评论:

新增了DATATYPE_SIZE_TABLE[sendType] == 0的判断

ccsccs成员
9月17日 预合并成功(commit_id: c5e97cc35f4e8100304224d683f7aa9411ce80f7)
ccsccs成员
9月17日 推送  1 个提交:c048eb1e-issue674_4
ccsccs成员
9月17日 预合并成功(commit_id: d6b82df76441862f32b93f08b04cef0ca188a3e1)
CANN-robotCANN-robot成员
9月17日 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
9月17日 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
9月17日 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robot成员
9月17日 添加了label:cann-cla/yes
ccs
ccs成员
9月17日 评论:

/compile

likedislike
ccsccs成员
9月17日 预合并成功(commit_id: 04ecac06d5541b4c4bc3098bc0c1eb71f514a1a5)
CANN-robot
CANN-robot成员
9月17日 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
9月17日 添加了label:ci-pipeline-running
ccsccs成员
9月17日 修改了pull request 的描述
ccsccs成员
9月17日 修改了pull request 的描述
CANN-robotCANN-robot成员
9月17日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
9月17日 添加了label:ci-pipeline-passed
Bbz_lee成员
9月17日 解决了最后一个问题
bz_lee成员
9月17日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
9月17日 添加了label:approved
chenyia成员
9月18日 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
9月18日 添加了label:lgtm
CANN-robotCANN-robot成员
9月18日 合入了pull request