kernel: Simplify state management logic

This commit is contained in:
ShirkNeko
2025-11-09 14:06:25 +08:00
parent 3e5f69cdf8
commit f670151f20
4 changed files with 23 additions and 19 deletions

View File

@@ -96,9 +96,8 @@ ifeq ($(CONFIG_KSU_MANUAL_HOOK), y)
ccflags-y += -DKSU_MANUAL_HOOK
$(info -- SukiSU: KSU_MANUAL_HOOK)
else
ccflags-y += -DKSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
ccflags-y += -DKSU_LKM_MODE
ccflags-y += -DKSU_KPROBES_HOOK
ccflags-y += -DKSU_TP_HOOK
$(info -- SukiSU: KSU_TRACEPOINT_HOOK)
endif

View File

@@ -77,7 +77,7 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
{
const char su[] = SU_PATH;
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
#ifdef KSU_MANUAL_HOOK
if (!ksu_su_compat_enabled) {
return 0;
}
@@ -107,7 +107,7 @@ int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags)
// const char sh[] = SH_PATH;
const char su[] = SU_PATH;
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
#ifdef KSU_MANUAL_HOOK
if (!ksu_su_compat_enabled) {
return 0;
}
@@ -159,7 +159,7 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
const char sh[] = KSUD_PATH;
const char su[] = SU_PATH;
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
#ifdef KSU_MANUAL_HOOK
if (!ksu_su_compat_enabled) {
return 0;
}
@@ -211,7 +211,7 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
const char su[] = SU_PATH;
char path[sizeof(su) + 1];
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
#ifdef KSU_MANUAL_HOOK
if (!ksu_su_compat_enabled){
return 0;
}
@@ -250,7 +250,7 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
int __ksu_handle_devpts(struct inode *inode)
{
#ifndef KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK
#ifdef KSU_MANUAL_HOOK
if (!ksu_su_compat_enabled)
return 0;
#endif

View File

@@ -9,6 +9,7 @@
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/version.h>
#include <linux/kprobes.h>
#include "arch.h"
#include "allowlist.h"
@@ -503,13 +504,12 @@ static int do_get_full_version(void __user *arg)
static int do_get_hook_type(void __user *arg)
{
struct ksu_hook_type_cmd cmd = {0};
const char *type = "Unknown";
const char *type = "Tracepoint";
#if defined(KSU_HAVE_SYSCALL_TRACEPOINTS_HOOK)
type = "Tracepoint";
#elif defined(KSU_MANUAL_HOOK)
#if defined(KSU_MANUAL_HOOK)
type = "Manual";
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
strscpy(cmd.hook_type, type, sizeof(cmd.hook_type));
#else
@@ -743,6 +743,7 @@ int ksu_handle_sys_reboot(int magic1, int magic2, unsigned int cmd, void __user
return 0;
}
#ifdef KSU_KPROBES_HOOK
// Reboot hook for installing fd
static int reboot_handler_pre(struct kprobe *p, struct pt_regs *regs)
{
@@ -759,6 +760,7 @@ static struct kprobe reboot_kp = {
.symbol_name = REBOOT_SYMBOL,
.pre_handler = reboot_handler_pre,
};
#endif
void ksu_supercalls_init(void)
{
@@ -768,17 +770,20 @@ void ksu_supercalls_init(void)
for (i = 0; ksu_ioctl_handlers[i].handler; i++) {
pr_info(" %-18s = 0x%08x\n", ksu_ioctl_handlers[i].name, ksu_ioctl_handlers[i].cmd);
}
#ifdef KSU_KPROBES_HOOK
int rc = register_kprobe(&reboot_kp);
if (rc) {
pr_err("reboot kprobe failed: %d\n", rc);
} else {
pr_info("reboot kprobe registered successfully\n");
}
#endif
}
void ksu_supercalls_exit(void){
#ifdef KSU_KPROBES_HOOK
unregister_kprobe(&reboot_kp);
#endif
}
static inline void ksu_ioctl_audit(unsigned int cmd, const char *cmd_name, uid_t uid, int ret)

View File

@@ -320,7 +320,7 @@ static inline void ksu_handle_task_alloc(struct pt_regs *regs)
static void ksu_sys_enter_handler(void *data, struct pt_regs *regs, long id)
{
if (unlikely(check_syscall_fastpath(id))) {
#ifdef KSU_LKM_MODE
#ifdef KSU_TP_HOOK
if (ksu_su_compat_enabled) {
// Handle newfstatat
if (id == __NR_newfstatat) {