kernel: refact (#113)

* refact

* sort inlude

* update

* unregister execve kprobe

* update log

* don't unregister if not in kprobe

* opt for no kprobe

* opt for no kprobe

* stop debug

* don't forget to call ksu_uid_observer_exit

* rename core to core_hook

* direct call do_persistent_allow_list

* add prefix

* use getter, add warn

* add wrapper

* run clang-format

clang-format --style="{BasedOnStyle: InheritParentConfig, SortIncludes: true}" -i kernel/**/*.[ch]

* try fix wsa x64 build
This commit is contained in:
Ylarod
2023-01-25 21:53:19 +08:00
committed by GitHub
parent 5fb8316e46
commit 2f970f7ab8
26 changed files with 1002 additions and 850 deletions

View File

@@ -1,11 +1,10 @@
#include <linux/moduleparam.h>
#include <linux/fs.h>
#include "linux/fs.h"
#include "linux/moduleparam.h"
#include "apk_sign.h"
#include "klog.h"
static __always_inline int check_v2_signature(char *path, unsigned expected_size,
unsigned expected_hash)
static __always_inline int
check_v2_signature(char *path, unsigned expected_size, unsigned expected_hash)
{
unsigned char buffer[0x11] = { 0 };
u32 size4;
@@ -67,23 +66,23 @@ 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;
@@ -104,7 +103,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;
}
@@ -127,8 +126,38 @@ clean:
unsigned ksu_expected_size = EXPECTED_SIZE;
unsigned ksu_expected_hash = EXPECTED_HASH;
module_param(ksu_expected_size, uint, S_IRUSR | S_IWUSR);
module_param(ksu_expected_hash, uint, S_IRUSR | S_IWUSR);
#include "manager.h"
static int set_expected_size(const char *val, const struct kernel_param *kp)
{
int rv = param_set_uint(val, kp);
ksu_invalidate_manager_uid();
pr_info("ksu_expected_size set to %x", ksu_expected_size);
return rv;
}
static int set_expected_hash(const char *val, const struct kernel_param *kp)
{
int rv = param_set_uint(val, kp);
ksu_invalidate_manager_uid();
pr_info("ksu_expected_hash set to %x", ksu_expected_hash);
return rv;
}
static struct kernel_param_ops expected_size_ops = {
.set = set_expected_size,
.get = param_get_uint,
};
static struct kernel_param_ops expected_hash_ops = {
.set = set_expected_hash,
.get = param_get_uint,
};
module_param_cb(ksu_expected_size, &expected_size_ops, &ksu_expected_size,
S_IRUSR | S_IWUSR);
module_param_cb(ksu_expected_hash, &expected_hash_ops, &ksu_expected_hash,
S_IRUSR | S_IWUSR);
int is_manager_apk(char *path)
{
@@ -137,7 +166,6 @@ int is_manager_apk(char *path)
#else
int is_manager_apk(char *path)
{
return check_v2_signature(path, EXPECTED_SIZE, EXPECTED_HASH);