当前位置:   article > 正文

android 11添加property遇到的selinux问题

android 11添加property遇到的selinux问题

android 11 项目中添加新的property启动sh脚本,遇到如下几个问题。
问题1 :coredomaim编译报错

  1. The following domain(s) must be associated with the "coredomain" attribute because they are executed off of /system:
  2. addnewservice
此处log 提示 addnewservice必须是coredomain类型的,为此我们在system/seploicy/public/addnewservice.te中添加修改
  1. -type addnewservice, domain, mlstrustedsubject;
  2. +type addnewservice, domain, coredomain, mlstrustedsubject;
之后重新编译报如下错误
  1. The following domain(s) must be associated with the "coredomain" attribute because they are executed off of /system:
  2. addnewservice
  1. 此时log显示addnewservice却又不能被设置为coredomain。
  2. 这就叫人很纠结了。不添加coredomain,编译报错必须是coredomain,添加coredomain之后编译又提示禁止被设置成coredomain。
  3. 分析log可知android 11 在system/bin/目录下执行的sh脚本必须是coredomain,如果不想设置成coredomain可以将sh脚本放到vendor/bin/目录下,这样就不会遇到coredomain问题,但是这种方式有时候会遇到一些必须修改到system/sepolicy目录下权限才能执行的,这样就必须将sh脚本放置到system/bin/目录下。
  4. sh脚本必须防止在system/bin/目录下,修改方案如下所示:

/system/sepolicy/private/file_contexts

+/system/bin/new.sh u:object_r:addnew_exec:s0

/system/sepolicy/public/目录下添加addnew.te 文件

  1. type addnew, domain;
  2. type addnew_exec, exec_type, file_type, system_file_type;
  3. allow addnew shell_exec:file { read getattr};
  4. ...

/system/sepolicy/private/目录下添加addnew.te 文件

  1. typeattribute addnew coredomain;
  2. init_daemon_domain(addnew)
  3. ...

问题2 :xxx.ignore.cil使用
添加新的te文件,必须在prebuilt目录下将之前所有的文件夹中添加te,但是不同版本有些typeattribute没有会导致编译报错,如果我们不想在prebuilt/目录下都添加addnew.te文件,只需要在29.0文件中添加如下修改,则29.0之前版本28.0,27.0,26.0中就不再需要添加addnew和addnew_exec相关的修改。

  1. --- a/system/sepolicy/private/compat/29.0/29.0.ignore.cil
  2. +++ b/system/sepolicy/private/compat/29.0/29.0.ignore.cil
  3. @@ -72,6 +72,8 @@
  4. iorap_prefetcherd_data_file
  5. + addnew
  6. + addnew_exec

问题3: dac_override 权限如何添加(neverallow权限如何添加)
dac_override 是一种典型的neverallow权限,要添加dac_override权限必须是coredomain才能添加,如果不是coredomain是没有办法添加这种neverallow权限的,也就是说在device/qcom/sepolicy/目录下添加的文件是不可能有dac_override权限的,如何添加coredomain修改如问题1所示
添加dac_override修改如下所示:

  1. --- a/system/sepolicy/private/domain.te
  2. +++ b/system/sepolicy/private/domain.te
  3. @@ -311,8 +311,9 @@ define(`dac_override_allowed', `{
  4. vold
  5. vold_prepare_subdirs
  6. zygote
  7. + addnew
  8. }')
  9. -neverallow ~dac_override_allowed self:global_capability_class_set dac_override;
  10. +neverallow ~{ dac_override_allowed addnew} self:global_capability_class_set dac_override;
  11. # Since the kernel checks dac_read_search before dac_override, domains that
  12. # have dac_override should also have dac_read_search to eliminate spurious
  13. # denials. Some domains have dac_read_search without having dac_override, so
  14. @@ -323,6 +324,7 @@ neverallow ~{
  15. iorap_prefetcherd
  16. traced_perf
  17. traced_probes
  18. + addnew
  19. userdebug_or_eng(`heapprofd')
  20. } self:global_capability_class_set dac_read_search;
  1. --- a/system/sepolicy/private/file_contexts
  2. +++ b/system/sepolicy/private/file_contexts
  3. @@ -301,6 +301,7 @@
  4. /system/bin/iorapd u:object_r:iorapd_exec:s0
  5. +/system/bin/new.sh u:object_r:addnew_exec:s0
  6. /system/bin/iorap\.inode2filename u:object_r:iorap_inode2filename_exec:s0

注意这边添加dac_override修改不确定是否会导致CTS测试fail,目前没有CTS测试需求,所以没有测试过,如果CTS测试fail则需要看看是否有其他方式绕开。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/1001369
推荐阅读
相关标签
  

闽ICP备14008679号