From 957feca626e670710eb598742d385a95d0d303cd Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 16 Mar 2019 17:15:48 -0400 Subject: [PATCH] Limit sepolicy load to Android Q only It seems both Android cancers, Samsung and Huawei devices, don't like preloading sepolicy. For a temporary solution now is to limit the sepolicy loading to Android Q only. --- native/jni/core/init.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/native/jni/core/init.cpp b/native/jni/core/init.cpp index 2504cff76..3c02771f7 100644 --- a/native/jni/core/init.cpp +++ b/native/jni/core/init.cpp @@ -146,12 +146,12 @@ private: raw_data init{}; raw_data config{}; int root = -1; + char **argv; + bool load_sepol = false; bool mnt_system = false; bool mnt_vendor = false; bool mnt_product = false; bool mnt_odm = false; - bool kirin = false; - char **argv; void load_kernel_info(); void preset(); @@ -209,7 +209,9 @@ void MagiskInit::load_kernel_info() { cmdline[read(fd, cmdline, sizeof(cmdline))] = '\0'; close(fd); - bool skip_initramfs = false, enter_recovery = false; + bool skip_initramfs = false; + bool enter_recovery = false; + bool kirin = false; parse_cmdline([&](auto key, auto value) -> void { LOGD("cmdline: [%s]=[%s]\n", key.data(), value); @@ -348,6 +350,10 @@ void MagiskInit::early_mount() { xmkdir("/system", 0755); xmount("/system_root/system", "/system", nullptr, MS_BIND, nullptr); + // Android Q + if (is_lnk("/system_root/init")) + load_sepol = true; + // Copy if these partitions are symlinks link_root("/vendor"); link_root("/product"); @@ -449,7 +455,7 @@ bool MagiskInit::patch_sepolicy() { dump_policydb("/sepolicy"); // Load policy to kernel so we can label rootfs - if (!kirin) + if (load_sepol) dump_policydb(SELINUX_LOAD); // Remove OnePlus stupid debug sepolicy and use our own @@ -483,7 +489,7 @@ bool MagiskInit::read_dt_fstab(const char *mnt_point, char *partname, char *part return false; } -#define umount_part(part) \ +#define umount_root(part) \ if (mnt_##part) \ umount("/" #part); @@ -491,10 +497,10 @@ void MagiskInit::cleanup() { umount(SELINUX_MNT); umount("/sys"); umount("/proc"); - umount_part(system); - umount_part(vendor); - umount_part(product); - umount_part(odm); + umount_root(system); + umount_root(vendor); + umount_root(product); + umount_root(odm); } static inline void patch_socket_name(const char *path) {