openharmony_ci c57c0eaede !8097 merge wls_20260730 into master
修改告警

Created-by: wu-liushuan
Commit-by: wu-liushuan
Merged-by: openharmony_ci
Description: ### 关联的issue:

### 修改描述(修改功能描述,规格变更说明):
优化后脚本正常跑过
![image.png](https://raw.gitcode.com/user-images/assets/4396780/bc3600be-c0c4-4d35-b405-31d590ccfc03/image.png 'image.png')
check_common_type.py检查正常拦截
![image.png](https://raw.gitcode.com/user-images/assets/4396780/2ef22270-6887-419c-86fe-c054e15b2392/image.png 'image.png')
check_context_length.py检查正常拦截
![image.png](https://raw.gitcode.com/user-images/assets/4396780/a7389317-b737-4c5e-a39d-ff466ea05468/image.png 'image.png')
![image.png](https://raw.gitcode.com/user-images/assets/4396780/7bdd2514-7a02-46a2-9ba9-a36fece29e8e/image.png 'image.png')
check_domain.py检测拦截正常
![image.png](https://raw.gitcode.com/user-images/assets/4396780/08a9da8e-6c59-4919-a3da-cab0353a9e56/image.png 'image.png')
![image.png](https://raw.gitcode.com/user-images/assets/4396780/42106d9f-bb4e-4e0f-9927-a4b90b9f54ac/image.png 'image.png')
check_file_contexts_typeattr.py检测拦截正常
![image.png](https://raw.gitcode.com/user-images/assets/4396780/2c92d66c-8b1b-4e18-a1f3-05cdd27bd62a/image.png 'image.png')
check_virtfs_access.py检测拦截正常
![image.png](https://raw.gitcode.com/user-images/assets/4396780/e5f3d74b-5657-46ed-acfb-1f3e275796e0/image.png 'image.png')

### 策略合入自检
- [X] 策略、注释不出现敏感词
- [X] 不要继续往sepolicy/base下新增策略,策略放在sepolicy/ohos_policy下,按子系统/部件存放,没有请新增目录
- [X] 如果涉及新增参数标签type ***, parameter_attr, 即type定义以parameter_attr结尾,需要与init责任田达成一致。参数规范详见:https://gitcode.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-boot-init-sysparam.md
- [X] neverallow管控请写在相应目录的public路径下,保证系统和芯片组件能同时管控
- [X] 不允许应用访问的SA服务使用neverallow规则看护
- [X] 系统参数应禁止三方应用配置
- [X] 具有写和执行的文件目录应该使用neverallow管控
- [X] bin二进制执行文件应该设置独立标签
- [X] 确保debug模式相关功能权限使用debug_only隔离
- [X] 确保开发者模式相关功能权限用developer_only隔离
- [X] 如果涉及修改neverallow策略,需要通过安全评审
    - [X] 每条neverallow语句中仅允许出现唯一的“-violator_xxx”和唯一的"-rgm_violater_xxx"
    - [X] 每条attribte violator_xx需要新增对应的neverallow violoater_xxx xxx:xxx {xxx}(该策略不在本仓库)
- [X] 如果涉及新增sh作为主体的权限allow sh b:c {xxx} 需经过DFX责任田和安全评审
- [X] 如果涉及新增su作为主体的权限allow su b:c {xxx} 无需添加,默认放行;su作为客体,需增加debug_only宏
- [X] 新增ioctl权限allow a b:c {ioctl}需跟进avc日志中答应的ioctl命令字增加对应的allowxperm规则来限制具体使用的接口。例如:allowxperm accessibility data_service_el1_file:file ioctl { 0x5413 };
详见:https://gitcode.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-security-selinux-checklist.md#涉及新增ioctl的selinux策略自检
- [X] 如果涉及hap权限,确认hap范围,如果是对全部应用使用hap_domain,allow hap_doamin xxx:xx xx
详见:https://gitcode.com/openharmony/docs/blob/master/zh-cn/device-dev/subsystems/subsys-security-selinux-checklist.md#涉及应用的selinux策略自检
- [X] 不允许使用limit_domain\default_param\default_service\default_hdf_service默认标签

See merge request: openharmony/security_selinux_adapter!8097
2026-08-24 11:01:09 +08:00
2026-03-24 16:33:04 +08:00
2025-11-09 22:33:01 +08:00
2022-04-11 14:18:25 +08:00
2026-07-21 09:02:50 +08:00
2026-08-22 16:17:11 +08:00
2026-04-20 15:22:22 +08:00
2023-06-07 15:34:50 +08:00
2026-07-14 17:37:18 +08:00
2026-07-21 15:32:18 +08:00
2026-05-12 10:06:35 +08:00
2024-11-27 07:36:34 +00:00
2025-12-10 10:35:15 +08:00
2026-01-16 17:58:09 +08:00
2022-03-18 19:46:38 +08:00
2022-03-18 19:46:38 +08:00
2026-04-02 09:49:40 +08:00
2026-04-02 09:50:23 +08:00
2026-05-12 10:06:35 +08:00

selinux_adapter

简介

SELinux (安全增强式 Linux Security-Enhanced Linux )是 Linux 历史上杰出的安全组件, 包含一组内核修改和用户空间工具,并提供了基于安全策略的强制访问控制机制( Mandatory Access Control MAC )。SELinux 已经被添加到各种 Linux 发行版中。其软件架构力图将软件执行与安全策略设计分离。本部件负责对文件,属性,服务等系统资源提供强制访问控制保护。提供neverallow规则限制系统中的高危操作,减少系统安全风险。

访问控制基本流程如下图所示: 整体架构

目录

.
├── config                  # 板侧    三方库配置文件
├── docs                    #         文档资源
│   └── images
├── interfaces
│   ├── policycoreutils     # 板侧    libload_policy.so、librestorecon.so
│   │   ├── include
│   │   └── src
│   └── tools               # 板侧    load_policy、restorecon
│       ├── load_policy
│       └── restorecon
├── scripts                 # 编译侧  策略编译脚本
├── sepolicy                # 编译侧  策略文件
└── test                    #         测试程序

约束

目前Selinux只支持RK3568

使用说明

编译镜像

运行以下命令编译打包支持 SELinux 的镜像:

本模块单独编译命令
./build.sh --product-name=rk3568 -T selinux_adapter --ccache

运行验证

将镜像烧录到开发板上,开机,通过串口拿到 Shell ,在其中执行:

ls -lZ /         # 查看文件标签
ls -lLZ /        # 查看link源文件标签
ps -eZ           # 查看进程标签
setenforce 1     # 使能selinux强制模式
setenforce 0     # 是能selinux宽容模式,当前默认宽容模式
getenforce       # 获取selinux工作模式

策略文件 /etc/selinux/targeted/policy/policy.31

文件标签规则 /etc/selinux/targeted/policy/file_contexts

selinux模式开关 /etc/selinux/config

验证时,可单独替换上述文件。

日志信息

audit: type=1400 audit(1502458430.566:4): avc:  denied  { open } for  pid=1658 comm="setenforce" path="/sys/fs/selinux/enforce" dev="selinuxfs" ino=4 scontext=u:r:hdcd:s0 tcontext=u:object_r:selinuxfs:s0 tclass=file permissive=1

日志解读
open                                #操作为open
pid=1658                            #访问主体进程号为1658
comm="setenforce"                   #访问主体进程名为setenforce
path="/sys/fs/selinux/enforce"      #被访问客体为/sys/fs/selinux/enforce
dev="selinuxfs"                     #被访问文件属于selinuxfs这一文件系统
ino=4                               #文件节点编号为4
scontext=u:r:hdcd:s0                #访问主体selinux标签为u:r:hdcd:s0
tcontext=u:object_r:selinuxfs:s0   #被访问客体selinux标签为u:object_r:selinuxfs:s0
tclass=file                         #当前告警属于file类型的操作
permissive=1                        #当前selinux处于宽容模式,只告警不做访问拦截。强制模式时,做拦截, permissive=0

策略编写

根据avc告警,获取访问信息
如:
audit: type=1400 audit(1502458430.566:4): avc:  denied  { open } for  pid=1658 comm="setenforce" path="/sys/fs/selinux/enforce" dev="selinuxfs" ino=4 scontext=u:r:hdcd:s0 tcontext=u:object_r:selinuxfs:s0 tclass=file permissive=1
对应规则为
allow hdcd selinuxfs:file open;

相关仓

涉及到的仓库有以下几个:

仓库 源码目录 说明
selinux_adapter base/security/selinux_adapter/ 策略和一些自研接口
third_party_selinux third_party/selinux/ SELinux 的主仓库
productdefine_common productdefine/common/ 添加 SELinux 组件定义
third_party_toybox third_party/toybox/ 完善了 ls 的 SELinux 支持
startup_init base/startup/init/ 系统启动加载策略并分化服务的标签
third_party_FreeBSD third_party/FreeBSD/ 提供 fts 库
third_party_pcre third_party/pcre/ 提供 pcre2 库
build build/ 编译控制
S
Description
暂无描述
Readme 94 MiB
Languages
C++ 54.3%
Python 36.3%
C 9%
Shell 0.4%