kernel: Resolving the issue of unavailable functionality

This commit is contained in:
ShirkNeko
2025-11-16 14:25:43 +08:00
parent 8802ea0aee
commit be63a062ad
3 changed files with 45 additions and 25 deletions

View File

@@ -70,9 +70,7 @@ int __init kernelsu_init(void)
sukisu_custom_config_init(); sukisu_custom_config_init();
#if defined(CONFIG_KPROBES) && !defined(CONFIG_KSU_SUSFS)
ksu_syscall_hook_manager_init(); ksu_syscall_hook_manager_init();
#endif
ksu_workqueue = alloc_ordered_workqueue("kernelsu_work_queue", 0); ksu_workqueue = alloc_ordered_workqueue("kernelsu_work_queue", 0);
@@ -109,9 +107,9 @@ void kernelsu_exit(void)
#if defined(CONFIG_KPROBES) && !defined(CONFIG_KSU_SUSFS) #if defined(CONFIG_KPROBES) && !defined(CONFIG_KSU_SUSFS)
ksu_ksud_exit(); ksu_ksud_exit();
#endif
ksu_syscall_hook_manager_exit(); ksu_syscall_hook_manager_exit();
#endif
sukisu_custom_config_exit(); sukisu_custom_config_exit();

View File

@@ -205,8 +205,6 @@ static const char sh_path[] = SH_PATH;
static const char su_path[] = SU_PATH; static const char su_path[] = SU_PATH;
static const char ksud_path[] = KSUD_PATH; static const char ksud_path[] = KSUD_PATH;
extern bool ksu_kernel_umount_enabled;
// the call from execve_handler_pre won't provided correct value for __never_use_argument, use them after fix execve_handler_pre, keeping them for consistence for manually patched code // the call from execve_handler_pre won't provided correct value for __never_use_argument, use them after fix execve_handler_pre, keeping them for consistence for manually patched code
int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr, int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
void *__never_use_argv, void *__never_use_envp, void *__never_use_argv, void *__never_use_envp,
@@ -214,6 +212,10 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
{ {
struct filename *filename; struct filename *filename;
if (!ksu_su_compat_enabled){
return 0;
}
if (unlikely(!filename_ptr)) if (unlikely(!filename_ptr))
return 0; return 0;
@@ -236,6 +238,10 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv, int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
void *envp, int *flags) void *envp, int *flags)
{ {
if (!ksu_su_compat_enabled){
return 0;
}
if (ksu_handle_execveat_ksud(fd, filename_ptr, argv, envp, flags)) { if (ksu_handle_execveat_ksud(fd, filename_ptr, argv, envp, flags)) {
return 0; return 0;
} }
@@ -248,6 +254,10 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
{ {
char path[sizeof(su_path) + 1] = {0}; char path[sizeof(su_path) + 1] = {0};
if (!ksu_su_compat_enabled){
return 0;
}
strncpy_from_user_nofault(path, *filename_user, sizeof(path)); strncpy_from_user_nofault(path, *filename_user, sizeof(path));
if (unlikely(!memcmp(path, su_path, sizeof(su_path)))) { if (unlikely(!memcmp(path, su_path, sizeof(su_path)))) {
@@ -277,6 +287,10 @@ int ksu_handle_stat(int *dfd, struct filename **filename, int *flags) {
#else #else
int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags) int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags)
{ {
if (!ksu_su_compat_enabled){
return 0;
}
if (unlikely(!filename_user)) { if (unlikely(!filename_user)) {
return 0; return 0;
} }
@@ -313,27 +327,31 @@ int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags)
int ksu_handle_devpts(struct inode *inode) int ksu_handle_devpts(struct inode *inode)
{ {
if (!current->mm) { if (!current->mm) {
return 0;
}
uid_t uid = current_uid().val;
if (uid % 100000 < 10000) {
// not untrusted_app, ignore it
return 0;
}
if (!__ksu_is_allow_uid_for_current(uid))
return 0;
if (ksu_file_sid) {
struct inode_security_struct *sec = selinux_inode(inode);
if (sec) {
sec->sid = ksu_file_sid;
}
}
return 0; return 0;
}
if (!ksu_su_compat_enabled){
return 0;
}
uid_t uid = current_uid().val;
if (uid % 100000 < 10000) {
// not untrusted_app, ignore it
return 0;
}
if (!__ksu_is_allow_uid_for_current(uid))
return 0;
if (ksu_file_sid) {
struct inode_security_struct *sec = selinux_inode(inode);
if (sec) {
sec->sid = ksu_file_sid;
}
}
return 0;
} }
#endif // #ifndef CONFIG_KSU_SUSFS #endif // #ifndef CONFIG_KSU_SUSFS

View File

@@ -324,6 +324,7 @@ static void ksu_sys_enter_handler(void *data, struct pt_regs *regs, long id)
void ksu_syscall_hook_manager_init(void) void ksu_syscall_hook_manager_init(void)
{ {
#if defined(CONFIG_KPROBES) && !defined(CONFIG_KSU_SUSFS)
int ret; int ret;
pr_info("hook_manager: ksu_hook_manager_init called\n"); pr_info("hook_manager: ksu_hook_manager_init called\n");
@@ -344,6 +345,7 @@ void ksu_syscall_hook_manager_init(void)
} else { } else {
pr_info("hook_manager: sys_enter tracepoint registered\n"); pr_info("hook_manager: sys_enter tracepoint registered\n");
} }
#endif
#endif #endif
ksu_setuid_hook_init(); ksu_setuid_hook_init();
@@ -352,6 +354,7 @@ void ksu_syscall_hook_manager_init(void)
void ksu_syscall_hook_manager_exit(void) void ksu_syscall_hook_manager_exit(void)
{ {
#if defined(CONFIG_KPROBES) && !defined(CONFIG_KSU_SUSFS)
pr_info("hook_manager: ksu_hook_manager_exit called\n"); pr_info("hook_manager: ksu_hook_manager_exit called\n");
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
unregister_trace_sys_enter(ksu_sys_enter_handler, NULL); unregister_trace_sys_enter(ksu_sys_enter_handler, NULL);
@@ -362,6 +365,7 @@ void ksu_syscall_hook_manager_exit(void)
#ifdef CONFIG_KRETPROBES #ifdef CONFIG_KRETPROBES
destroy_kretprobe(&syscall_regfunc_rp); destroy_kretprobe(&syscall_regfunc_rp);
destroy_kretprobe(&syscall_unregfunc_rp); destroy_kretprobe(&syscall_unregfunc_rp);
#endif
#endif #endif
ksu_sucompat_exit(); ksu_sucompat_exit();