1.adb修改SELinux权限
getenforce; //获取当前SELinux模式,包含两种模式permissive,enforcing
permissive mode, in which permission denials are logged but not enforced, and enforcing mode, in which denials are both logged and enforced
setenforce 1; //设置SELinux 模式为enforcing
setenforce 0; //设置SELinux 模式为permissive
2.自定义安全策略文件
首先如何获取一段SELinux权限的打印
cat /proc/kmsg | grep denied 或者 dmesg | grep avc
实例
avc: denied { setattr } for pid=4388 comm=”chmod” name=”icons” dev=”mmcblk0p22” ino=1549398 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=1
看上去一脸懵逼,这都是什么鬼,实际上有模板比对,如下
avc: denied { 操作权限 } for pid=7201 comm=“进程名” scontext=u:r:源类型:s0 tcontext=u:r:目标类型:s0 tclass=访问类型 permissive=0
由此我们看出
操作权限:setattr
进程名: chmod
源类型 : system_app
目标类型: system_data_file
访问类型: file
修改方案在system_app.te中添加 SELinux Policy语言
allow system_app system_data_file:file { setattr };
http://blog.csdn.net/gqlovelj/article/details/70885507?locationNum=13&fps=1
遇到过一个untrusted_app的权限问题
[ 48.857930] type=1400 audit(15449.825:60): avc: denied { write } for pid=5355 comm="om.xdja.apitest" name="mmcblk1" dev="tmpfs" ino=11662 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:sd_device:s0 tclass=blk_file permissive=0
按提示加上allow untrusted_app sd_device:blk_file { open read write };根本不起作用,后面是在untrusted_app 的定义里面改的才有效:
diff --git a/system/sepolicy/untrusted_app.te b/system/sepolicy/untrusted_app.te
old mode 100644
new mode 100755
index 35c811c..05c3ac8
--- a/system/sepolicy/untrusted_app.te
+++ b/system/sepolicy/untrusted_app.te
@@ -20,7 +20,7 @@
### additional following rules:
###
-type untrusted_app, domain;
+type untrusted_app, domain, mlstrustedsubject;
参考https://blog.csdn.net/nuanhua209/article/details/56481783