From 495654f9fffc2058b8665834a5a410ee38dec97b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 24 Apr 2017 21:43:30 +0800 Subject: [PATCH] Small tweaks --- jni/daemon/daemon.c | 3 +-- jni/magisk.h | 3 ++- jni/magiskhide/list_manager.c | 2 +- jni/magiskhide/magiskhide.c | 11 +++++++++-- jni/magiskhide/proc_monitor.c | 2 +- jni/su | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/jni/daemon/daemon.c b/jni/daemon/daemon.c index 0fa64ad8b..bbbfd88fb 100644 --- a/jni/daemon/daemon.c +++ b/jni/daemon/daemon.c @@ -89,8 +89,6 @@ static int setup_socket(struct sockaddr_un *sun) { return fd; } -static void do_nothing() {} - static void *large_sepol_patch(void *args) { LOGD("sepol: Starting large patch thread\n"); // Patch su to everything @@ -117,6 +115,7 @@ void start_daemon() { } xsetsid(); xsetcon("u:r:su:s0"); + umask(022); // Patch selinux with medium patch before we do anything load_policydb("/sys/fs/selinux/policy"); diff --git a/jni/magisk.h b/jni/magisk.h index db33b97a5..1ac8fdc87 100644 --- a/jni/magisk.h +++ b/jni/magisk.h @@ -33,9 +33,10 @@ // Global handler for PLOGE extern __thread void (*err_handler)(void); -// Two common error handlers +// Common error handlers static inline void exit_proc() { exit(1); } static inline void exit_thread() { pthread_exit(NULL); } +static inline void do_nothing() {} // Dummy function to depress debug message static inline void stub(const char *fmt, ...) {} diff --git a/jni/magiskhide/list_manager.c b/jni/magiskhide/list_manager.c index bd3d94e02..5fcbbf1b4 100644 --- a/jni/magiskhide/list_manager.c +++ b/jni/magiskhide/list_manager.c @@ -102,7 +102,7 @@ int init_list() { return 1; vec_init(hide_list); - // Might return 1 if first time + // Might error if file doesn't exist, no need to report file_to_vector(HIDELIST, hide_list); char *line; diff --git a/jni/magiskhide/magiskhide.c b/jni/magiskhide/magiskhide.c index cd2aa1239..18f8f06a8 100644 --- a/jni/magiskhide/magiskhide.c +++ b/jni/magiskhide/magiskhide.c @@ -43,6 +43,9 @@ static void usage(char *arg0) { } void launch_magiskhide(int client) { + // We manually handle crashes + err_handler = do_nothing; + if (hideEnabled) { write_int(client, HIDE_IS_ENABLED); close(client); @@ -52,8 +55,12 @@ void launch_magiskhide(int client) { LOGI("* Starting MagiskHide\n"); hideEnabled = 1; - init_resetprop(); - setprop2("persist.magisk.hide", "1", 0); + + if (init_resetprop()) + goto error; + + if (setprop2("persist.magisk.hide", "1", 0)) + goto error; hide_sensitive_props(); diff --git a/jni/magiskhide/proc_monitor.c b/jni/magiskhide/proc_monitor.c index 3ee1c5540..ad26fe183 100644 --- a/jni/magiskhide/proc_monitor.c +++ b/jni/magiskhide/proc_monitor.c @@ -66,7 +66,7 @@ static void proc_monitor_err() { void proc_monitor() { // Register the cancel signal signal(SIGUSR1, quit_pthread); - // The error handler should only exit the thread, not the whole process + // The error handler should stop magiskhide services err_handler = proc_monitor_err; int pid; diff --git a/jni/su b/jni/su index b499ac8ab..c55836203 160000 --- a/jni/su +++ b/jni/su @@ -1 +1 @@ -Subproject commit b499ac8abacc9d009d110146e2f681a9b0a66f19 +Subproject commit c5583620349aa7700435bda0b0f356c3510e550e