From 9e22b807142b1fe74303c609b7de0f80062c1634 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 2 Jul 2017 23:34:28 +0800 Subject: [PATCH] Update unmounting policies --- jni/magiskhide/hide_daemon.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/jni/magiskhide/hide_daemon.c b/jni/magiskhide/hide_daemon.c index 650b50777..7c3b1a0a6 100644 --- a/jni/magiskhide/hide_daemon.c +++ b/jni/magiskhide/hide_daemon.c @@ -89,10 +89,11 @@ int hide_daemon() { } } - // First unmount the mirror, dummy skeletons, cache mounts, and /sbin links + // First unmount dummy skeletons, /sbin links, cache mounts, and mirrors vec_for_each_r(&mount_list, line) { if (strstr(line, "tmpfs /system") || strstr(line, "tmpfs /vendor") || strstr(line, "tmpfs /sbin") - || (strstr(line, cache_block) && strstr(line, "/system/")) || strstr(line, MIRRDIR) ) { + || (strstr(line, cache_block) && (strstr(line, " /system") || strstr(line, " /vendor"))) + || strstr(line, MIRRDIR)) { sscanf(line, "%*s %512s", buffer); lazy_unmount(buffer); } @@ -105,9 +106,25 @@ int hide_daemon() { vec_init(&mount_list); file_to_vector(buffer, &mount_list); - // Unmount loop mounts + // Unmount loop mounts on /system, /vendor, /magisk vec_for_each_r(&mount_list, line) { - if (strstr(line, "/dev/block/loop") || strstr(line, DUMMDIR)) { + if (strstr(line, "/dev/block/loop") + && (strstr(line, " /system") || strstr(line, " /vendor") || strstr(line, " /magisk"))) { + sscanf(line, "%*s %512s", buffer); + lazy_unmount(buffer); + } + free(line); + } + vec_destroy(&mount_list); + + // Re-read mount infos + snprintf(buffer, sizeof(buffer), "/proc/%d/mounts", pid); + vec_init(&mount_list); + file_to_vector(buffer, &mount_list); + + // Unmount remaining mounts on dummy skeletons + vec_for_each_r(&mount_list, line) { + if (strstr(line, DUMMDIR)) { sscanf(line, "%*s %512s", buffer); lazy_unmount(buffer); }