android 11 项目中添加新的property启动sh脚本,遇到如下几个问题。
问题1 :coredomaim编译报错
The following domain(s) must be associated with the "coredomain" attribute because they are executed off of /system:
addnewservice
此处log 提示 addnewservice必须是coredomain类型的,为此我们在system/seploicy/public/addnewservice.te中添加修改
-type addnewservice, domain, mlstrustedsubject;
+type addnewservice, domain, coredomain, mlstrustedsubject;
之后重新编译报如下错误
The following domain(s) must be associated with the "coredomain" attribute because they are executed off of /system:
addnewservice
此时log显示addnewservice却又不能被设置为coredomain。
这就叫人很纠结了。不添加coredomain,编译报错必须是coredomain,添加coredomain之后编译又提示禁止被设置成coredomain。
分析log可知android 11 在system/bin/目录下执行的sh脚本必须是coredomain,如果不想设置成coredomain可以将sh脚本放到vendor/bin/目录下,这样就不会遇到coredomain问题,但是这种方式有时候会遇到一些必须修改到system/sepolicy目录下权限才能执行的,这样就必须将sh脚本放置到system/bin/目录下。
sh脚本必须防止在system/bin/目录下,修改方案如下所示:
/system/sepolicy/private/file_contexts
+/system/bin/new.sh u:object_r:addnew_exec:s0
/system/sepolicy/public/目录下添加addnew.te 文件
type addnew, domain;
type addnew_exec, exec_type, file_type, system_file_type;
allow addnew shell_exec:file { read getattr};
...
/system/sepolicy/private/目录下添加addnew.te 文件
typeattribute addnew coredomain;
init_daemon_domain(addnew)
...
问题2 :xxx.ignore.cil使用
添加新的te文件,必须在prebuilt目录下将之前所有的文件夹中添加te,但是不同版本有些typeattribute没有会导致编译报错,如果我们不想在prebuilt/目录下都添加addnew.te文件,只需要在29.0文件中添加如下修改,则29.0之前版本28.0,27.0,26.0中就不再需要添加addnew和addnew_exec相关的修改。
--- a/system/sepolicy/private/compat/29.0/29.0.ignore.cil
+++ b/system/sepolicy/private/compat/29.0/29.0.ignore.cil
@@ -72,6 +72,8 @@
iorap_prefetcherd_data_file
+ addnew
+ addnew_exec
问题3: dac_override 权限如何添加(neverallow权限如何添加)
dac_override 是一种典型的neverallow权限,要添加dac_override权限必须是coredomain才能添加,如果不是coredomain是没有办法添加这种neverallow权限的,也就是说在device/qcom/sepolicy/目录下添加的文件是不可能有dac_override权限的,如何添加coredomain修改如问题1所示
添加dac_override修改如下所示:
--- a/system/sepolicy/private/domain.te
+++ b/system/sepolicy/private/domain.te
@@ -311,8 +311,9 @@ define(`dac_override_allowed', `{
vold
vold_prepare_subdirs
zygote
+ addnew
}')
-neverallow ~dac_override_allowed self:global_capability_class_set dac_override;
+neverallow ~{ dac_override_allowed addnew} self:global_capability_class_set dac_override;
# Since the kernel checks dac_read_search before dac_override, domains that
# have dac_override should also have dac_read_search to eliminate spurious
# denials. Some domains have dac_read_search without having dac_override, so
@@ -323,6 +324,7 @@ neverallow ~{
iorap_prefetcherd
traced_perf
traced_probes
+ addnew
userdebug_or_eng(`heapprofd')
} self:global_capability_class_set dac_read_search;
--- a/system/sepolicy/private/file_contexts
+++ b/system/sepolicy/private/file_contexts
@@ -301,6 +301,7 @@
/system/bin/iorapd u:object_r:iorapd_exec:s0
+/system/bin/new.sh u:object_r:addnew_exec:s0
/system/bin/iorap\.inode2filename u:object_r:iorap_inode2filename_exec:s0
注意这边添加dac_override修改不确定是否会导致CTS测试fail,目前没有CTS测试需求,所以没有测试过,如果CTS测试fail则需要看看是否有其他方式绕开。