Android开发过程中遇到的SELINUX权限问题


1、selinux权限一般问题

问题详情

log输出如下所示:

01-01 00:00:12.210 1 1 I auditd : type=1107 audit(0.0:33): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied{ set } for property=persist.sys.locale pid=476 uid=1000 gid=1000 scontext=u:r:hal_test_noch:s0 tcontext=u:object_r:exported_system_prop:s0 tclass=property_service permissive=0'

01-01 00:00:12.210 1 1 W /system/bin/init: type=1107 audit(0.0:33): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied { set } for property=persist.sys.locale pid=476 uid=1000 gid=1000 scontext=u:r:hal_test_ztt:s0 tcontext=u:object_r:exported_system_prop:s0 tclass=property_service permissive=0'

01-01 00:00:12.214 476 662 W libc : Unable to set property "persist.sys.locale" to "zh-CN": error code: 0x18

01-01 00:00:12.215 476 662 I test: PropertySet set property persist.sys.locale value is

01-01 00:00:12.226 1 1 I auditd : type=1107 audit(0.0:35): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied{ set } for property=persist.sys.locale pid=476 uid=1000 gid=1000 scontext=u:r:hal_test_ztt:s0 tcontext=u:object_r:exported_system_prop:s0 tclass=property_service permissive=0'

01-01 00:00:12.226 1 1 W /system/bin/init: type=1107 audit(0.0:35): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied { set } for property=persist.sys.locale pid=476 uid=1000 gid=1000 scontext=u:r:hal_test_ztt:s0 tcontext=u:object_r:exported_system_prop:s0 tclass=property_service permissive=0'

01-01 00:00:12.236 476 662 W libc : Unable to set property "persist.sys.locale" to "zh-CN": error code: 0x18

01-01 00:00:12.236 476 662 I test: PropertySet set property persist.sys.locale value is

01-01 00:00:12.286 1 1 I auditd : type=1107 audit(0.0:47): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied{ set } for property=persist.sys.locale pid=476 uid=1000 gid=1000 scontext=u:r:hal_test_noch:s0 tcontext=u:object_r:exported_system_prop:s0 tclass=property_service permissive=0'

01-01 00:00:12.286 1 1 W /system/bin/init: type=1107 audit(0.0:47): uid=0 auid=4294967295 ses=4294967295 subj=u:r:init:s0 msg='avc: denied { set } for property=persist.sys.locale pid=476 uid=1000 gid=1000 scontext=u:r:hal_test_noch:s0 tcontext=u:object_r:exported_system_prop:s0 tclass=property_service permissive=0'

01-01 00:00:12.290 476 662 W libc : Unable to set property "persist.sys.locale" to "zh-CN": error code: 0x18

01-01 00:00:12.290 476 662 I test: PropertySet set property persist.sys.locale value is

一个以用户 ID 为 1000 的进程(可能是一个应用程序或服务)试图设置系统属性 persist.sys.locale,但由于 SELinux 的安全策略,该操作被拒绝。触发该审计的总体进程是 init(PID 476),且该请求没有有效的用户(无效的AUID和会话ID)。SELinux 在此情况下以强制模式工作,因此拒绝了这项操作。

翻译下就是表明test模块在调用set property设置系统属性persist.sys.locale时没有exported_system_prop的set权限和获取权限

解决方法

修改hal_test_ztt.te文件,添加"exported_system_prop"的设置、获取权限。

cpp 复制代码
set_prop(hal_test_ztt, exported_system_prop)
get_prop(hal_test_ztt, exported_system_prop)

然后make selinux_policy ,将生成的selinux权限文件push到对应的位置,

一般是android的/system/etc/selinux/ 或者/vendor/etc/selinux/

push成功之后记得重启Android设备以应用新的selinux策略。

2、neverallow问题

问题详情

log:

04-03 14:30:51.659 527 527 W test: type=1400 audit(0.0:39): avc: denied { read } for name="u:object_r:default_prop:s0" dev="tmpfs" ino=13409 scontext=u:r:hal_test_ztt:s0 tcontext=u:object_r:default_prop:s0 tclass=file permissive=0

04-03 14:30:51.659 527 527 W test: type=1400 audit(0.0:39): avc: denied { read } for name="u:object_r:default_prop:s0" dev="tmpfs" ino=13409 scontext=u:r:hal_test_ztt:s0 tcontext=u:object_r:default_prop:s0 tclass=file permissive=0

04-03 14:30:51.673 527 664 W libc : Unable to set property "persist.version" to "20": error code: 0x18

04-03 14:30:51.673 527 664 E libc : Access denied finding property "persist.version"

04-03 14:30:51.674 527 664 I test: get persist.gwm.hud.version []

正在运行的名为 hal_test_ztt 的进程试图获取和设置系统属性persist.version时,但由于 SELinux 的安全策略,该操作被拒绝。

翻译下就是表明test模块在获取/设置系统属性persist.version时没有default_prop的set权限和get权限.

解决方法

如果是直接添加default_prop的设置权限,会报neverallow问题。

直接在hal_test_ztt .te文件夹添加:

cpp 复制代码
set_prop(hal_test_ztt , default_prop)
get_prop(hal_test_ztt , default_prop)

执行make selinux_policy之后提示:

libsepol.report_failure: neverallow on line 200 of system/sepolicy/public/domain.te (or line 10674 of policy.conf) violated by allow hal_test_ztt default_prop:property_service { set };

libsepol.check_assertions: 1 neverallow failures occurred

查看对应的domain.te的200行,如下所示:

cpp 复制代码
neverallow { domain -init } default_prop:property_service set;

上面的语句表示:在除了 init 以外的所有域中,禁止它们对 default_prop 类型的属性执行设置操作。

怎么解决呢?

答:有两种方法。

方法1:neverallow添加自己模块的例外,然后再自己对应的te里面配置权限。

比如自己的模块te里面写的域叫testdomain,那么直接在domain.te添加例外。注意编译遇到什么问题解决就行

cpp 复制代码
neverallow { domain -init -testdomain } default_prop:property_service set;

然后再在hal_test_ztt .te文件夹添加:

cpp 复制代码
set_prop(hal_test_ztt , default_prop)
get_prop(hal_test_ztt , default_prop)

方法2:

在property_contexts文件中添加一个别名定义,这里是定义成:test_prop,然后在hal_test_ztt .te里面添加权限:

property_contexts:

cpp 复制代码
persist.version u:object_r:test_prop:s0

hal_test_ztt .te:

cpp 复制代码
set_prop(hal_test_ztt , test_prop)
get_prop(hal_test_ztt , test_prop)

一般的,采用第二种方法。

相关推荐
虹科网络安全4 分钟前
艾体宝方案 | 释放数据潜能 · 构建 AI 驱动的自动驾驶实时数据处理与智能筛选平台
人工智能·机器学习·自动驾驶
Deepoch18 分钟前
Deepoc数学大模型:发动机行业的算法引擎
人工智能·算法·机器人·发动机·deepoc·发动机行业
2501_9401986938 分钟前
从“数据孤岛”到“智慧医脑”:实战 MCP 协议安全接入 HIS 系统,构建医疗级 AI 辅助诊断合规中台
人工智能·安全·asp.net
kuankeTech1 小时前
解决内外贸双轨制难题,外贸ERP智能引擎同步管理国内外合规与标准
大数据·人工智能·数据可视化·软件开发·erp
Hcoco_me1 小时前
大模型面试题84:是否了解 OpenAI 提出的Clip,它和SigLip有什么区别?为什么SigLip效果更好?
人工智能·算法·机器学习·chatgpt·机器人
BHXDML2 小时前
第九章:EM 算法
人工智能·算法·机器学习
q_35488851532 小时前
AI大模型:python新能源汽车推荐系统 协同过滤推荐算法 Echarts可视化 Django框架 大数据毕业设计(源码+文档)✅
大数据·人工智能·python·机器学习·信息可视化·汽车·推荐算法
陆研一2 小时前
2026国内无痛使用Gemini 3与GPT-5.2
人工智能·ai·chatgpt
Honmaple2 小时前
加载 .env 文件
人工智能
2501_937145412 小时前
神马影视8.8版2026最新版:核心技术升级与多场景适配解析
android·源码·电视盒子·源代码管理