android笔记 SELinux

本文介绍了如何解析和处理SELinux的错误日志,包括添加白名单以允许特定权限,以及在调试时临时关闭SELinux权限以排查问题。作者提到在解决问题后需确保所有权限正确配置,且在遇到未解决问题时可能需要临时禁用SELinux。

1.SELinux解错步骤

log信息:
11-20 02:25:12.526  8976  8976 W om.jzzh.setting: type=1400 audit(0.0:1316): avc: denied { write } for name="com.jzzh.setting-IWLR9dkz8TWizbNujdTpWw==" dev="mmcblk2p15" ino=2661 scontext=u:r:system_app:s0 tcontext=u:object_r:system_data_file:s0 tclass=file permissive=0

这个报错信息的解法为:

在system_app.te文件中加入一行
allow system_app system_data_file:file { write };
结构:allow scontext tcontext:tclass { 所需权限 }

neverallow编译报错:
libsepol.report_failure: neverallow on line 464 of system/sepolicy/public/app.te (or line 9937 of policy.conf) violated by allow system_app system_data_file:file { write };

编译错误告诉你在system/sepolicy/public/app.te的464行需要加入白名单

neverallow appdomain system_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };

这行的意思是appdomain这个类型的访问者tcontext为system_data_file,tclass为dir_file_class_set,权限为{ create write setattr relabelfrom relabelto append unlink link rename }加入白名单

目前我们需要加入白名单的是
访问类型:system_app
tcontext:system_data_file
tclass:file
权限:{ write }

加完以后:

neverallow { appdomain -system_app } system_data_file:dir_file_class_set
    { create write setattr relabelfrom relabelto append unlink link rename };

可以看到这里只是把system_app这个类型加进来,其他没有改动,因为tcontext(system_data_file)原本已经有了tclass(dir_file_class_set)是包含了file的,而后面那串权限更是包含了write

不同报错:

文件 system/sepolicy/prebuilts/api/30.0/public/app.te 和 system/sepolicy/public/app.te 不同

上述加完以后可能还会报这个不同,只需要使他们保持一致即可,编译通过以后权限就加好了

2.SELinux权限临时关闭(重启会重新打开)

adb root
adb shell setenforce 0
adb shell getenforce --------- 打印的是Permissive为成功

在调试SELinux权限问题时候先把临时权限关掉,如果问题还是存在,说明不是权限问题引起的,而且打开以后所需的权限会全部给你打出来,不会出现加了一个重新编译以后发现还需要再加,而且还有一点就是不关闭的话,有一些权限问题还不会打出来

3.SELinux权限关闭

system/core/init/selinux.cpp 有个isEnforcing()方法使他返回false即可

4.问题

目前遇到一个问题:把所有的avc报错解完还是没能拿到权限,但是在临时关闭权限问题又能解决,不知道是哪里出了问题,迫于无奈只能在system/core/init/selinux.cpp中把SELinux权限关闭,如果后续找到了原因再更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值