已开启
[安全问题]: 【白细胞AI辅助分析】【安全】【IPC反序列化边界检查缺失】pipe.c存在IPC反序列化边界检查缺失 #23
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

漏洞简述

  1. 调用点证据:pipe_server_handler (pipe.c:64) 直接将IPC反序列化得到的 pipe_rq->count 传递给 chcore_pipe_read_local,且 check_validation 确认无任何校验。2. 数据流与边界检查:在 chcore_pipe_read_local (pipe.c:168-194) 中,虽然 MIN 宏 (line 184, 190, 193) 限制了拷贝长度 len_tmp 不超过管道源缓冲区 pf->buf 的可用数据量,防止了越界读源缓冲区,但 len_tmp 的最大值仍受 count 约束。3. 漏洞机制:如果恶意IPC客户端传入的 count 大于目标缓冲区 buf (即 pipe_rq->data) 的实际分配大小,且管道中有足够数据,line 194 的 memcpy(buf, pf->buf, len_tmp) 将导致越界写入目标缓冲区 buf,引发内存损坏。

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

攻击场景:
攻击者通过IPC向Pipe Server发送恶意的读管道请求,指定一个远大于IPC接收缓冲区实际大小的count值。由于服务端未校验count,且管道中已预置足够数据,chcore_pipe_read_local在执行memcpy时将管道数据越界写入IPC堆缓冲区,导致堆溢出。攻击者可进一步利用此堆溢出覆盖堆上关键数据结构,劫持控制流,在Pipe Server进程中实现权限提升或任意代码执行。

攻击步骤:

  1. {'step': 1, 'action': '攻击者进程通过IPC机制连接到Pipe Server,获取通信通道', 'code_path': 'pipe.c:83 init_pipe_server / IPC连接逻辑', 'detail': '攻击者利用系统正常的IPC通信机制,作为客户端注册到Pipe Server,建立可控的输入通道'}
  2. {'step': 2, 'action': '攻击者创建一个管道,并向其中写入大量数据,确保管道缓冲区处于满载或接近满载状态', 'code_path': 'pipe.c chcore_pipe_write_local', 'detail': '通过正常写操作填充管道,使得pf->write_idx - pf->read_idx的值足够大,以满足后续恶意的大count读取请求'}
  3. {'step': 3, 'action': '攻击者构造恶意的IPC消息,设置pipe_rq_type为PIPE_RQ_READ,fd指向已填充的管道,count设置为远大于IPC data柔性数组实际分配大小的值', 'code_path': 'pipe.c:60-64 pipe_server_handler()', 'detail': '利用柔性数组char data[]的特性,IPC消息实际分配的内存可能很小,但攻击者在结构体中声明极大的count,且服务端未对count与实际IPC消息长度进行一致性校验'}
  4. {'step': 4, 'action': '服务端解析IPC消息,直接将恶意的count和data指针传递给chcore_pipe_read_local,触发越界写入', 'code_path': 'pipe.c:184-194 chcore_pipe_read_local()', 'detail': '在chcore_pipe_read_local中,MIN(pf->write_idx - pf->read_idx, count)由于管道有足够数据且count极大,计算出的len将超过buf(即pipe_rq->data)的实际边界,导致memcpy(buf, pf->buf, len)发生堆溢出'}
  5. {'step': 5, 'action': '攻击者利用堆溢出覆盖Pipe Server堆上的关键数据结构(如函数指针、vtable等),劫持控制流执行任意代码', 'code_path': 'pipe.c:194 memcpy后续影响', 'detail': '溢出数据覆盖相邻堆块,当服务端后续处理被覆盖的对象时,触发控制流劫持,实现权限提升'}

PoC 概念验证:
构造一个pipe_request结构体,设置pipe_rq_type为PIPE_RQ_READ(0),fd指向一个已被攻击者写入大量数据的有效管道描述符,count设置为一个极大的值(例如0x10000,远超IPC消息分配给data[]的堆块大小)。通过IPC发送此结构体,服务端在处理时将把管道中的数据以count指定的大小拷贝到狭小的data缓冲区中,触发堆溢出。

前置条件:

  • 攻击者需要能够与Pipe Server建立IPC连接(通常普通用户进程即可满足)
  • 攻击者需要能够在目标管道中写入足够的数据以满足过大的count请求
  • 实现完整的RCE可能需要信息泄露辅助以绕过ASLR等内存保护机制

入口点: callback — pipe_server_handler() @ /home/treffen/OpenHarmony_code/base/tee/tee_os_kernel/user/system-services/chcore-libc/libchcore/porting/overrides/src/chcore-port/pipe.c:64
影响类型: memory_corruption (high) — chcore_pipe_read_local() @ /home/treffen/OpenHarmony_code/base/tee/tee_os_kernel/user/system-services/chcore-libc/libchcore/porting/overrides/src/chcore-port/pipe.c:185

影响性分析说明

原理分析

受影响版本

规避方案或消减措施

修改建议: 在pipe_server_handler中将pipe_rq->count传递给chcore_pipe_read_local之前,必须结合IPC消息的实际数据长度(ipc_get_msg_data的长度)进行严格校验,确保count不超过data柔性数组在当前IPC消息中的实际可用空间大小。

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
7月27日 关联了pull request:fix: 修复不可信输入校验问题