Android7.1添加开机启动服务程序关于Selinux权限问题说明
当需要添加一个binder服务xxx程序,并且设置成开机自启动时,需要按照如下步骤操作:
第一步,我们可以在init.rc中添加了如下代码行:
service xxxx /system/bin/xxxx
class main
user root
group root
oneshot
seclabel u:r:xxxx:s0 #这句是为加selinux权限添加的,android5.1以后不加则无法启动该服务
编译img后烧到机器,发现服务xxx无法启动,kernel log中有如下提示(例如这里新加的服务程序是eGTouchD的log):
[ 3.958386] init: Service eGTouchD does not have a SELinux domain defined.
该提示说明没有定义SELinux domain,导致服务eGTouchD无法自启动。
第二步,为了解决这个问题我们按如下方式修改并且添加sepolicy文件:
修改seplicy/file_contexts文件,添加以下内容:
/system/bin/xxx u:object_r:xxx_exec:s0
第三步,在sepolicy目录新增xxx.te文件,并在其中添加如下内容:
需要为新增的进程增加域、执行权限
type xxx, domain;
type xxx_exec, exec_type, file_type;
然后启用这个域
init_daemon_domain(xxx),
例如我下面添加的一个sepolicy/eGTouchD.te文件的例子:
type eGTouchD, domain;
type eGTouchD_exec, exec_type, file_type;init_daemon_domain(eGTouchD)allow eGTouchD init_tmpfs:file create_file_perms;
allow eGTouchD self:capability { dac_override net_admin net_raw setgid setuid };
allow eGTouchD device:dir { open read };
allow eGTouchD shell:lnk_file { read };
allow eGTouchD rootfs:lnk_file { getattr };
allow eGTouchD socket_device:sock_file { write };
详细可参考seplicy/目录下的其他te文件。
或者根据logcat中打印出来的avc:denied log报错来添加,先把相关的avc报错全部收集起来:
在相应的te、文件中增加语句,语句格式为
allow sourcecontext targetcontext:class { 许可 };
例如出现下面的avc log,可以这样添加:
[ 4.009832] type=1400 audit(1577344637.716:12): avc: denied { read } for pid=263 comm=“lowmem_manage.s” path="/system/bin/sh" dev=“mmcblk1p10”
ino=467 scontext=u:r:lowmem_manage:s0 tcontext=u:object_r:shell_exec:s0 tclass=file permissive=1
sourcecontext指的是"scontext=u:r:lowmem_manage:s0"中的lowmem_manage,targetcontext指的是"tcontext=u:object_r:rfs_system_file:s0"中的rfs_system_file,
class指的是"tclass=file"中的file,许可指的是"avc: denied { read }"中的read。
所以增加语句
allow lowmem_manage rfs_system_file:file { read };
其他avc报错可以类似添加即可。
PS:
其实有时候可以在init.xxxx.rc文件执行一些拷贝或者赋权限的操作,例如我这里:
--- a/init.tablet.rc
+++ b/init.tablet.rc
@@ -3,7 +3,13 @@ on post-fs-data#CABCchown root system /sys/class/graphics/fb0/cabcchmod 0664 /sys/class/graphics/fb0/cabc
+
+ #add for eGTouchD by czd 2020-03-05
+ chmod 0664 /sys/devices/platform/eeti_usbtp/eeti_usbtpchmod 0755 /system/bin/eGTouchD //赋权限
+ copy system/etc/eGTouchA.ini /data/eGTouchA.ini //拷贝
+ chmod 0777 /data/eGTouchA.ini
+ #add end
Android7.1添加开机启动服务程序关于Selinux权限问题说明相关推荐
- android+启动脚本,imx6q android 添加开机启动脚本
1.在xx/out/target/product/sabresd_6dq/root/init.rc中添加以下内容 ========================================== ...
- win7如何添加开机启动程序(开机就自动运行打开)
点击打开链接 win7添加开机启动程序后,开机后该程序就会运行,即是说每天都需要打开的软件可以设置为开机就可以启动,这样就简便很多了,如果有一天不需要开机自启动了,也可以把它删除即可,那么来看下过程吧 ...
- php添加开机启动脚本_centos 7.2 添加php7 的 php-fpm 开机启动
在centos7中编译安装好php后,系统重启后并不会对php进行开机启动,所以需要对centos7添加开机启动脚本对php进行开机启动服务. 手动启动:/usr/local/php/sbin/php ...
- Ubuntu下添加开机启动脚本
[转载]Ubuntu下添加开机启动脚本 原文地址:http://blog.163.com/yangshuai126%40126/blog/static/173426265201092810164155 ...
- CentOS 7添加开机启动服务/脚本
CentOS 7添加开机启动服务/脚本 一.添加开机自启服务 在CentOS 7中添加开机自启服务非常方便,只需要两条命令(以Jenkins为例): systemctl enable jenkins. ...
- windows 增加开机启动服务器,Windows Server2012删除或添加开机启动项的方法
Windows Server2012怎么删除或添加开机启动项?Windows Server 2012跟Windows8一样,拥有全新的任务管理器.Windows Server 2012可以随意在服务器 ...
- linux 添加开机启动项的三种方法。
原文地址: https://blog.csdn.net/lylload/article/details/79488968 Shell环境变量配置文件:https://blog.csdn.net/yzs ...
- Ubuntu下添加开机启动项的2种方法
Ubuntu下添加开机启动项的方法 1.方法一,编辑rc.loacl脚本 Ubuntu开机之后会执行/etc/rc.local文件中的脚本, 所以我们可以直接在/etc/rc.local中添加启动脚本 ...
- Windows快速添加开机启动项
有很多应用程序不自带开机启动的设置,前段时间发现个很快捷方便的方法添加开机启动: 如图: 打开开始菜单里面的启动中,右键打开,进去到启动的文件夹,然后只需要把程序的快捷方式放进去,就可以开机启动啦! ...
- linux 添加开机启动项的三种方法
linux 添加开机启动项的三种方法. (1)编辑文件 /etc/rc.local 输入命令:vim /etc/rc.local 将出现类似如下的文本片段: #!/bin/sh # # This sc ...
最新文章
- swift_008(Swift的类型转换)
- python获取当前年份_Python根据当前日期取去年同星期日期
- python数字处理技巧(1): 精度舍入、精确运算、格式化、进制数、大数打包解包、复数、NaN、分数
- 中国语言文学专业c刊排行榜,中国有名的文学刊物有哪些 十大中国著名文学刊物盘点...
- 使用Nexus私服代理其他maven仓库(jitpack、jcenter)
- Asp.Net Core 2.2.0-preview1已经发布
- 17 PP配置-生产计划-总体维护工厂参数
- MathType 插入定义的chapter and section break后无法隐藏
- sql 拆解函数_在SQL Server数据库中拆分字符串函数
- Javascript常见设计模式解析
- CPT205-Computer Graphics
- 外贸软件如何提升出口流程管理效率
- 数据库多表查询关联查询SQL语句
- Kano模型思考:以QQ第一版为例,如何确定产品优先级
- 新win10计算机分区,预装win10系统新电脑怎么分区
- 小程序配置px2rem
- char可以是负数吗
- DotSoft.C3DTools.v7.0.0.3民用勘测地图和GIS工具集合
- HDU 5058	 So easy (set容器大法好)
- 数据库以及Mysql入门