首先我们都知道,添加SELinux方法都是按这种格式来添加的 语句格式为:allow scontex tcontex:class action,但是类型比较多,有时候添加到那个文件还是不够清晰啊,能不能有工具来告诉我们 把avc报错生成对应的权限格式添加到对应的文件呢?这里还真有,有了这个工具,我们再遇到AVC报错就不用愁了,废话不多说
(一)我们还是先介绍下确定是否是SELinux的原因导致的问题,虽然网上很多,当你怀疑是SELinux原因导致的问题,用userdebug版本或者eng版本的机器执行下面语句
adb shell getenforce
Enforcing
在Enforcing模式下,除安全策略允许外的操作都会被阻止;使用setenforce命令设置成Permissive
模式,只输出警告不阻止操作
$ adb shell setenforce 0
$ adb shell getenforce
Permissive
开发如果碰到怀疑是SELinux 可以通过这种方法关闭SELiunx( setenforce 0
),以确认是不是SELinux引起的,当为Permissive模式时再去看你的问题是否存在,如果现在依然存在,那就是SELiunx问题导致的了,你需要换方向了,相反的话就是了,当然你还可以再试一下改回Enforcing模式,再验证问题依然存在,确认是SELinux原因导致无疑
$ adb shell setenforce 1
$ adb shell getenforce
Enforcing
(二)下面说工具吧,android的工具 audit2allow生成安全策略,网上关于audit2allow的文章较少,可能是用这个工具的人不多吧
1. ubuntu下安装工具
sudo apt-get install policycoreutils
安装完工具你可能看到仅有的几篇文章说此时处理你的log文件
grep "avc: *denied" log.txt > denied.txt
(这一步早晚的事,把log中的avc都提取出来放到 denied.txt),然后执行
audit2allow -i denied.txt
(我看网上都这么说的,我也执行了,但是报错啊)
unable to open (null): Bad address
其实这里是你安装了python工具之后才可以执行这个命令
2. 我们需要再安装python
sudo apt-get install python2.7
好了 现在可以执行 audit2allow -i denied.txt(这里的denied.txt千万别看错成了你的log.txt,
否则又会报错You must specify the -p option with the path to the policy file)
执行完结果见上图,其中#============= adpl ==============代表你要添加的te文件,这里我们需要找到adpl.te文件,然后添加allow adpl diag_device:chr_file { read write };,需要哪个添加那个即可