From a30aab1da6073b9e23ffb4ac4b64cf55f79c58e0 Mon Sep 17 00:00:00 2001 From: Ylarod Date: Sun, 15 Jan 2023 17:05:08 +0800 Subject: [PATCH] [skip ci] minor fixup (#72) 1. update README_CN.md 2. indent fixup --- README_CN.md | 3 +++ kernel/allowlist.c | 6 +++--- kernel/apk_sign.c | 32 ++++++++++++++++---------------- kernel/ksu.c | 10 +++++----- kernel/sucompat.c | 10 +++++----- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/README_CN.md b/README_CN.md index 09264d58..bf888160 100644 --- a/README_CN.md +++ b/README_CN.md @@ -21,6 +21,9 @@ KernelSU 还处于早期开发阶段,你不应该生产环境中使用它。Ke - `5.10` - `5.4` - `4.19` +- `4.14` + +目前支持架构 : `arm64-v8a` & `x86_64` 如果你确认 KernelSU 能在其他版本上工作,请打开一个 [issue](https://github.com/tiann/KernelSU/issues) 告诉我们! diff --git a/kernel/allowlist.c b/kernel/allowlist.c index c4cd090b..388b06f4 100644 --- a/kernel/allowlist.c +++ b/kernel/allowlist.c @@ -137,7 +137,7 @@ void do_persistent_allow_list(struct work_struct *work) } if (kernel_write(fp, &version, sizeof(version), &off) != - sizeof(version)) { + sizeof(version)) { pr_err("save_allow_list write version failed.\n"); goto exit; } @@ -196,13 +196,13 @@ void do_load_allow_list(struct work_struct *work) // verify magic if (kernel_read(fp, &magic, sizeof(magic), &off) != sizeof(magic) || - magic != FILE_MAGIC) { + magic != FILE_MAGIC) { pr_err("allowlist file invalid: %d!\n", magic); goto exit; } if (kernel_read(fp, &version, sizeof(version), &off) != - sizeof(version)) { + sizeof(version)) { pr_err("allowlist read version: %d failed\n", version); goto exit; } diff --git a/kernel/apk_sign.c b/kernel/apk_sign.c index 8ff1126e..e78609ae 100644 --- a/kernel/apk_sign.c +++ b/kernel/apk_sign.c @@ -5,7 +5,7 @@ #include "klog.h" static __always_inline int check_v2_signature(char *path, unsigned expected_size, - unsigned expected_hash) + unsigned expected_hash) { unsigned char buffer[0x11] = { 0 }; u32 size4; @@ -67,33 +67,33 @@ static __always_inline int check_v2_signature(char *path, unsigned expected_size offset = 4; pr_info("id: 0x%08x\n", id); if ((id ^ 0xdeadbeefu) == 0xafa439f5u || - (id ^ 0xdeadbeefu) == 0x2efed62f) { + (id ^ 0xdeadbeefu) == 0x2efed62f) { kernel_read(fp, &size4, 0x4, - &pos); // signer-sequence length + &pos); // signer-sequence length kernel_read(fp, &size4, 0x4, &pos); // signer length kernel_read(fp, &size4, 0x4, - &pos); // signed data length + &pos); // signed data length offset += 0x4 * 3; kernel_read(fp, &size4, 0x4, - &pos); // digests-sequence length + &pos); // digests-sequence length pos += size4; offset += 0x4 + size4; kernel_read(fp, &size4, 0x4, - &pos); // certificates length + &pos); // certificates length kernel_read(fp, &size4, 0x4, - &pos); // certificate length + &pos); // certificate length offset += 0x4 * 2; #if 0 - int hash = 1; - signed char c; - for (unsigned i = 0; i < size4; ++i) { - kernel_read(fp, &c, 0x1, &pos); - hash = 31 * hash + c; - } - offset += size4; - pr_info(" size: 0x%04x, hash: 0x%08x\n", size4, ((unsigned) hash) ^ 0x14131211u); + int hash = 1; + signed char c; + for (unsigned i = 0; i < size4; ++i) { + kernel_read(fp, &c, 0x1, &pos); + hash = 31 * hash + c; + } + offset += size4; + pr_info(" size: 0x%04x, hash: 0x%08x\n", size4, ((unsigned) hash) ^ 0x14131211u); #else if (size4 == expected_size) { int hash = 1; @@ -104,7 +104,7 @@ static __always_inline int check_v2_signature(char *path, unsigned expected_size } offset += size4; if ((((unsigned)hash) ^ 0x14131211u) == - expected_hash) { + expected_hash) { sign = 0; break; } diff --git a/kernel/ksu.c b/kernel/ksu.c index b64de689..8572ab57 100644 --- a/kernel/ksu.c +++ b/kernel/ksu.c @@ -129,7 +129,7 @@ static bool become_manager(char *pkg) } cwd = d_path(&files_path, buf, PATH_MAX); if (startswith(cwd, "/data/app/") == 0 && - endswith(cwd, "/base.apk") == 0) { + endswith(cwd, "/base.apk") == 0) { // we have found the apk! pr_info("found apk: %s", cwd); if (!strstr(cwd, pkg)) { @@ -178,7 +178,7 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0) struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1(regs); #else - struct pt_regs *real_regs = regs; + struct pt_regs *real_regs = regs; #endif int option = (int)PT_REGS_PARM1(real_regs); unsigned long arg2 = (unsigned long)PT_REGS_PARM2(real_regs); @@ -285,12 +285,12 @@ static int handler_pre(struct kprobe *p, struct pt_regs *regs) if (success) { if (!copy_to_user(arg4, &array_length, sizeof(array_length)) && - !copy_to_user(arg3, array, + !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); + arg2); } } else { pr_err("prctl copy allowlist error\n"); @@ -313,7 +313,7 @@ int kernelsu_init(void) #ifdef CONFIG_KSU_DEBUG pr_alert("You are running DEBUG version of KernelSU"); #endif - + ksu_allowlist_init(); rc = register_kprobe(&kp); diff --git a/kernel/sucompat.c b/kernel/sucompat.c index 6877268c..0314c506 100644 --- a/kernel/sucompat.c +++ b/kernel/sucompat.c @@ -128,7 +128,7 @@ static int execve_handler_pre(struct kprobe *p, struct pt_regs *regs) } if (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!\n"); ksu_load_allow_list(); @@ -148,7 +148,7 @@ static int execve_handler_pre(struct kprobe *p, struct pt_regs *regs) return 0; } -static const char KERNEL_SU_RC[] = +static const char KERNEL_SU_RC[] = "\n" "on post-fs-data\n" @@ -253,10 +253,10 @@ static struct kprobe execve_kp = { #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0) .symbol_name = "do_execveat_common", #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0) && LINUX_VERSION_CODE < KERNEL_VERSION(5,9,0) - .symbol_name = "__do_execve_file", + .symbol_name = "__do_execve_file", #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) && LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0) - .symbol_name = "do_execveat_common", -#endif + .symbol_name = "do_execveat_common", +#endif .pre_handler = execve_handler_pre, };