From 758c8eb8450d9c6e7fb3eae4aadd9d18eebc1f85 Mon Sep 17 00:00:00 2001 From: weishu Date: Tue, 20 Dec 2022 10:51:40 +0700 Subject: [PATCH] kernel: fix compile errors & warnings on android13-5.15 gki --- kernel/allowlist.c | 6 +++--- kernel/ksu.c | 46 ++++++++++++++++++++++++++++++---------------- kernel/sucompat.c | 5 +++-- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/kernel/allowlist.c b/kernel/allowlist.c index 4a1a15a9..06ea33c1 100644 --- a/kernel/allowlist.c +++ b/kernel/allowlist.c @@ -87,13 +87,14 @@ exit: } bool ksu_is_allow_uid(uid_t uid) { + struct perm_data *p = NULL; + struct list_head *pos = NULL; + if (uid == 0) { // already root return true; } - struct perm_data *p = NULL; - struct list_head *pos = NULL; list_for_each(pos, &allow_list) { p = list_entry(pos, struct perm_data, list); // pr_info("is_allow_uid uid :%d, allow: %d\n", p->uid, p->allow); @@ -162,7 +163,6 @@ void do_load_allow_list(struct work_struct *work) { loff_t off = 0; ssize_t ret = 0; struct file *fp = NULL; - int n = 0; u32 magic; u32 version; diff --git a/kernel/ksu.c b/kernel/ksu.c index cc67ce90..4e6fd454 100644 --- a/kernel/ksu.c +++ b/kernel/ksu.c @@ -83,21 +83,25 @@ static bool is_manager() { } static bool become_manager() { - if (__manager_uid != 0) { - pr_info("manager already exist: %d\n", __manager_uid); - return true; - } - // list current process's files - struct files_struct *current_files; struct fdtable *files_table; int i = 0; struct path files_path; char *cwd; - char *buf = (char *)kmalloc(GFP_KERNEL, PATH_MAX); + char *buf; bool result = false; - current_files = current->files; - files_table = files_fdtable(current_files); + if (__manager_uid != 0) { + pr_info("manager already exist: %d\n", __manager_uid); + return true; + } + + buf = (char *) kmalloc(GFP_KERNEL, PATH_MAX); + if (!buf) { + pr_err("kalloc path failed.\n"); + return false; + } + + files_table = files_fdtable(current->files); // todo: use iterate_fd while(files_table->fd[i] != NULL) { @@ -168,7 +172,9 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs) { // someone wants to be root manager, just check it! bool success = become_manager(); if (success) { - copy_to_user(result, &reply_ok, sizeof(reply_ok)); + if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) { + pr_err("prctl reply error\n"); + } } return 0; } @@ -198,21 +204,29 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs) { uid_t uid = (uid_t) arg3; success = ksu_allow_uid(uid, allow); if (success) { - copy_to_user(result, &reply_ok, sizeof(reply_ok)); + if (copy_to_user(result, &reply_ok, sizeof(reply_ok))) { + pr_err("prctl reply error, cmd: %d\n", arg2); + } } } else if (arg2 == CMD_GET_ALLOW_LIST || arg2 == CMD_GET_DENY_LIST) { u32 array[128]; u32 array_length; bool success = ksu_get_allow_list(array, &array_length, arg2 == CMD_GET_ALLOW_LIST); if (success) { - copy_to_user(arg4, &array_length, sizeof(array_length)); - copy_to_user(arg3, array, sizeof(u32) * array_length); - - copy_to_user(result, &reply_ok, sizeof(reply_ok)); + if (!copy_to_user(arg4, &array_length, sizeof(array_length)) && + !copy_to_user(arg3, array, sizeof(u32) * array_length)) { + if (!copy_to_user(result, &reply_ok, sizeof(reply_ok))) { + pr_err("prctl reply error, cmd: %d\n", arg2); + } + } else { + pr_err("prctl copy allowlist error\n"); + } } } else if (arg2 == CMD_GET_VERSION) { u32 version = KERNEL_SU_VERSION; - copy_to_user(arg3, &version, sizeof(version)); + if (copy_to_user(arg3, &version, sizeof(version))) { + pr_err("prctl reply error, cmd: %d\n", arg2); + } } return 0; diff --git a/kernel/sucompat.c b/kernel/sucompat.c index 18933a81..9c1a5bba 100644 --- a/kernel/sucompat.c +++ b/kernel/sucompat.c @@ -93,13 +93,14 @@ static int execve_handler_pre(struct kprobe *p, struct pt_regs *regs) { const char sh[] = SH_PATH; const char su[] = SU_PATH; + static const char app_process[] = "/system/bin/app_process"; + static bool first_app_process = true; + filename = PT_REGS_PARM2(regs); if (IS_ERR(filename)) { return 0; } - 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");