一 流程
- 1.查看权限69
ps -A
cat /proc/kmsg
- 获取当前设备selinux的权限问题
getenforce
setenforce
- 修改selinux配置文件
4.selinux system_app.te文件
!!通过下面两个命令,可以生成selinux语句
adb pull /sys/fs/selinux/policy
adb shell dmesg | audit2allow -p policy
allow init sysfs_usb_mode:file { write };
allow scontext tcontext:tclass { operation };
二 权限说明
avc权限说明:
type=1400 audit(0.0:41): avc: denied { read } for name=“u:object_r:media_prop:s0” dev=“tmpfs” ino=11511 scontext=u:r:mediacodec:s0 tcontext=u:object_r:media_prop:s0 tclass=file permissive=0
1、缺少的权限:{ permission }
2、哪个进程:scontext=u:r:进程:s0
3、哪个对象缺少:tcontext=u:object_r:对象:s0
4、缺少要访问的对象:tclass=被访问对象
type=1400 audit(0.0:18): avc: denied { ioctl } for path=“socket:[57632]” dev=“sockfs” ino=57632 ioctlcmd=8927 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:untrusted_app:s0:c512,c768 tclass=tcp_socket permissive=0
像上述avc权限,有ioctlcmd值时,
1、在system/sepolicy/ioctl_defines找到对应定义
如上述ioctlcmd=8927,对应是define(SIOCGIFHWADDR',
0x00008927’)
2、在system/sepolicy/untrusted_app.te(对应scontext)添加 allowxperm
untrusted_app self:tcp_socket ioctl SIOCGIFHWADDR; 格式:allowxperm
{tcontext} self:{tclass} ioctl SIOCGIFHWADDR;
type=1400 audit(0.0:9): avc: denied { getattr } for path=“/dev/block/mmcblk1p12” dev=“tmpfs” ino=2369 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:block_device:s0 tclass=blk_file permissive=0
像上述avc中的c512,c768,需要在mlstrustedsubject
例如上述avc需修改:
system/sepolicy/untrusted_app.te
--- type untrusted_app, domain;
+++ type untrusted_app, domain, mlstrustedsubject;
+++ allow untrusted_app block_device:blk_file getattr;
type=1400 audit(0.0:41): avc: denied { read } for name="u:object_r:media_prop:s0" dev="tmpfs" ino=11511 scontext=u:r:mediacodec:s0 tcontext=u:object_r:media_prop:s0 tclass=file permissive=0
像上述的,只需添加
/system/sepolicy/mediacodec.te
allow mediacodec media_prop:file { read };
1.ls -Z 查看文件的selinux权限
2.ps -Z 查看进程selinux权限
//3.关于selinux rc文件 service 启动脚本的权限问题
1.添加sh rc文件 : xxx.rc xxx.sh
2.添加te文件 :xxx.te 并配置权限
3.修改file_contexts 文件: #/(vendor|system/vendor)/bin/deletelog.sh u:object_r:delete_log-sh_exec:s0
//file_contexts 脚本文件定义
//property_contexts 属性定义
//service_contexts 服务定义
//hwservice_contexts hal服务定义
编译遇到neverallow 问题,在提示的文件中,把type加上前面加上-,如 -xxx
三 验证
编译后,替换到车机 /system/etc/selinux 和 vendor/etc/selinux
四 新增.te文件
1.user=system seinfo=platform name=包名 domain= te文件名 type=system_app_data_file
2.新增对应.te文件,如:
type xxxx, domain,coredomain; typeattribute
xxxx xxxdomain;
app_domain(xxxx)