通过上面的方法介绍,我们已经知道了,如何添加权限问题,但有时会遇到一个问题就是: 明明已经添加了对应的权限,但是编译固件烧录到板子后,还是会报这个权限没有添加。
1.问题说明
在实际的项目开发中,遇到了如下图所示的权限问题
通过 audit2allow 工具解析出了需要添加的权限,于是乎我在 untrusted_app.te 文件中添加了对应的权限,如下图所示:
然后,重新编译打包固件,烧录到板子后,发现 “allow untrusted_app proc:file write;" 权限问题仍然存在,并没有解决,此时就有点懵了。
2.解决方案
(1) cd 到 system/sepolicy/ 目录下,使用 find 命令找到一个名字是 mls 的文件,我这个项目的 mls文件路径如下所示:system/sepolicy/private/mls
(2) 打开文件,发现有如下的限制:
mlsconstrain { file lnk_file sock_file chr_file blk_file } { write setattr append unlink link rename }
(t2 == app_data_file or l1 eq l2 or t1 == mlstrustedsubject or t2 == mlstrustedobject);
(3)上一条的限制就导致了,即使在 untrusted_app.te 文件中添加的语句验证没有问题,但是这条限制没有通过,权限问题同样没有解决。上述规则通过的四个条件如下:
t2 == app_data_file
l1 eq l2
t1 == mlstrustedsubject
t2 == mlstrustedobject
上面的四条规则,只要一条通过,都可以,所以我们最终的修改方法是:
system/sepolicy/public/untrusted_app.te
test34@test34:~/Source/rk3399_TVI3337_9.0/system/sepolicy$ git diff public/untrusted_app.te
diff --git a/public/untrusted_app.te b/public/untrusted_app.te
index 5289bf96b..2a0531b11 100644
--- a/public/untrusted_app.te
+++ b/public/untrusted_app.te
@@ -16,6 +16,6 @@
### seapp_contexts.
###
-type untrusted_app, domain;
+type untrusted_app, domain, mlstrustedsubject;
test34@test34:~/Source/rk3399_TVI3337_9.0/system/sepolicy$
(4) 如上修改完成后,重新编译固件,打包,烧录。将不会在报该权限存在问题。