如何在init.rc文件中完全禁用Android L中的SELinux?

Red*_*son 5 android selinux android-ndk android-4.4-kitkat android-5.0-lollipop

我想在启动时为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
Run Code Online (Sandbox Code Playgroud)

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

有什么建议?

Sha*_*esh 5

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

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


小智 5

好吧,我想您可以为您的“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)
Run Code Online (Sandbox Code Playgroud)

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

/system/bin/my_daemon   u:object_r:mydomain_exec:s0
Run Code Online (Sandbox Code Playgroud)

这是你的 init.rc 文件:

service my_daemon /system/bin/my_daemon
    class core
Run Code Online (Sandbox Code Playgroud)

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


小智 0

设定强度 0

force 属性将立即变为 Permissive。