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 };
还可以使用工具简单粗暴地得到SELinux Policy语言,具体如下
ganqiao@ubuntu1:~/code$ audit2allow -i log.txt
============= system_app ==============
allow system_app system_data_file:file setattr;