Skip to content

Commit

Permalink
kernel: add CONFIG_KSU_DEBUG (#19)
Browse files Browse the repository at this point in the history
* Kconfig: add KSU_DEBUG

* print alert on debug mode

* allow shell by default

* store signature to var on debug mode

* format

* export as module_param

* rename apk_sign to kernelsu
  • Loading branch information
Ylarod authored Jan 14, 2023
1 parent 50f44ff commit 5e77d1c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions kernel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ config KSU
depends on OVERLAY_FS
help
This is the KSU privilege driver for android system.

config KSU_DEBUG
tristate "KernelSU module debug mode"
default n
depends on KSU
help
This enables debug mode for KSU
3 changes: 2 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
obj-y += ksu.o
obj-y += allowlist.o
obj-y += apk_sign.o
kernelsu-objs := apk_sign.o
obj-y += kernelsu.o
obj-y += module_api.o
obj-y += sucompat.o

Expand Down
9 changes: 9 additions & 0 deletions kernel/allowlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,16 @@ void do_load_allow_list(struct work_struct *work)
fp = filp_open(KERNEL_SU_ALLOWLIST, O_RDONLY, 0);

if (IS_ERR(fp)) {
#ifdef CONFIG_KSU_DEBUG
int errno = PTR_ERR(fp);
if (errno == -ENOENT) {
ksu_allow_uid(2000, true); // allow adb shell by default
} else {
pr_err("load_allow_list open file failed: %d\n", PTR_ERR(fp));
}
#else
pr_err("load_allow_list open file failed: %d\n", PTR_ERR(fp));
#endif
return;
}

Expand Down
23 changes: 21 additions & 2 deletions kernel/apk_sign.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <linux/moduleparam.h>
#include <linux/fs.h>

#include "apk_sign.h"
#include "klog.h"

static 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 char buffer[0x11] = { 0 };
Expand Down Expand Up @@ -121,7 +122,25 @@ static int check_v2_signature(char *path, unsigned expected_size,
return sign;
}

#ifdef CONFIG_KSU_DEBUG

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);

int is_manager_apk(char *path)
{
return check_v2_signature(path, ksu_expected_size, ksu_expected_hash);
}

#else


int is_manager_apk(char *path)
{
return check_v2_signature(path, EXPECTED_SIZE, EXPECTED_HASH);
}
}

#endif
4 changes: 4 additions & 0 deletions kernel/ksu.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ int kernelsu_init(void)
{
int rc = 0;

#ifdef CONFIG_KSU_DEBUG
pr_alert("You are running DEBUG version of KernelSU");
#endif

ksu_allowlist_init();

rc = register_kprobe(&kp);
Expand Down

0 comments on commit 5e77d1c

Please sign in to comment.