From 551be7d28e2c8170d711d45b83515eaeaf66e3c2 Mon Sep 17 00:00:00 2001 From: xiangfeidexiaohuo Date: Wed, 25 Oct 2023 20:43:48 +0800 Subject: [PATCH] Revert "kernel: Adapt to low version Android init process (#973)" This reverts commit 54ee400dc5ccb521de761b4dfdff4613d36262e0. Signed-off-by: xiangfeidexiaohuo --- kernel/allowlist.c | 2 +- kernel/apk_sign.c | 6 ++-- kernel/core_hook.c | 8 ++--- kernel/ksud.c | 74 ++++----------------------------------- kernel/selinux/rules.c | 10 +++--- kernel/selinux/selinux.c | 2 +- kernel/selinux/sepolicy.c | 4 +-- 7 files changed, 23 insertions(+), 83 deletions(-) diff --git a/kernel/allowlist.c b/kernel/allowlist.c index 00777e625d61..b0f6279e4815 100644 --- a/kernel/allowlist.c +++ b/kernel/allowlist.c @@ -98,7 +98,7 @@ void ksu_show_allow_list(void) { struct perm_data *p = NULL; struct list_head *pos = NULL; - pr_info("ksu_show_allow_list\n"); + pr_info("ksu_show_allow_list"); list_for_each (pos, &allow_list) { p = list_entry(pos, struct perm_data, list); pr_info("uid :%d, allow: %d\n", p->profile.current_uid, diff --git a/kernel/apk_sign.c b/kernel/apk_sign.c index c2a5562367c3..2fe66e29be27 100644 --- a/kernel/apk_sign.c +++ b/kernel/apk_sign.c @@ -187,7 +187,7 @@ static __always_inline bool check_v2_signature(char *path, int i; struct file *fp = ksu_filp_open_compat(path, O_RDONLY, 0); if (IS_ERR(fp)) { - pr_err("open %s error.\n", path); + pr_err("open %s error.", path); return false; } @@ -298,7 +298,7 @@ static int set_expected_size(const char *val, const struct kernel_param *kp) { int rv = param_set_uint(val, kp); ksu_set_manager_uid(ksu_debug_manager_uid); - pr_info("ksu_manager_uid set to %d\n", ksu_debug_manager_uid); + pr_info("ksu_manager_uid set to %d", ksu_debug_manager_uid); return rv; } @@ -315,4 +315,4 @@ module_param_cb(ksu_debug_manager_uid, &expected_size_ops, &ksu_debug_manager_ui bool is_manager_apk(char *path) { return check_v2_signature(path, EXPECTED_SIZE, EXPECTED_HASH); -} \ No newline at end of file +} diff --git a/kernel/core_hook.c b/kernel/core_hook.c index fef98df1515e..dea178a590d0 100644 --- a/kernel/core_hook.c +++ b/kernel/core_hook.c @@ -197,7 +197,7 @@ int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry) if (strcmp(buf, "/system/packages.list")) { return 0; } - pr_info("renameat: %s -> %s, new path: %s\n", old_dentry->d_iname, + pr_info("renameat: %s -> %s, new path: %s", old_dentry->d_iname, new_dentry->d_iname, buf); track_throne(); @@ -275,7 +275,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3, static bool post_fs_data_lock = false; if (!post_fs_data_lock) { post_fs_data_lock = true; - pr_info("post-fs-data triggered\n"); + pr_info("post-fs-data triggered"); on_post_fs_data(); } break; @@ -284,7 +284,7 @@ int ksu_handle_prctl(int option, unsigned long arg2, unsigned long arg3, static bool boot_complete_lock = false; if (!boot_complete_lock) { boot_complete_lock = true; - pr_info("boot_complete triggered\n"); + pr_info("boot_complete triggered"); } break; } @@ -630,7 +630,7 @@ static int ksu_key_permission(key_ref_t key_ref, const struct cred *cred, return 0; } init_session_keyring = cred->session_keyring; - pr_info("kernel_compat: got init_session_keyring\n"); + pr_info("kernel_compat: got init_session_keyring"); return 0; } #endif diff --git a/kernel/ksud.c b/kernel/ksud.c index f1ba3e2e26cf..099aa193401e 100644 --- a/kernel/ksud.c +++ b/kernel/ksud.c @@ -69,11 +69,11 @@ void on_post_fs_data(void) { static bool done = false; if (done) { - pr_info("on_post_fs_data already done\n"); + pr_info("on_post_fs_data already done"); return; } done = true; - pr_info("on_post_fs_data!\n"); + pr_info("on_post_fs_data!"); ksu_load_allow_list(); // sanity check, this may influence the performance stop_input_hook(); @@ -161,11 +161,7 @@ int ksu_handle_execveat_ksud(int *fd, struct filename **filename_ptr, static const char app_process[] = "/system/bin/app_process"; static bool first_app_process = true; - - /* This applies to versions Android 10+ */ static const char system_bin_init[] = "/system/bin/init"; - /* This applies to versions between Android 6 ~ 9 */ - static const char old_system_init[] = "/init"; static bool init_second_stage_executed = false; if (!filename_ptr) @@ -185,8 +181,8 @@ int ksu_handle_execveat_ksud(int *fd, struct filename **filename_ptr, const char __user *p = get_user_arg_ptr(*argv, 1); if (p && !IS_ERR(p)) { char first_arg[16]; - ksu_strncpy_from_user_nofault(first_arg, p, sizeof(first_arg)); - pr_info("/system/bin/init first arg: %s\n", first_arg); + ksu_strncpy_from_user_nofault(first_arg, p, sizeof(first_arg)); + pr_info("first arg: %s\n", first_arg); if (!strcmp(first_arg, "second_stage")) { pr_info("/system/bin/init second_stage executed\n"); apply_kernelsu_rules(); @@ -197,63 +193,10 @@ int ksu_handle_execveat_ksud(int *fd, struct filename **filename_ptr, pr_err("/system/bin/init parse args err!\n"); } } - } else if (unlikely(!memcmp(filename->name, old_system_init, - sizeof(old_system_init) - 1) && argv)) { - // /init executed - int argc = count(*argv, MAX_ARG_STRINGS); - pr_info("/init argc: %d\n", argc); - if (argc > 1 && !init_second_stage_executed) { - /* This applies to versions between Android 6 ~ 7 */ - const char __user *p = get_user_arg_ptr(*argv, 1); - if (p && !IS_ERR(p)) { - char first_arg[16]; - ksu_strncpy_from_user_nofault(first_arg, p, sizeof(first_arg)); - pr_info("/init first arg: %s\n", first_arg); - if (!strcmp(first_arg, "--second-stage")) { - pr_info("/init second_stage executed\n"); - apply_kernelsu_rules(); - init_second_stage_executed = true; - ksu_android_ns_fs_check(); - } - } else { - pr_err("/init parse args err!\n"); - } - } else if (argc == 1 && !init_second_stage_executed && envp) { - /* This applies to versions between Android 8 ~ 9 */ - int envc = count(*envp, MAX_ARG_STRINGS); - if (envc > 0) { - int n; - for (n = 1; n <= envc; n++) { - const char __user *p = get_user_arg_ptr(*envp, n); - if (!p || IS_ERR(p)) { - continue; - } - char env[256]; - // Reading environment variable strings from user space - if (ksu_strncpy_from_user_nofault(env, p, sizeof(env)) < 0) - continue; - // Parsing environment variable names and values - char *env_name = env; - char *env_value = strchr(env, '='); - if (env_value == NULL) - continue; - // Replace equal sign with string terminator - *env_value = '\0'; - env_value++; - // Check if the environment variable name and value are matching - if (!strcmp(env_name, "INIT_SECOND_STAGE") && (!strcmp(env_value, "1") || !strcmp(env_value, "true"))) { - pr_info("/init second_stage executed\n"); - apply_kernelsu_rules(); - init_second_stage_executed = true; - ksu_android_ns_fs_check(); - } - } - } - } } if (unlikely(first_app_process && - !memcmp(filename->name, app_process, sizeof(app_process) - 1))) { + !memcmp(filename->name, app_process, sizeof(app_process) - 1))) { first_app_process = false; pr_info("exec app_process, /data prepared, second_stage: %d\n", init_second_stage_executed); on_post_fs_data(); // we keep this for old ksud @@ -274,7 +217,7 @@ static ssize_t read_proxy(struct file *file, char __user *buf, size_t count, bool first_read = file->f_pos == 0; ssize_t ret = orig_read(file, buf, count, pos); if (first_read) { - pr_info("read_proxy append %ld + %ld\n", ret, read_count_append); + pr_info("read_proxy append %ld + %ld", ret, read_count_append); ret += read_count_append; } return ret; @@ -285,7 +228,7 @@ static ssize_t read_iter_proxy(struct kiocb *iocb, struct iov_iter *to) bool first_read = iocb->ki_pos == 0; ssize_t ret = orig_read_iter(iocb, to); if (first_read) { - pr_info("read_iter_proxy append %ld + %ld\n", ret, + pr_info("read_iter_proxy append %ld + %ld", ret, read_count_append); ret += read_count_append; } @@ -557,7 +500,6 @@ static void stop_vfs_read_hook() pr_info("unregister vfs_read kprobe: %d!\n", ret); #else ksu_vfs_read_hook = false; - pr_info("stop vfs_read_hook\n"); #endif } @@ -568,7 +510,6 @@ static void stop_execve_hook() pr_info("unregister execve kprobe: %d!\n", ret); #else ksu_execveat_hook = false; - pr_info("stop execve_hook\n"); #endif } @@ -584,7 +525,6 @@ static void stop_input_hook() pr_info("unregister input kprobe: %d!\n", ret); #else ksu_input_hook = false; - pr_info("stop input_hook\n"); #endif } diff --git a/kernel/selinux/rules.c b/kernel/selinux/rules.c index 2ae960afe93f..b41b62d8220e 100644 --- a/kernel/selinux/rules.c +++ b/kernel/selinux/rules.c @@ -39,7 +39,7 @@ static struct policydb *get_policydb(void) void apply_kernelsu_rules() { if (!getenforce()) { - pr_info("SELinux permissive or disabled, apply rules!\n"); + pr_info("SELinux permissive or disabled, apply rules!"); } rcu_read_lock(); @@ -263,7 +263,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4) } else if (subcmd == 4) { success = ksu_dontaudit(db, s, t, c, p); } else { - pr_err("sepol: unknown subcmd: %d\n", subcmd); + pr_err("sepol: unknown subcmd: %d", subcmd); } ret = success ? 0 : -1; @@ -308,7 +308,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4) } else if (subcmd == 3) { success = ksu_dontauditxperm(db, s, t, c, perm_set); } else { - pr_err("sepol: unknown subcmd: %d\n", subcmd); + pr_err("sepol: unknown subcmd: %d", subcmd); } ret = success ? 0 : -1; } else if (cmd == CMD_TYPE_STATE) { @@ -325,7 +325,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4) } else if (subcmd == 2) { success = ksu_enforce(db, src); } else { - pr_err("sepol: unknown subcmd: %d\n", subcmd); + pr_err("sepol: unknown subcmd: %d", subcmd); } if (success) ret = 0; @@ -440,7 +440,7 @@ int handle_sepolicy(unsigned long arg3, void __user *arg4) success = ksu_type_member(db, src, tgt, cls, default_type); } else { - pr_err("sepol: unknown subcmd: %d\n", subcmd); + pr_err("sepol: unknown subcmd: %d", subcmd); } if (success) ret = 0; diff --git a/kernel/selinux/selinux.c b/kernel/selinux/selinux.c index 40a926318a68..e13198897dd8 100644 --- a/kernel/selinux/selinux.c +++ b/kernel/selinux/selinux.c @@ -40,7 +40,7 @@ static int transive_to_domain(const char *domain) void setup_selinux(const char *domain) { if (transive_to_domain(domain)) { - pr_err("transive domain failed.\n"); + pr_err("transive domain failed."); return; } diff --git a/kernel/selinux/sepolicy.c b/kernel/selinux/sepolicy.c index 8d8d98315324..e07c873319c3 100644 --- a/kernel/selinux/sepolicy.c +++ b/kernel/selinux/sepolicy.c @@ -581,14 +581,14 @@ static bool add_filename_trans(struct policydb *db, const char *s, trans = (struct filename_trans_datum *)kcalloc(sizeof(*trans), 1, GFP_ATOMIC); if (!trans) { - pr_err("add_filename_trans: Failed to alloc datum\n"); + pr_err("add_filename_trans: Failed to alloc datum"); return false; } struct filename_trans *new_key = (struct filename_trans *)kmalloc(sizeof(*new_key), GFP_ATOMIC); if (!new_key) { - pr_err("add_filename_trans: Failed to alloc new_key\n"); + pr_err("add_filename_trans: Failed to alloc new_key"); return false; } *new_key = key;