已开启
[安全问题]: 【白细胞AI辅助分析】【安全】【IPC反序列化边界检查缺失】crypto_syscall_common.c存在IPC反序列化边界检查缺失 #28
King of Harmony创建于  6月1日
King of Harmony
King of Harmony成员
6月1日 创建

感谢对OpenHarmony社区的支持与关注,欢迎反馈安全问题。

漏洞编号:

漏洞归属组件

漏洞归属版本

CVSS V3.0分值

Attack Vector(AV): Local(L) Attack Complexity(AC): Low(L) Privileges Required(PR): Low(L) User Interaction(UI): Not Required(N) Scope(S): Unchanged(U) Confidentiality Impact(C): Medium(M) Integrity Impact(I): Medium(M) Availability Impact(A): Medium(M) CVSS Base Score: 5.5

漏洞简述

【攻击链分析】
利用难度: medium
Prover验证: CONFIRMED (置信度: 0.95)

攻击场景:
恶意可信应用(TA)通过IPC向TEE OS加密驱动发送精心构造的加密参数,利用restore_attrs函数中attr_count与attr_total_len缺乏一致性校验的缺陷,在buffer首部写入超大attr_count值。这会绕过仅校验物理边界的check_attrs_size检查,导致malloc分配时发生整数溢出(分配极小堆块)或触发超大内存请求,最终通过后续的memset_s或循环赋值造成TEE OS内核态堆溢出破坏或OOM拒绝服务。

攻击步骤:

  1. {'step': 1, 'action': '恶意TA构造包含异常属性的IPC共享内存', 'code_path': 'TA -> TEE Driver IPC接口', 'detail': '攻击者在可控的共享内存中,设置attr_total_len(crypto_arg->size)为一个较小的合法值(如8字节)以通过物理边界检查,但在buffer首4字节(attr_count)写入一个极大的值(如0xFFFFFFFF)。'}
  2. {'step': 2, 'action': '绕过边界校验函数', 'code_path': 'base/tee/tee_os_framework/drivers/crypto_mgr/src/crypto_ioctl/crypto_syscall_common.c:363', 'detail': 'check_attrs_size(arg_buf, attr_total_len)仅校验了attr_total_len是否超出IPC共享内存的物理边界,未校验attr_count与attr_total_len的逻辑一致性(即attr_count * sizeof(crypto_attribute_t) + sizeof(uint32_t) <= attr_total_len),导致恶意超大attr_count被放行。'}
  3. {'step': 3, 'action': '触发整数溢出或OOM', 'code_path': 'base/tee/tee_os_framework/drivers/crypto_mgr/src/crypto_ioctl/crypto_syscall_common.c:367', 'detail': '执行malloc(*attr_count * sizeof(struct crypto_attribute_t))。若sizeof(struct crypto_attribute_t)较大,乘法在32位或64位下发生整数溢出,导致分配极小堆块;若未溢出,则请求超限内存导致malloc失败返回NULL(此处代码虽检查了NULL,但仅返回错误,若攻击者反复触发可造成OOM DoS)。'}
  4. {'step': 4, 'action': '触发堆溢出破坏TEE OS内存', 'code_path': 'base/tee/tee_os_framework/drivers/crypto_mgr/src/crypto_ioctl/crypto_syscall_common.c:374', 'detail': '若整数溢出成功分配了小堆块,后续memset_s(attr, *attr_count * sizeof(struct crypto_attribute_t), ...)将使用溢出前的巨大长度值对极小堆块进行清零,造成严重的内核态堆溢出,可覆盖TEE OS驱动关键数据结构实现权限提升。'}

PoC 概念验证:
构造一个crypto_arg结构,设置其size(attr_total_len)为8(合法物理长度,包含4字节count+4字节id),设置其buffer指向的共享内存首4字节(*attr_count)为0x40000000。假设sizeof(crypto_attribute_t)为12,0x40000000 * 12将发生整数溢出,导致malloc分配远小于预期大小的堆块,随后memset_s触发堆溢出。

前置条件:

  • 攻击者需具备在TEE环境中运行恶意TA的权限
  • 需要精确掌握sizeof(crypto_attribute_t)的值以构造能触发整数溢出的attr_count
  • 目标TEE OS的malloc实现需对极大值分配返回非NULL(即发生整数溢出截断)而非直接失败

入口点: driver — ecc_verify_digest_call() @ /home/treffen/OpenHarmony_code/base/tee/tee_os_framework/drivers/crypto_mgr/src/crypto_ioctl/crypto_syscall_ec.c:431
影响类型: uaf (high) — malloc() @ /home/treffen/OpenHarmony_code/applications/standard/photos/imageEditor/common/src/main/cpp/sdk/libs/AiModelRef/include/opencv2/core/utility.hpp:79

影响性分析说明

原理分析

受影响版本

规避方案或消减措施

修改建议: 在restore_attrs函数的check_attrs_size校验中,增加严格的逻辑一致性检查:验证 (*attr_count * sizeof(struct crypto_attribute_t) + sizeof(uint32_t)) <= attr_total_len,并在malloc前对 *attr_count * sizeof(struct crypto_attribute_t) 乘法运算进行显式的整数溢出检查(如检查结果是否小于原值或超过系统限制)。

likedislike
King of HarmonyKing of Harmony成员
6月1日 添加了label:SIG_Security
openharmony_ci
openharmony_ci成员
6月1日 评论:

感谢提交Issue!关于Issue的交互操作,请访问OpenHarmony社区支持命令清单。如果有问题,请联系 [@peterli](https://gitcode.com/peterli) [@heyanhong](https://gitcode.com/heyanhong) [@sjtugjy](https://gitcode.com/sjtugjy) 。如果需要调整订阅PR、Issue的变更状态,请访问链接


Thanks for submitting the issue. For more commands, please visit OpenHarmony Command List. If you have any questions, please refer to committer gitcode for help. If you need to change the subscription of a Pull Request or Issue, please visit the link.

likedislike
openharmony_ciopenharmony_ci成员
6月1日 添加了label:waiting_for_assign
yzmyzm
6月24日 关联了pull request:fix(crypto): add overflow checks for restored attributes
yzmyzm
7月27日 关联了pull request:修复框架组件中的安全漏洞