如果问题容易复现,我们可以先将SELinux 模式调整到Permissive mode,然后再测试确认是否与SELinux 约束相关.
在ENG 版本中:

adb shell setenforce 0

setenforce 0 设置SELinux 成为permissive模式 临时关闭selinux

setenforce 1  临时打开selinux

另外当出现selinux相关问题,我们可以通过下面的命令来抓取对应的log

adb shell

su

cat proc/kmsg

android selinux 权限问题  

对报错内容的解析

android selinux 权限问题

例如

audit(0.0:53): avc: denied { execute }for path="/data/data/com.mofing/qt-reserved-files/plugins/platforms/libgnustl_shared.so"dev="nandl" ino=115502 scontext=u:r:platform_app:s0 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=0
缺少权限:  缺少execute权限
谁缺少权限: scontext=u:r:platform_app:s0                                 
哪个文件缺少权限: tcontext=u:object_r:app_data_file            
什么类型的文件: tclass=file

解决办法:
allow platform_app app_data_file:file execute
如果是多个权限的添加可以使用下面方式:
allow mediaserver acdb_delta_file:file { create open read append getattr };

1. 简单粗暴写个rw_dir_perms,这个权限包含了{open search write …}等等很多权限,我们可以查看external/sepolicy/global_macros来了解更多权限声明;
2. 要加入的权限很多时,可以用中括号,比如
allow engsetmacaddr vfat:dir { search write add_name create};

 修改生效

在sourcecode/external/sepolicy 目录下的对应模块的policy.mk做更改,添加或者移除我们修改的.te文件

 

查看进程权限ps -Z
查看文件权限ls -Z

 

分类:

技术点:

相关文章: