adb shell setenforce 0 关闭selinux 验证
selinux的配置规则:
首先要了解sepolicy的结构:
a. App进程 -> mac_permissions.xml
b. App数据文件 -> seapp_contexts
c. 系统文件 -> file_contexts
d. 系统属性 -> property_contexts
一 、预置条件:
安装audit2allow,安装方法ubuntu下执行sudo apt-get install policycoreutils.
二、通过 avc 关键字过滤log
adb logcat | grep avc > xxxx.txt 或 adb shell,执行dmesg|grep avc
查看到 log后,其实可以手动转换
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:s0tclass=file permissive=0
文件 platform_app.te
allow platform_app app_data_file:file execute;
audit(1444651438.800:8): avc: denied { search }for pid=158 comm="setmacaddr" name="/" dev="nandi" ino=1
scontext=u:r:engsetmacaddr:s0
tcontext=u:object_r:vfat:s0 tclass=dir permissive=0
文件 engsetmacaddr.te
allow engsetmacaddr vfat:dir { search write add_name create };
allow engsetmacaddr vfat:dir create_dir_perms;
audit(1441759284.810:5): avc: denied { read } for pid=1494 comm="sdcard" name="0" dev="nandk" ino=245281
scontext=u:r:sdcardd:s0
tcontext=u:object_r:system_data_file:s0 tclass=dir permissive=0
文件 sdcardd.te
allow sdcardd system_data_file:dir read;
FileBrowser( 8940): type=1400 audit(0.0:121): avc: denied { write } for name="mpctl" dev="mmcblk0p31" ino=181 scontext=u:r:platform_app:s0 tcontext=u:object_r:mpctl_socket:s0 tclass=sock_file permissive=0
三、工具 对log 进行权限转换
3.1 audit2allow -i XXX.txt
然后就可以在屏幕看到生成的权限了,如果错误少的话其实也不用这么麻烦,在log中就可以看到如何添加权限了。
注意audit2allow 它自动机械的帮您将LOG 转换成policy, 而无法知道你操作的真实意图,有可能出现权限放大问题,经常出现policy 无法编译通过的情况。
确认是哪个进程访问哪个资源,具体需要哪些访问权限,read ? write ? exec ? create ? search ?
3.2 当前进程是否已经创建了policy 文件
通常是process 的执行档.te,如果没有并且它的父进程即source context 无须访问对应的资源,则创建新的te 文件。
在L 版本上, Google 要求维护关键 security context 的唯一性, 比如严禁zygote, netd, installd, vold, ueventd 等关键process 与其它process 共享同一个security context.
创建 .te 文件
3.3 创建文件后,关联它的执行档
在 qcom 或者 mtk 目录下的
file_context 中, 关联相关的执行档.
指定一个名字,一定要以_exec结尾
如:
/system/bin/idmap u:object_r:idmap_exec:s0
/system/bin/install-recovery.sh u:object_r:install_recovery_exec:s0
/system/bin/dex2oat u:object_r:dex2oat_exec:s0
/system/bin/patchoat u:object_r:dex2oat_exec:s0
3.4 填写policy 到相关的te 文件中
如果沿用原来父进程的te 文件,则直接添加.
如果是新的文件,那么首先:
3.5 类型定义:
类型定义
external/sepolicy/device.te;
device/mediatek/common/sepolicy/device.te
类型绑定:
external/sepolicy/file_contexts;
device/mediatek/common/sepolicy/file_contexts
(1)添加type device/mediatek/common/sepolicy/device.te 中
type tfa9897_device, dev_type;
(2)关联, 在 device/mediatek/common/sepolicy/file_contexts
/dev/tfa9897(/.*)? u:object_r:tfa9897_device:s0
(3)添加对应process/domain 的访问权限. 比如上述案例, 在 device/mediatek/common/sepolicy/mediaserver.te 添加
allow mediaserver tfa9897_device:chr_file { open read write };
四,验证问题
make bootimage 然后烧录查看问题是否
MTK 的相关解决方案
。。。