Commit 003fea52 authored by topjohnwu's avatar topjohnwu

Remove all non-Magisk hiding code

Magisk no longer interferes with any signals/info that were not created
or caused by Magisk itself.
parent 2b17c771
......@@ -298,10 +298,10 @@ void post_fs_data(int client) {
safe_mode = true;
// Disable all modules and magiskhide so next boot will be clean
disable_modules();
stop_magiskhide();
disable_hide();
} else {
exec_common_scripts("post-fs-data");
auto_start_magiskhide(false);
check_enable_hide();
handle_modules();
}
......@@ -350,7 +350,7 @@ void boot_complete(int client) {
if (access(SECURE_DIR, F_OK) != 0)
xmkdir(SECURE_DIR, 0700);
auto_start_magiskhide(true);
check_enable_hide();
if (!check_manager()) {
if (access(MANAGERAPK, F_OK) == 0) {
......
......@@ -55,5 +55,5 @@ void magiskhide_handler(int client, ucred *cred);
void su_daemon_handler(int client, ucred *credential);
// MagiskHide
void auto_start_magiskhide(bool late_props);
int stop_magiskhide();
void check_enable_hide();
int disable_hide();
......@@ -9,69 +9,6 @@
using namespace std;
static const char *prop_key[] =
{ "ro.boot.vbmeta.device_state", "ro.boot.verifiedbootstate", "ro.boot.flash.locked",
"ro.boot.veritymode", "ro.boot.warranty_bit", "ro.warranty_bit",
"ro.debuggable", "ro.secure", "ro.build.type", "ro.build.tags",
"ro.vendor.boot.warranty_bit", "ro.vendor.warranty_bit",
"vendor.boot.vbmeta.device_state", nullptr };
static const char *prop_val[] =
{ "locked", "green", "1",
"enforcing", "0", "0",
"0", "1", "user", "release-keys",
"0", "0",
"locked", nullptr };
static const char *late_prop_key[] =
{ "vendor.boot.verifiedbootstate", nullptr };
static const char *late_prop_val[] =
{ "green", nullptr };
void hide_sensitive_props() {
LOGI("hide: Hiding sensitive props\n");
for (int i = 0; prop_key[i]; ++i) {
auto value = getprop(prop_key[i]);
if (!value.empty() && value != prop_val[i])
setprop(prop_key[i], prop_val[i], false);
}
// Hide that we booted from recovery when magisk is in recovery mode
auto bootmode = getprop("ro.bootmode");
if (!bootmode.empty() && str_contains(bootmode, "recovery"))
setprop("ro.bootmode", "unknown", false);
bootmode = getprop("ro.boot.mode");
if (!bootmode.empty() && str_contains(bootmode, "recovery"))
setprop("ro.boot.mode", "unknown", false);
bootmode = getprop("vendor.boot.mode");
if (!bootmode.empty() && str_contains(bootmode, "recovery"))
setprop("vendor.boot.mode", "unknown", false);
// Xiaomi cross region flash
auto hwc = getprop("ro.boot.hwc");
if (!hwc.empty() && str_contains(hwc, "CN"))
setprop("ro.boot.hwc", "GLOBAL", false);
auto hwcountry = getprop("ro.boot.hwcountry");
if (!hwcountry.empty() && str_contains(hwcountry, "China"))
setprop("ro.boot.hwcountry", "GLOBAL", false);
auto selinux = getprop("ro.build.selinux");
if (!selinux.empty())
delprop("ro.build.selinux");
}
void hide_late_sensitive_props() {
LOGI("hide: Hiding sensitive props (late)\n");
for (int i = 0; late_prop_key[i]; ++i) {
auto value = getprop(late_prop_key[i]);
if (!value.empty() && value != late_prop_val[i])
setprop(late_prop_key[i], late_prop_val[i], false);
}
}
static void lazy_unmount(const char* mountpoint) {
if (umount2(mountpoint, MNT_DETACH) != -1)
LOGD("hide: Unmounted (%s)\n", mountpoint);
......@@ -86,8 +23,7 @@ void hide_daemon(int pid) {
}
}
#define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && \
strncmp(mentry->mnt_dir, "/" #dir, sizeof("/" #dir) - 1) == 0)
#define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && str_starts(mentry->mnt_dir, "/" #dir))
void hide_unmount(int pid) {
if (pid > 0 && switch_mnt_ns(pid))
......@@ -95,16 +31,6 @@ void hide_unmount(int pid) {
LOGD("hide: handling PID=[%d]\n", pid);
char val;
int fd = xopen(SELINUX_ENFORCE, O_RDONLY);
xxread(fd, &val, sizeof(val));
close(fd);
// Permissive
if (val == '0') {
chmod(SELINUX_ENFORCE, 0640);
chmod(SELINUX_POLICY, 0440);
}
vector<string> targets;
// Unmount dummy skeletons and /sbin links
......@@ -121,7 +47,7 @@ void hide_unmount(int pid) {
// Unmount all Magisk created mounts
parse_mnt("/proc/self/mounts", [&](mntent *mentry) {
if (strstr(mentry->mnt_fsname, BLOCKDIR))
if (str_contains(mentry->mnt_fsname, BLOCKDIR))
targets.emplace_back(mentry->mnt_dir);
return true;
});
......@@ -129,4 +55,3 @@ void hide_unmount(int pid) {
for (auto &s : reversed(targets))
lazy_unmount(s.data());
}
This diff is collapsed.
......@@ -20,9 +20,6 @@ using namespace std;
" ls Print the current hide list\n"
" exec CMDs... Execute commands in isolated mount\n"
" namespace and do all hide unmounts\n"
#ifdef MAGISK_DEBUG
" test Run process monitor test\n"
#endif
, arg0);
exit(1);
}
......@@ -32,10 +29,10 @@ void magiskhide_handler(int client, ucred *cred) {
int res = DAEMON_ERROR;
switch (req) {
case STOP_MAGISKHIDE:
case ADD_HIDELIST:
case RM_HIDELIST:
case LS_HIDELIST:
case DISABLE_HIDE:
case ADD_LIST:
case RM_LIST:
case LS_LIST:
if (!hide_enabled()) {
write_int(client, HIDE_NOT_ENABLED);
close(client);
......@@ -44,19 +41,19 @@ void magiskhide_handler(int client, ucred *cred) {
}
switch (req) {
case LAUNCH_MAGISKHIDE:
res = launch_magiskhide(true);
case ENABLE_HIDE:
res = enable_hide();
break;
case STOP_MAGISKHIDE:
res = stop_magiskhide();
case DISABLE_HIDE:
res = disable_hide();
break;
case ADD_HIDELIST:
case ADD_LIST:
res = add_list(client);
break;
case RM_HIDELIST:
case RM_LIST:
res = rm_list(client);
break;
case LS_HIDELIST:
case LS_LIST:
ls_list(client);
return;
case HIDE_STATUS:
......@@ -79,15 +76,15 @@ int magiskhide_main(int argc, char *argv[]) {
int req;
if (opt == "enable"sv)
req = LAUNCH_MAGISKHIDE;
req = ENABLE_HIDE;
else if (opt == "disable"sv)
req = STOP_MAGISKHIDE;
req = DISABLE_HIDE;
else if (opt == "add"sv)
req = ADD_HIDELIST;
req = ADD_LIST;
else if (opt == "rm"sv)
req = RM_HIDELIST;
req = RM_LIST;
else if (opt == "ls"sv)
req = LS_HIDELIST;
req = LS_LIST;
else if (opt == "status"sv)
req = HIDE_STATUS;
else if (opt == "exec"sv && argc > 2) {
......@@ -104,7 +101,7 @@ int magiskhide_main(int argc, char *argv[]) {
int fd = connect_daemon();
write_int(fd, MAGISKHIDE);
write_int(fd, req);
if (req == ADD_HIDELIST || req == RM_HIDELIST) {
if (req == ADD_LIST || req == RM_LIST) {
write_string(fd, argv[2]);
write_string(fd, argv[3] ? argv[3] : "");
}
......@@ -141,7 +138,7 @@ int magiskhide_main(int argc, char *argv[]) {
return DAEMON_ERROR;
}
if (req == LS_HIDELIST) {
if (req == LS_LIST) {
string res;
for (;;) {
read_string(fd, res);
......
#pragma once
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>
#include <unistd.h>
#include <dirent.h>
#include <string_view>
#include <functional>
#include <map>
#include <daemon.hpp>
#define SIGTERMTHRD SIGUSR1
#define ISOLATED_MAGIC "isolated"
// CLI entries
int launch_magiskhide(bool late_props);
int stop_magiskhide();
int enable_hide();
int disable_hide();
int add_list(int client);
int rm_list(int client);
void ls_list(int client);
// Utility functions
void crawl_procfs(const std::function<bool (int)> &fn);
void crawl_procfs(DIR *dir, const std::function<bool (int)> &fn);
bool hide_enabled();
void update_uid_map();
bool is_hide_target(int uid, std::string_view process, int max_len = 1024);
bool is_hide_target(int uid, std::string_view process);
// Hide policies
void hide_daemon(int pid);
void hide_unmount(int pid = -1);
void hide_sensitive_props();
void hide_late_sensitive_props();
extern pthread_mutex_t hide_state_lock;
extern std::map<int, std::vector<std::string_view>> uid_proc_map;
enum {
LAUNCH_MAGISKHIDE,
STOP_MAGISKHIDE,
ADD_HIDELIST,
RM_HIDELIST,
LS_HIDELIST,
ENABLE_HIDE,
DISABLE_HIDE,
ADD_LIST,
RM_LIST,
LS_LIST,
HIDE_STATUS,
};
......
This diff is collapsed.
......@@ -58,6 +58,9 @@ reversed_container<T> reversed(T &base) {
return reversed_container<T>(base);
}
template<class T>
static inline void default_new(T *&p) { p = new T(); }
template<typename T, typename Impl>
class stateless_allocator {
public:
......
......@@ -326,9 +326,6 @@ int hook_register(const char *path, const char *symbol, void *new_func, void **o
} // namespace
template<class T>
static inline void default_new(T *&p) { p = new T(); }
#define XHOOK_REGISTER_SYM(PATH_REGEX, SYM, NAME) \
hook_register(PATH_REGEX, SYM, (void*) new_##NAME, (void **) &old_##NAME)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment