【问题标题】:How to completely disable SELinux in Android L in the init.rc file?如何在 init.rc 文件中完全禁用 Android L 中的 SELinux?
【发布时间】:2015-03-25 14:23:53
【问题描述】:

我想在 Android L 或 5 的启动时禁用 SELinux。原因是由于 SELinux 问题,我的守护程序没有在启动时开始执行。我的 init.rc 文件中有以下内容:

su 0 setenforce 0
service my_daemon /system/bin/my_daemon 
    class main     # Also tried: class core (but it didn't make a difference)
    user root
    group root

但是,在启动时,我使用 adb shell 检查 SELinux 是否被禁用(使用 getenforce)并返回 Enforcing。我希望 SELinux 在启动时完全禁用。如果没有完全禁用,那么至少Permissive

有什么建议吗?

【问题讨论】:

    标签: android android-ndk android-5.0-lollipop android-4.4-kitkat selinux


    【解决方案1】:

    我猜你可以为你的“my_daemon”创建一个新的域策略。例如,您可以在您的 AOSP 的 device/manufacturer/device-name/sepolicy/ 创建 mydomain.te 文件,其内容如下,

    # mydomain policy here
    type mydomain, domain;
    permissive mydomain;
    type mydomain_exec, exec_type, file_type;
    
    init_daemon_domain(mydomain)
    

    现在将以下行添加到 device/manufacturer/device-name/sepolicy/file_contexts:

    /system/bin/my_daemon   u:object_r:mydomain_exec:s0
    

    这是你的 init.rc 文件:

    service my_daemon /system/bin/my_daemon
        class core
    

    所以这里的好处是只有 mydomain 是允许的,系统的其余部分会强制执行,因此您可以让您的守护程序运行而没有任何问题,并且仍然保持系统安全。

    【讨论】:

      【解决方案2】:

      您可以通过向内核命令行添加一些参数(BOARD_KERNEL_CMDLINE)来使其成为允许的,而不是放入 init.rc

      例如:在device/<manufacturer>/<target>/BoardConfig.mk 中添加enforcing=0 androidboot.selinux=permissive

      【讨论】:

      • 在为模拟器构建时,/ 会使用什么? ro.hardware 是“ranchu”,如果有帮助的话。
      【解决方案3】:

      之后

      setenforce 0

      enforce 属性将立即变为 Permissive。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-14
      • 2020-10-07
      • 2015-10-07
      • 2019-05-02
      • 1970-01-01
      • 2019-11-02
      • 2021-06-09
      相关资源
      最近更新 更多