已合并
feat: enable BTI branch protector for account SOs #3748
feat: enable BTI branch protector for account SOs #3748
已合并
zhenghui25创建于 24 天前
zhenghui25
zhenghui25
24 天前

关联的issue:

https://gitcode.com/openharmony/account_os_account/issues/3038

修改描述:

测试用例(附上截图):

TDD:3条失败用例于修改无关,dev用例测试通过
image.png
XTS:

手工用例:

综合代码修改检视报告

📋 检视摘要 (Executive Summary)

基本信息

项目 内容
提交哈希 801da333930fcaeaa196230d8b794a0f9cc550d2
提交信息 feat: enable BTI branch protector for account SOs
作者 zhenghui25 zhenghui25@h-partners.com
提交日期 2026-08-05
检视日期 2026-08-06
变更文件 7 个 BUILD.gn
变更行数 +7 / -0
变更类型 构建配置(GN),非 C++ 代码

变更文件列表

# 文件 目标 新增行
1 frameworks/account_iam/BUILD.gn account_iam_innerkits branch_protector_frt = "bti"
2 frameworks/authorization/BUILD.gn authorization_innerkits branch_protector_frt = "bti"
3 frameworks/osaccount/native/BUILD.gn os_account_innerkits branch_protector_frt = "bti"
4 interfaces/kits/napi/authorization/BUILD.gn authorization_napi branch_protector_frt = "bti"
5 interfaces/kits/napi/common/BUILD.gn account_napi_common branch_protector_frt = "bti"
6 interfaces/kits/napi/domain_account/BUILD.gn domain_account_napi branch_protector_frt = "bti"
7 interfaces/kits/napi/osaccount/BUILD.gn osaccount branch_protector_frt = "bti"

✅ 检查项目清单

🔐 Security Review(安全检查)

  • 内存安全: 无 C++ 代码变更,无内存风险
  • 输入验证: N/A(构建配置)
  • 权限控制: N/A(构建配置)
  • 敏感信息: 无敏感信息变更
  • 并发安全: N/A(构建配置)
  • 安全增强: BTI 是安全增强,非安全风险——启用后增加 Control-Flow 攻击防护

小计: 6/6 通过 ✅


🔍 Logic Analyzer(逻辑分析)

  • 目标完整性: 用户请求的 7 个 SO 全部覆盖,无遗漏
  • 属性值正确: "bti" 是构建系统唯一支持的合法值(cxx.gni:408
  • 属性位置一致: 7 处均在 branch_protector_ret = "pac_ret" 紧随其后
  • 前置条件满足: 7 个目标均已有 branch_protector_ret = "pac_ret",组合后产出 -mbranch-protection=pac-ret+b-key+bticxx.gni:418-420
  • 平台守护: support_branch_protector_bti 仅在 target_cpu=="arm64" && is_ohos && is_standard_system 时为 true(security_config.gni:45-49),非 arm64 平台自动跳过,不会破坏 x86 模拟器编译

小计: 5/5 通过 ✅


📊 DFX Reviewer(DFX检查)

  • 客户端禁令: N/A(无代码变更)
  • 场景区分: N/A
  • 事件覆盖: N/A
  • 数据隐私: N/A

小计: 4/4 通过 ✅(N/A 维度)


📋 Code Review Checklist(规范检查)

兼容性检查:

  • API变更: 无 — 仅构建配置,无公共/内部 API 签名变更
  • IDL接口: 无 IDL 变更
  • 错误码: 无错误码变更
  • on-disk schema: 无数据格式变更

AGENTS.md 约束检查:

  • §3.1 公共 API: 未触及 interfaces/kits/ 的接口签名
  • §3.1 SA 启动序列: 未触及 account_mgr_service.cpp
  • §3.1 Feature flags: 未修改 os_account.gni 中的 feature flag
  • §3.4 Pitfall 1-10: 均不适用(纯构建配置,非 C++ 逻辑)

属性合法性验证:

  • branch_protector_frt 是构建系统正式支持的属性(cxx.gni:291 白名单已声明,cxx.gni:407-412 已实现处理逻辑)
  • ✅ 属性值 "bti" 与构建系统判断条件 invoker.branch_protector_frt == "bti" 匹配(cxx.gni:408

小计: 9/9 通过 ✅


🧪 Test Coverage Reviewer(测试覆盖度检查)

  • 修改点性质: 仅修改 BUILD.gn 构建配置,不涉及 C++ 业务逻辑变更,无需新增测试用例覆盖
  • 编译验证: 本地已进行编译验证
  • 回归验证: BTI 是编译期标志,运行时行为透明(不支持 BTI 的 CPU 自动忽略),不需要功能测试

小计: 3/3 通过 ✅


🎨 Coding Style Review(编码风格检查)

  • GN 语法: 缩进 2 空格,符合 GN 规范
  • 属性命名: branch_protector_frt 使用下划线命名,与 branch_protector_ret 风格一致
  • 值格式: "bti" 字符串,与 "pac_ret" 风格一致
  • 放置位置: 7 处均紧跟 branch_protector_ret 之后,风格统一
  • 提交信息格式: feat: <description> 符合 Conventional Commits 规范
  • DCO 签名: Signed-off-by: zhenghui25 <zhenghui25@h-partners.com> 已包含
  • 提交信息完整性: 包含变更目的、技术原理、目标列表

小计: 7/7 通过 ✅


🎯 总体评价

维度 通过率 等级 评价
Security Review 100% (6/6) 🟢 优秀 安全增强,无风险引入
Logic Analyzer 100% (5/5) 🟢 优秀 目标完整,属性正确
DFX Reviewer 100% (4/4) 🟢 优秀 N/A
Code Review Checklist 100% (9/9) 🟢 优秀 无兼容性/约束风险
Test Coverage Reviewer 100% (3/3) 🟢 优秀 仅构建配置,本地已编译验证
Coding Style Review 100% (7/7) 🟢 优秀 风格统一

整体评分: 100/100 (🟢 优秀)

整体风险等级: 🟢 低风险

是否建议上库: ✅ (建议补充编译验证)


📊 问题统计

检查维度 问题总数 🔴 致命 🟠 严重 🟡 警告
Security Review 0 0 0 0
Logic Analyzer 0 0 0 0
DFX Reviewer 0 0 0 0
Code Review Checklist 0 0 0 0
Test Coverage Reviewer 0 0 0 0
Coding Style Review 0 0 0 0
总计 0 0 0 0

检视澄清说明

# 澄清项 说明
1 仅修改 BUILD.gn 本次变更不涉及 C++ 代码,无需测试用例覆盖
2 本地已编译验证 提交前已在本地完成编译验证,编译通过
3 BTI 配置范围 当前需求仅涉及 7 个 SO,这是明确的需求边界,非遗漏

🔍 检视依据(代码级证据)

1. 构建系统对 branch_protector_frt 的处理逻辑

文件: /home/zhenghui/duli/build/templates/cxx/cxx.gni

属性白名单声明 (line 291):

                              "branch_protector_frt",

属性处理逻辑 (line 407-426):

if (defined(invoker.branch_protector_frt)) {
  if (invoker.branch_protector_frt == "bti" &&
      support_branch_protector_bti) {
    bti = true
  }
}

if (bti && pac_ret) {
  cflags += [ "-mbranch-protection=pac-ret+b-key+bti" ]
  ldflags += [ "-Wl,-z,force-bti" ]
} else if (bti && !pac_ret) {
  cflags += [ "-mbranch-protection=bti" ]
  ldflags += [ "-Wl,-z,force-bti" ]
} else if (!bti && pac_ret) {
  cflags += [ "-mbranch-protection=pac-ret+b-key" ]
}

结论: branch_protector_frt = "bti" + branch_protector_ret = "pac_ret" 组合产出 -mbranch-protection=pac-ret+b-key+bti + -Wl,-z,force-bti

2. support_branch_protector_bti 平台守卫

文件: /home/zhenghui/duli/build/config/security/security_config.gni

# pac_ret is supported in armv8.3
# bti is supported in armv8.5
if (target_cpu == "arm64" && is_ohos && is_standard_system && !is_mingw) {
  if (use_pac_ret) {
    support_branch_protector_pac_ret = true
  }
  support_branch_protector_bti = true
}

结论: BTI 仅在 arm64 + OHOS 标准系统下生效,x86 模拟器自动跳过,不会破坏编译。

3. 7 个目标的属性放置一致性验证

文件 branch_protector_ret 行号 branch_protector_frt 行号 是否紧邻
frameworks/account_iam/BUILD.gn 71 72
frameworks/authorization/BUILD.gn 71 72
frameworks/osaccount/native/BUILD.gn 66 67
interfaces/kits/napi/authorization/BUILD.gn 36 37
interfaces/kits/napi/common/BUILD.gn 36 37
interfaces/kits/napi/domain_account/BUILD.gn 36 37
interfaces/kits/napi/osaccount/BUILD.gn 43 44

总结与建议

关键发现

本次提交无致命、严重、警告问题。所有 6 个检视维度均 100% 通过。

最终评价

代码质量评分

整体评分: 100/100 (🟢 优秀)

维度 得分 等级 说明
安全性 100/100 🟢 优秀 安全增强,无风险引入
逻辑正确性 100/100 🟢 优秀 目标完整,属性值正确,平台守护完整
DFX规范性 100/100 🟢 优秀 N/A
代码规范性 100/100 🟢 优秀 无兼容性/约束风险
测试覆盖度 100/100 🟢 优秀 仅构建配置,本地已编译验证
编码风格 100/100 🟢 优秀 风格统一,DCO 签名完整

上库决策

是否建议上库: ✅

上库前置条件


附录

A. 检查文件列表

frameworks/account_iam/BUILD.gn
frameworks/authorization/BUILD.gn
frameworks/osaccount/native/BUILD.gn
interfaces/kits/napi/authorization/BUILD.gn
interfaces/kits/napi/common/BUILD.gn
interfaces/kits/napi/domain_account/BUILD.gn
interfaces/kits/napi/osaccount/BUILD.gn

B. 参考文档

  • 构建系统处理逻辑: build/templates/cxx/cxx.gni:407-426
  • 平台守卫配置: build/config/security/security_config.gni:45-49
  • AGENTS.md 约束: AGENTS.md §3.1, §5.1

C. 检视信息

  • 检视者: AI Assistant (comprehensive_review skill v1.3)
  • 检视日期: 2026-08-06
  • 报告版本: v1.0

报告生成时间: 2026-08-06
报告生成工具: Comprehensive Code Review Skill v1.3

兼容性上库自检:

日志规范自检:

安全编码自检:

是否已执行L0用例

likedislike
Pull Request已成功合入, 合并人@openharmony_ci
(感谢 zhenghui25 的贡献)
AsterNighT
AsterNighT
24 天前 评论:

AI检视任务后台执行中,稍候返回结果。

The AI Review task is being executed in the background and will return results shortly.

您可通过评论"list commands"来查询命令列表。
You can leave a "list commands" comment to get commands list.

likedislike
openharmony_ci
openharmony_ci成员
24 天前 评论:

感谢提交 Pull Requests !此PR未通过DCO校验。
校验失败可能原因:

1. 未签署“DCO协议”(开发者原创声明协议),在线签署、查看签署状态

2. Commits 中未包含 Signed-off-by信息,参考FAQ处理

修复上述问题后,在PR的评论框输入“check dco” ,单击”评论”,系统将再次进行DCO校验。

当前检测到如下Commits 未包含Signed-off-by信息:


Thanks for submitting a pull request. This pull request has not passed the DCO check.
Possible causes:

1. You have not signed the Developer Certificate of Origin (DCO). Sign the DCO and check DCO status.

2. The commits do not contain the Signed-off-by information. To resolve this issue, see FAQs.

After resolving the preceding issues, enter check dco in the comment box of this pull request and click Comment. The system will check DCO status again.

The following commits do not contain the Signed-off-by information:

likedislike
openharmony_ciopenharmony_ci成员
24 天前 添加了label:waiting_on_author
openharmony_ciopenharmony_ci成员
24 天前 添加了label:dco检查失败
zhenghui25zhenghui25
24 天前 修改了pull request 的描述
zhenghui25zhenghui25
24 天前 强制推送  1 个提交:801da333-feat: enable BTI branch protector for account SOs
openharmony_ci
openharmony_ci成员
24 天前 评论:

感谢提交 Pull Requests!如果您提交的PR已经开发完毕,请评论 "start build" 触发门禁,更多交互操作,请访问OpenHarmony社区支持命令清单。如果需要调整订阅PR、Issue的变更状态,请访问订阅链接


Thanks for submitting the pull request. If your Pull Request has already been developed, you can leave a "start build" comment to trigger the gated system. For more commands, please visit OpenHarmony Command List. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ci成员
24 天前 删除了label:dco检查失败
openharmony_ciopenharmony_ci成员
24 天前 添加了label:dco检查成功
zhenghui25
zhenghui25
24 天前 评论:

start build

likedislike
openharmony_ci
openharmony_ci成员
24 天前 评论:

首次触发
门禁构建开始,包含静态检查、代码编译和测试【part_compile编译, dayu600_7885测试, ohos-host_mini_tdd编译, dayu200测试, master_inner_build编译, dayu600_7885编译, x86_64_virt编译, dayu200编译, dayu200_tdd编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6a72b55c64650f998b9fcdba/runlist

likedislike
openharmony_ciopenharmony_ci成员
24 天前 添加了label:编译成功
openharmony_ciopenharmony_ci成员
24 天前 添加了label:静态检查成功
openharmony_ciopenharmony_ci成员
24 天前 添加了label:冒烟测试成功
openharmony_ciopenharmony_ci成员
24 天前 通过测试
openharmony_ci
openharmony_ci成员
24 天前 评论:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6a72b55c64650f998b9fcdba/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result test result package
1 dayu200 success success >>>
2 dayu200_tdd success NA >>>
3 part_compile success(IGNORE) NA >>>
4 master_inner_build success NA >>>
5 ohos-host_mini_tdd success NA >>>
6 dayu600_7885 success success(IGNORE) >>>
7 x86_64_virt success NA >>>

likedislike
openharmony_ciopenharmony_ci成员
24 天前 删除了label:waiting_on_author
openharmony_ciopenharmony_ci成员
24 天前 添加了label:waiting_for_review
openharmony_ci
openharmony_ci成员
24 天前 评论:

您好,Committer @JiDong-CS1 @steven-q @linshuqing @chennian ,请分配检视人员检视该PR,可以通过命令"assign [@someone_id]"分配检视人员,也可以直接评论"assign"分配给自己进行检视。


Hello, Committer @JiDong-CS1 @steven-q @linshuqing @chennian . Please assign someone to review the PR. You can assign a reviewer by using the command "assign [@someone_id]", or you can comment "assign" to review the PR by yourself.

likedislike
zhenghui25zhenghui25
23 天前 修改了pull request 的描述
zhenghui25zhenghui25
23 天前 修改了pull request 的描述
zhenghui25zhenghui25
23 天前 修改了pull request 的描述
steven-qsteven-q成员
23 天前 通过审查
openharmony_ci
openharmony_ci成员
23 天前 评论:

验证结果已超过12小时,之前验证结果无效,自动重新触发构建,请关注最新验证结果

likedislike
openharmony_ci
openharmony_ci成员
23 天前 评论:

start build

likedislike
openharmony_ciopenharmony_ci成员
23 天前 删除了label:编译成功
openharmony_ciopenharmony_ci成员
23 天前 删除了label:静态检查成功
openharmony_ciopenharmony_ci成员
23 天前 删除了label:冒烟测试成功
openharmony_ci
openharmony_ci成员
23 天前 评论:

本地或库上代码有更新,全量重新构建,重置所有关联PR的验证状态
门禁构建开始,包含静态检查、代码编译和测试【ohos-host_mini_tdd编译, dayu600_7885测试, dayu200_tdd编译, x86_64_virt编译, dayu200编译, dayu600_7885编译, part_compile编译, dayu200测试, master_inner_build编译】,预计在60分钟内完成,门禁结果会同步发送到注册邮箱。您可以通过如下链接跟踪门禁进展:http://dcp.openharmony.cn/workbench/cicd/detail/6a7428b964650f998b1f9d2c/runlist

likedislike
openharmony_ciopenharmony_ci成员
23 天前 添加了label:编译成功
openharmony_ciopenharmony_ci成员
23 天前 添加了label:静态检查成功
openharmony_ciopenharmony_ci成员
23 天前 添加了label:冒烟测试成功
openharmony_ciopenharmony_ci成员
23 天前 通过测试
openharmony_ci
openharmony_ci成员
23 天前 评论:

代码门禁通过
您可以通过如下链接查看门禁报告:http://dcp.openharmony.cn/workbench/cicd/detail/6a7428b964650f998b1f9d2c/runlist

静态检查:

# check type result report
1 codeCheck pass >>>

编译测试:
# Device build result test result package
1 dayu200 success success >>>
2 dayu200_tdd success NA >>>
3 part_compile success(IGNORE) NA >>>
4 master_inner_build success NA >>>
5 ohos-host_mini_tdd success NA >>>
6 dayu600_7885 success success >>>
7 x86_64_virt success NA >>>

likedislike
openharmony_ci
openharmony_ci成员
23 天前 评论:

您好,Committer @JiDong-CS1 @steven-q @linshuqing @chennian ,请分配检视人员检视该PR,可以通过命令"assign [@someone_id]"分配检视人员,也可以直接评论"assign"分配给自己进行检视。


Hello, Committer @JiDong-CS1 @steven-q @linshuqing @chennian . Please assign someone to review the PR. You can assign a reviewer by using the command "assign [@someone_id]", or you can comment "assign" to review the PR by yourself.

likedislike
openharmony_ciopenharmony_ci成员
23 天前 关闭了关联的issue
openharmony_ciopenharmony_ci成员
23 天前 合入了pull request,合并节点 SHA:0bcdbb23ca9fb3f33e021a0b40e09ad7a08a7f56
openharmony_ciopenharmony_ci成员
23 天前 删除了label:waiting_for_review
openharmony_ciopenharmony_ci成员
23 天前 添加了label:merged