SELinux avc 权限, audit2allow 使用

若在log出现“ avc:”则按照调试添加权限。

使用avc关键词查找权限相关log
adb logcat -b all | grep "avc:"

进行操作复现问题,抓取最新日志,eg:

05-28 11:41:34.264  7393  7393 I auditd  : type=1400 audit(0.0:383): avc: denied { read } for comm="m.android.email" name="vmstat" dev="proc" ino=4026532351 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0
05-28 11:41:34.264  7393  7393 W m.android.email: type=1400 audit(0.0:383): avc: denied { read } for name="vmstat" dev="proc" ino=4026532351 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0
05-28 11:43:05.454  7696  7696 I auditd  : type=1400 audit(0.0:384): avc: denied { read } for comm="m.android.email" name="vmstat" dev="proc" ino=4026532351 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0
05-28 11:43:05.454  7696  7696 W m.android.email: type=1400 audit(0.0:384): avc: denied { read } for name="vmstat" dev="proc" ino=4026532351 scontext=u:r:untrusted_app_25:s0:c512,c768 tcontext=u:object_r:proc:s0 tclass=file permissive=0

创建任意文件,粘贴日志内容,eg:创建文件名称为se.txt,而后使用如下命令:

ubuntu@ubuntu:~$ audit2allow -i se.txt               //很重要的一个以python写的命令,主要用来处理日志,把日志中的违反策略的动作的记录,转换成 access vector
//如果没有该指令,执行安装
sudo apt-get install policycoreutils

得到结果:

#============= untrusted_app_25 ==============
allow untrusted_app_25 proc:file read;

修改该路径下的文件:/device/qcom/sepolicy/common/ untrusted_app_25.te,在文件添加上述语句:

allow untrusted_app_25 proc:file read;

如果没有相似的文件,使用下面查找

grep -rsn "untrusted_app_25" .
///////////////////////////////得到结果//////////////////////////////////////
./untrusted_app_25.te:29:hal_client_domain(untrusted_app_25, hal_perf);
./untrusted_app_25.te:32:hal_client_domain(untrusted_app_25, hal_iop);
./untrusted_app_25.te:35:allow untrusted_app_25 vendor_file:file {getattr open read};
./untrusted_app_25.te:38:allow untrusted_app_25 vendor_file:file execute;
./untrusted_app_25.te:41:allow untrusted_app_25 exfat:dir search;
./untrusted_app_25.te:42:allow untrusted_app_25 fuseblk:dir search;
./untrusted_app_25.te:44:allow untrusted_app_25 proc:file read;
///////////////////////////////模仿修改/////////////////////////////////////

编译 vendorimage、bootimage 验证。

参考链接:
Selinux SeAndroid理解
SELinux audit2allow命令使用

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐