android 11添加property遇到的selinux问题

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则需要看看是否有其他方式绕开。

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值