init启动Native Service时出现Service xxxx needs a SELinux domain defined;

在android 5.0 后, 默认启用了Enforcing SELinux. 有很多同仁经常会从kernel log 中看到这样
的警告.
"[1:init]init: Warning! Service xxxx needs a SELinux domain defined; please fix!"
其原因是因为Google 要求init 启动service 时,都要进行SELinux domain 切换,即从init
domain 切换到另外的domain. 这个是从安全方面考虑的, 默认init domain 的SELinux 权限很大,
可以做很多危险行为,比如mount image, kill process 等等. 如果普通service 使用 init
domain, 就增大了可攻击的安全面.
Google 在CTS 中有对这一项进行检查, CTS fail of android.security.cts.SELinuxDomainTest
# testInitDomain
通常情况下,如果init 启动的是一个可快速执行完的oneshot 的service, 即非deamon 程序, “一
闪而过” 的话,可以不进行domain 切换. 此类CTS 检测不到. 如果init 启动的是常驻内存的
deamon service, 那么一定要进行domain 切换.(L0/L1 版版本)
但在M版本上,Google 增强了这块的约束,通过使用neverallow init { file_type fs_type}:file
execure_no_trans;严格限制了init 启动service 都必须进行domain 切换,否则service 无法启动
!!!
下面是一个demo, 方便大家参考.
定义一个init 启动的service, demo_service, 对应的执行档是/system/bin/demo.
(1). 创建一个demo.te 在/device/mediatke/common/sepolicy 目录下, 然后在
/device/mediatke/common/BoardConfig.mk 的BOARD_SEPOLICY_UNION 宏中新增 demo.te (注意: M
版本后取消了BOARD_SEPOLICY_UNION 宏,不需要再修改了,添加了文件即可)
(2). 定义demo 类型,init 启动service 时类型转换, demo.te 中
type demo, domain;
type demo_exec, exec_type, file_type;
init_daemon_domain(demo)
(3). 绑定执行档 file_context 类型
/system/bin/demo u:object_r:demo_exec:s0
(4). 根据demo 需要访问的文件以及设备, 定义其它的权限在demo.te 中.
如果大家需要更加深入理解SELinux ,可以参考:
mtk Online SELinux Topic, 没有比这更加完整的文档了.
http://online.mediatek.com/_Layouts/15/mol/topic/ext/Topic.aspx?id=158
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值