Refactor sepolicy.rules resolve

We resolve available partitions for sepolicy.rules when patching
boot and bind mount the partition by magiskinit.

For older devices, the previous logic won't work because the part name
is never readable.

Co-authored-by: topjohnwu <topjohnwu@gmail.com>
This commit is contained in:
LoveSy
2023-02-12 16:36:38 +08:00
committed by GitHub
parent 03418ddcbf
commit 9e8c68af12
11 changed files with 151 additions and 144 deletions
+9 -4
View File
@@ -267,7 +267,8 @@ void RootFSInit::prepare() {
rename(backup_init(), "/init");
}
#define PRE_TMPDIR "/magisk-tmp"
#define PRE_TMPSRC "/magisk"
#define PRE_TMPDIR PRE_TMPSRC "/tmp"
void MagiskInit::patch_rw_root() {
mount_list.emplace_back("/data");
@@ -292,6 +293,8 @@ void MagiskInit::patch_rw_root() {
treble = init.contains(SPLIT_PLAT_CIL);
}
xmkdir(PRE_TMPSRC, 0);
xmount("tmpfs", PRE_TMPSRC, "tmpfs", 0, "mode=755");
xmkdir(PRE_TMPDIR, 0);
setup_tmp(PRE_TMPDIR);
chdir(PRE_TMPDIR);
@@ -319,10 +322,12 @@ int magisk_proxy_main(int argc, char *argv[]) {
unlink("/sbin/magisk");
// Move tmpfs to /sbin
// For some reason MS_MOVE won't work, as a workaround bind mount then unmount
xmount(PRE_TMPDIR, "/sbin", nullptr, MS_BIND | MS_REC, nullptr);
xumount2(PRE_TMPDIR, MNT_DETACH);
// make parent private before MS_MOVE
xmount(nullptr, PRE_TMPSRC, nullptr, MS_PRIVATE, nullptr);
xmount(PRE_TMPDIR, "/sbin", nullptr, MS_MOVE, nullptr);
xumount2(PRE_TMPSRC, MNT_DETACH);
rmdir(PRE_TMPDIR);
rmdir(PRE_TMPSRC);
// Create symlinks pointing back to /root
recreate_sbin("/root", false);