SElinux 问题定位 与 添加权限

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 的相关解决方案
。。。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

空白的泡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值