kernel: guard functionality that requires kprobes

Since upstream is now making kprobes a requirement, we adapt this tree to still allow
building with manual hooks in an easier way. Furthermore, this also allows a user to
build with manual hooks even with kprobes enabled.

Offending commit:
	kernel: remove unused CONFIG guard becuase GKI kernel enable kprobe by default
	upstream: https://github.com/tiann/KernelSU/commit/500ff9b

Other changes:
	ksud.c, stop_input_hook(), short-circuit redundant logic left by this change.
	cherry pick from: https://github.com/backslashxx/KernelSU/commit/a3d3e93

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
This commit is contained in:
backslashxx
2025-02-23 22:19:44 +08:00
committed by rifsxd
parent 85866848ea
commit 097451d578
5 changed files with 30 additions and 17 deletions
+3 -3
View File
@@ -198,7 +198,7 @@ int ksu_handle_devpts(struct inode *inode)
return 0;
}
#ifdef CONFIG_KPROBES
#ifdef CONFIG_KSU_WITH_KPROBES
static int faccessat_handler_pre(struct kprobe *p, struct pt_regs *regs)
{
@@ -277,7 +277,7 @@ static struct kprobe *su_kps[4];
// sucompat: permited process can execute 'su' to gain root access.
void ksu_sucompat_init()
{
#ifdef CONFIG_KPROBES
#ifdef CONFIG_KSU_WITH_KPROBES
su_kps[0] = init_kprobe(SYS_EXECVE_SYMBOL, execve_handler_pre);
su_kps[1] = init_kprobe(SYS_FACCESSAT_SYMBOL, faccessat_handler_pre);
su_kps[2] = init_kprobe(SYS_NEWFSTATAT_SYMBOL, newfstatat_handler_pre);
@@ -287,7 +287,7 @@ void ksu_sucompat_init()
void ksu_sucompat_exit()
{
#ifdef CONFIG_KPROBES
#ifdef CONFIG_KSU_WITH_KPROBES
for (int i = 0; i < ARRAY_SIZE(su_kps); i++) {
destroy_kprobe(&su_kps[i]);
}