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) { ...@@ -298,10 +298,10 @@ void post_fs_data(int client) {
safe_mode = true; safe_mode = true;
// Disable all modules and magiskhide so next boot will be clean // Disable all modules and magiskhide so next boot will be clean
disable_modules(); disable_modules();
stop_magiskhide(); disable_hide();
} else { } else {
exec_common_scripts("post-fs-data"); exec_common_scripts("post-fs-data");
auto_start_magiskhide(false); check_enable_hide();
handle_modules(); handle_modules();
} }
...@@ -350,7 +350,7 @@ void boot_complete(int client) { ...@@ -350,7 +350,7 @@ void boot_complete(int client) {
if (access(SECURE_DIR, F_OK) != 0) if (access(SECURE_DIR, F_OK) != 0)
xmkdir(SECURE_DIR, 0700); xmkdir(SECURE_DIR, 0700);
auto_start_magiskhide(true); check_enable_hide();
if (!check_manager()) { if (!check_manager()) {
if (access(MANAGERAPK, F_OK) == 0) { if (access(MANAGERAPK, F_OK) == 0) {
......
...@@ -55,5 +55,5 @@ void magiskhide_handler(int client, ucred *cred); ...@@ -55,5 +55,5 @@ void magiskhide_handler(int client, ucred *cred);
void su_daemon_handler(int client, ucred *credential); void su_daemon_handler(int client, ucred *credential);
// MagiskHide // MagiskHide
void auto_start_magiskhide(bool late_props); void check_enable_hide();
int stop_magiskhide(); int disable_hide();
...@@ -9,69 +9,6 @@ ...@@ -9,69 +9,6 @@
using namespace std; 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) { static void lazy_unmount(const char* mountpoint) {
if (umount2(mountpoint, MNT_DETACH) != -1) if (umount2(mountpoint, MNT_DETACH) != -1)
LOGD("hide: Unmounted (%s)\n", mountpoint); LOGD("hide: Unmounted (%s)\n", mountpoint);
...@@ -86,8 +23,7 @@ void hide_daemon(int pid) { ...@@ -86,8 +23,7 @@ void hide_daemon(int pid) {
} }
} }
#define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && \ #define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && str_starts(mentry->mnt_dir, "/" #dir))
strncmp(mentry->mnt_dir, "/" #dir, sizeof("/" #dir) - 1) == 0)
void hide_unmount(int pid) { void hide_unmount(int pid) {
if (pid > 0 && switch_mnt_ns(pid)) if (pid > 0 && switch_mnt_ns(pid))
...@@ -95,16 +31,6 @@ void hide_unmount(int pid) { ...@@ -95,16 +31,6 @@ void hide_unmount(int pid) {
LOGD("hide: handling PID=[%d]\n", 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; vector<string> targets;
// Unmount dummy skeletons and /sbin links // Unmount dummy skeletons and /sbin links
...@@ -121,7 +47,7 @@ void hide_unmount(int pid) { ...@@ -121,7 +47,7 @@ void hide_unmount(int pid) {
// Unmount all Magisk created mounts // Unmount all Magisk created mounts
parse_mnt("/proc/self/mounts", [&](mntent *mentry) { 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); targets.emplace_back(mentry->mnt_dir);
return true; return true;
}); });
...@@ -129,4 +55,3 @@ void hide_unmount(int pid) { ...@@ -129,4 +55,3 @@ void hide_unmount(int pid) {
for (auto &s : reversed(targets)) for (auto &s : reversed(targets))
lazy_unmount(s.data()); lazy_unmount(s.data());
} }
This diff is collapsed.
...@@ -20,9 +20,6 @@ using namespace std; ...@@ -20,9 +20,6 @@ using namespace std;
" ls Print the current hide list\n" " ls Print the current hide list\n"
" exec CMDs... Execute commands in isolated mount\n" " exec CMDs... Execute commands in isolated mount\n"
" namespace and do all hide unmounts\n" " namespace and do all hide unmounts\n"
#ifdef MAGISK_DEBUG
" test Run process monitor test\n"
#endif
, arg0); , arg0);
exit(1); exit(1);
} }
...@@ -32,10 +29,10 @@ void magiskhide_handler(int client, ucred *cred) { ...@@ -32,10 +29,10 @@ void magiskhide_handler(int client, ucred *cred) {
int res = DAEMON_ERROR; int res = DAEMON_ERROR;
switch (req) { switch (req) {
case STOP_MAGISKHIDE: case DISABLE_HIDE:
case ADD_HIDELIST: case ADD_LIST:
case RM_HIDELIST: case RM_LIST:
case LS_HIDELIST: case LS_LIST:
if (!hide_enabled()) { if (!hide_enabled()) {
write_int(client, HIDE_NOT_ENABLED); write_int(client, HIDE_NOT_ENABLED);
close(client); close(client);
...@@ -44,19 +41,19 @@ void magiskhide_handler(int client, ucred *cred) { ...@@ -44,19 +41,19 @@ void magiskhide_handler(int client, ucred *cred) {
} }
switch (req) { switch (req) {
case LAUNCH_MAGISKHIDE: case ENABLE_HIDE:
res = launch_magiskhide(true); res = enable_hide();
break; break;
case STOP_MAGISKHIDE: case DISABLE_HIDE:
res = stop_magiskhide(); res = disable_hide();
break; break;
case ADD_HIDELIST: case ADD_LIST:
res = add_list(client); res = add_list(client);
break; break;
case RM_HIDELIST: case RM_LIST:
res = rm_list(client); res = rm_list(client);
break; break;
case LS_HIDELIST: case LS_LIST:
ls_list(client); ls_list(client);
return; return;
case HIDE_STATUS: case HIDE_STATUS:
...@@ -79,15 +76,15 @@ int magiskhide_main(int argc, char *argv[]) { ...@@ -79,15 +76,15 @@ int magiskhide_main(int argc, char *argv[]) {
int req; int req;
if (opt == "enable"sv) if (opt == "enable"sv)
req = LAUNCH_MAGISKHIDE; req = ENABLE_HIDE;
else if (opt == "disable"sv) else if (opt == "disable"sv)
req = STOP_MAGISKHIDE; req = DISABLE_HIDE;
else if (opt == "add"sv) else if (opt == "add"sv)
req = ADD_HIDELIST; req = ADD_LIST;
else if (opt == "rm"sv) else if (opt == "rm"sv)
req = RM_HIDELIST; req = RM_LIST;
else if (opt == "ls"sv) else if (opt == "ls"sv)
req = LS_HIDELIST; req = LS_LIST;
else if (opt == "status"sv) else if (opt == "status"sv)
req = HIDE_STATUS; req = HIDE_STATUS;
else if (opt == "exec"sv && argc > 2) { else if (opt == "exec"sv && argc > 2) {
...@@ -104,7 +101,7 @@ int magiskhide_main(int argc, char *argv[]) { ...@@ -104,7 +101,7 @@ int magiskhide_main(int argc, char *argv[]) {
int fd = connect_daemon(); int fd = connect_daemon();
write_int(fd, MAGISKHIDE); write_int(fd, MAGISKHIDE);
write_int(fd, req); 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[2]);
write_string(fd, argv[3] ? argv[3] : ""); write_string(fd, argv[3] ? argv[3] : "");
} }
...@@ -141,7 +138,7 @@ int magiskhide_main(int argc, char *argv[]) { ...@@ -141,7 +138,7 @@ int magiskhide_main(int argc, char *argv[]) {
return DAEMON_ERROR; return DAEMON_ERROR;
} }
if (req == LS_HIDELIST) { if (req == LS_LIST) {
string res; string res;
for (;;) { for (;;) {
read_string(fd, res); read_string(fd, res);
......
#pragma once #pragma once
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h>
#include <dirent.h>
#include <string_view> #include <string_view>
#include <functional> #include <functional>
#include <map> #include <map>
#include <daemon.hpp> #include <daemon.hpp>
#define SIGTERMTHRD SIGUSR1
#define ISOLATED_MAGIC "isolated" #define ISOLATED_MAGIC "isolated"
// CLI entries // CLI entries
int launch_magiskhide(bool late_props); int enable_hide();
int stop_magiskhide(); int disable_hide();
int add_list(int client); int add_list(int client);
int rm_list(int client); int rm_list(int client);
void ls_list(int client); void ls_list(int client);
// Utility functions // 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(); bool hide_enabled();
void update_uid_map(); bool is_hide_target(int uid, std::string_view process);
bool is_hide_target(int uid, std::string_view process, int max_len = 1024);
// Hide policies // Hide policies
void hide_daemon(int pid); void hide_daemon(int pid);
void hide_unmount(int pid = -1); 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 { enum {
LAUNCH_MAGISKHIDE, ENABLE_HIDE,
STOP_MAGISKHIDE, DISABLE_HIDE,
ADD_HIDELIST, ADD_LIST,
RM_HIDELIST, RM_LIST,
LS_HIDELIST, LS_LIST,
HIDE_STATUS, HIDE_STATUS,
}; };
......
This diff is collapsed.
...@@ -58,6 +58,9 @@ reversed_container<T> reversed(T &base) { ...@@ -58,6 +58,9 @@ reversed_container<T> reversed(T &base) {
return reversed_container<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> template<typename T, typename Impl>
class stateless_allocator { class stateless_allocator {
public: public:
......
...@@ -326,9 +326,6 @@ int hook_register(const char *path, const char *symbol, void *new_func, void **o ...@@ -326,9 +326,6 @@ int hook_register(const char *path, const char *symbol, void *new_func, void **o
} // namespace } // namespace
template<class T>
static inline void default_new(T *&p) { p = new T(); }
#define XHOOK_REGISTER_SYM(PATH_REGEX, SYM, NAME) \ #define XHOOK_REGISTER_SYM(PATH_REGEX, SYM, NAME) \
hook_register(PATH_REGEX, SYM, (void*) new_##NAME, (void **) &old_##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