@@ -21,6 +21,9 @@ KernelSU 还处于早期开发阶段,你不应该生产环境中使用它。Ke
|
|||||||
- `5.10`
|
- `5.10`
|
||||||
- `5.4`
|
- `5.4`
|
||||||
- `4.19`
|
- `4.19`
|
||||||
|
- `4.14`
|
||||||
|
|
||||||
|
目前支持架构 : `arm64-v8a` & `x86_64`
|
||||||
|
|
||||||
如果你确认 KernelSU 能在其他版本上工作,请打开一个 [issue](https://github.com/tiann/KernelSU/issues) 告诉我们!
|
如果你确认 KernelSU 能在其他版本上工作,请打开一个 [issue](https://github.com/tiann/KernelSU/issues) 告诉我们!
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ void do_persistent_allow_list(struct work_struct *work)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (kernel_write(fp, &version, sizeof(version), &off) !=
|
if (kernel_write(fp, &version, sizeof(version), &off) !=
|
||||||
sizeof(version)) {
|
sizeof(version)) {
|
||||||
pr_err("save_allow_list write version failed.\n");
|
pr_err("save_allow_list write version failed.\n");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@@ -196,13 +196,13 @@ void do_load_allow_list(struct work_struct *work)
|
|||||||
|
|
||||||
// verify magic
|
// verify magic
|
||||||
if (kernel_read(fp, &magic, sizeof(magic), &off) != sizeof(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);
|
pr_err("allowlist file invalid: %d!\n", magic);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kernel_read(fp, &version, sizeof(version), &off) !=
|
if (kernel_read(fp, &version, sizeof(version), &off) !=
|
||||||
sizeof(version)) {
|
sizeof(version)) {
|
||||||
pr_err("allowlist read version: %d failed\n", version);
|
pr_err("allowlist read version: %d failed\n", version);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "klog.h"
|
#include "klog.h"
|
||||||
|
|
||||||
static __always_inline int check_v2_signature(char *path, unsigned expected_size,
|
static __always_inline int check_v2_signature(char *path, unsigned expected_size,
|
||||||
unsigned expected_hash)
|
unsigned expected_hash)
|
||||||
{
|
{
|
||||||
unsigned char buffer[0x11] = { 0 };
|
unsigned char buffer[0x11] = { 0 };
|
||||||
u32 size4;
|
u32 size4;
|
||||||
@@ -67,33 +67,33 @@ static __always_inline int check_v2_signature(char *path, unsigned expected_size
|
|||||||
offset = 4;
|
offset = 4;
|
||||||
pr_info("id: 0x%08x\n", id);
|
pr_info("id: 0x%08x\n", id);
|
||||||
if ((id ^ 0xdeadbeefu) == 0xafa439f5u ||
|
if ((id ^ 0xdeadbeefu) == 0xafa439f5u ||
|
||||||
(id ^ 0xdeadbeefu) == 0x2efed62f) {
|
(id ^ 0xdeadbeefu) == 0x2efed62f) {
|
||||||
kernel_read(fp, &size4, 0x4,
|
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); // signer length
|
||||||
kernel_read(fp, &size4, 0x4,
|
kernel_read(fp, &size4, 0x4,
|
||||||
&pos); // signed data length
|
&pos); // signed data length
|
||||||
offset += 0x4 * 3;
|
offset += 0x4 * 3;
|
||||||
|
|
||||||
kernel_read(fp, &size4, 0x4,
|
kernel_read(fp, &size4, 0x4,
|
||||||
&pos); // digests-sequence length
|
&pos); // digests-sequence length
|
||||||
pos += size4;
|
pos += size4;
|
||||||
offset += 0x4 + size4;
|
offset += 0x4 + size4;
|
||||||
|
|
||||||
kernel_read(fp, &size4, 0x4,
|
kernel_read(fp, &size4, 0x4,
|
||||||
&pos); // certificates length
|
&pos); // certificates length
|
||||||
kernel_read(fp, &size4, 0x4,
|
kernel_read(fp, &size4, 0x4,
|
||||||
&pos); // certificate length
|
&pos); // certificate length
|
||||||
offset += 0x4 * 2;
|
offset += 0x4 * 2;
|
||||||
#if 0
|
#if 0
|
||||||
int hash = 1;
|
int hash = 1;
|
||||||
signed char c;
|
signed char c;
|
||||||
for (unsigned i = 0; i < size4; ++i) {
|
for (unsigned i = 0; i < size4; ++i) {
|
||||||
kernel_read(fp, &c, 0x1, &pos);
|
kernel_read(fp, &c, 0x1, &pos);
|
||||||
hash = 31 * hash + c;
|
hash = 31 * hash + c;
|
||||||
}
|
}
|
||||||
offset += size4;
|
offset += size4;
|
||||||
pr_info(" size: 0x%04x, hash: 0x%08x\n", size4, ((unsigned) hash) ^ 0x14131211u);
|
pr_info(" size: 0x%04x, hash: 0x%08x\n", size4, ((unsigned) hash) ^ 0x14131211u);
|
||||||
#else
|
#else
|
||||||
if (size4 == expected_size) {
|
if (size4 == expected_size) {
|
||||||
int hash = 1;
|
int hash = 1;
|
||||||
@@ -104,7 +104,7 @@ static __always_inline int check_v2_signature(char *path, unsigned expected_size
|
|||||||
}
|
}
|
||||||
offset += size4;
|
offset += size4;
|
||||||
if ((((unsigned)hash) ^ 0x14131211u) ==
|
if ((((unsigned)hash) ^ 0x14131211u) ==
|
||||||
expected_hash) {
|
expected_hash) {
|
||||||
sign = 0;
|
sign = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ static bool become_manager(char *pkg)
|
|||||||
}
|
}
|
||||||
cwd = d_path(&files_path, buf, PATH_MAX);
|
cwd = d_path(&files_path, buf, PATH_MAX);
|
||||||
if (startswith(cwd, "/data/app/") == 0 &&
|
if (startswith(cwd, "/data/app/") == 0 &&
|
||||||
endswith(cwd, "/base.apk") == 0) {
|
endswith(cwd, "/base.apk") == 0) {
|
||||||
// we have found the apk!
|
// we have found the apk!
|
||||||
pr_info("found apk: %s", cwd);
|
pr_info("found apk: %s", cwd);
|
||||||
if (!strstr(cwd, pkg)) {
|
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)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
|
||||||
struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1(regs);
|
struct pt_regs *real_regs = (struct pt_regs *)PT_REGS_PARM1(regs);
|
||||||
#else
|
#else
|
||||||
struct pt_regs *real_regs = regs;
|
struct pt_regs *real_regs = regs;
|
||||||
#endif
|
#endif
|
||||||
int option = (int)PT_REGS_PARM1(real_regs);
|
int option = (int)PT_REGS_PARM1(real_regs);
|
||||||
unsigned long arg2 = (unsigned long)PT_REGS_PARM2(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 (success) {
|
||||||
if (!copy_to_user(arg4, &array_length,
|
if (!copy_to_user(arg4, &array_length,
|
||||||
sizeof(array_length)) &&
|
sizeof(array_length)) &&
|
||||||
!copy_to_user(arg3, array,
|
!copy_to_user(arg3, array,
|
||||||
sizeof(u32) * array_length)) {
|
sizeof(u32) * array_length)) {
|
||||||
if (!copy_to_user(result, &reply_ok,
|
if (!copy_to_user(result, &reply_ok,
|
||||||
sizeof(reply_ok))) {
|
sizeof(reply_ok))) {
|
||||||
pr_err("prctl reply error, cmd: %d\n",
|
pr_err("prctl reply error, cmd: %d\n",
|
||||||
arg2);
|
arg2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pr_err("prctl copy allowlist error\n");
|
pr_err("prctl copy allowlist error\n");
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ static int execve_handler_pre(struct kprobe *p, struct pt_regs *regs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (first_app_process &&
|
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;
|
first_app_process = false;
|
||||||
pr_info("exec app_process, /data prepared!\n");
|
pr_info("exec app_process, /data prepared!\n");
|
||||||
ksu_load_allow_list();
|
ksu_load_allow_list();
|
||||||
@@ -253,9 +253,9 @@ static struct kprobe execve_kp = {
|
|||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
|
||||||
.symbol_name = "do_execveat_common",
|
.symbol_name = "do_execveat_common",
|
||||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,19,0) && LINUX_VERSION_CODE < KERNEL_VERSION(5,9,0)
|
#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)
|
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) && LINUX_VERSION_CODE < KERNEL_VERSION(4,19,0)
|
||||||
.symbol_name = "do_execveat_common",
|
.symbol_name = "do_execveat_common",
|
||||||
#endif
|
#endif
|
||||||
.pre_handler = execve_handler_pre,
|
.pre_handler = execve_handler_pre,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user