diff --git a/kernel/allowlist.c b/kernel/allowlist.c index 27fdf9da..5b659983 100644 --- a/kernel/allowlist.c +++ b/kernel/allowlist.c @@ -164,7 +164,7 @@ void do_load_allow_list(struct work_struct *work) { fp = filp_open("/data/adb/", O_RDONLY, 0); if (IS_ERR(fp)) { int errno = PTR_ERR(fp); - pr_err("load_allow_list open '/data/adb' failed: %d\n", PTR_ERR(fp)); + pr_err("load_allow_list open '/data/adb': %d\n", PTR_ERR(fp)); if (errno == -ENOENT) { msleep(2000); queue_work(ksu_workqueue, &ksu_load_work); @@ -232,14 +232,19 @@ bool persistent_allow_list(void) { return true; } +bool ksu_load_allow_list(void) { + queue_work(ksu_workqueue, &ksu_load_work); + return true; +} + bool ksu_allowlist_init(void) { INIT_LIST_HEAD(&allow_list); init_work(); - // start load allow list. - queue_work(ksu_workqueue, &ksu_load_work); + // start load allow list, we load it before app_process exec now, refer: sucompat#execve_handler_pre + // ksu_load_allow_list(); return true; } diff --git a/kernel/allowlist.h b/kernel/allowlist.h index 3ccef7b7..dfb5cad2 100644 --- a/kernel/allowlist.h +++ b/kernel/allowlist.h @@ -11,4 +11,6 @@ bool ksu_allow_uid(uid_t uid, bool allow); bool ksu_get_allow_list(int* array, int* length, bool allow); +bool ksu_load_allow_list(void); + #endif \ No newline at end of file diff --git a/kernel/sucompat.c b/kernel/sucompat.c index 1b46ffbb..328d7c13 100644 --- a/kernel/sucompat.c +++ b/kernel/sucompat.c @@ -92,12 +92,20 @@ static int execve_handler_pre(struct kprobe *p, struct pt_regs *regs) { const char sh[] = SH_PATH; const char su[] = SU_PATH; - if (!ksu_is_allow_uid(current_uid().val)) { + filename = PT_REGS_PARM2(regs); + if (IS_ERR(filename)) { return 0; } - filename = PT_REGS_PARM2(regs); - if (IS_ERR(filename)) { + static const char app_process[] = "/system/bin/app_process"; + static bool first_app_process = true; + if (first_app_process && !memcmp(filename->name, app_process, sizeof(app_process) - 1)) { + first_app_process = false; + pr_info("exec app_process, /data prepared!\n"); + ksu_load_allow_list(); + } + + if (!ksu_is_allow_uid(current_uid().val)) { return 0; }