kernel: ksud: commonize handle_execve_ksud and add support for compat_execve_ksud (#109)

* This is only for 32bit userspace, 64bit kernel
* Adapt from backslashxx KernelSU repository (our fork still using struct)
* Sync-up with baskslashxx's scope minimized hook.

Signed-off-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
This commit is contained in:
rsuntk
2025-06-12 07:30:03 +07:00
committed by ShirkNeko
parent 8359bc5890
commit a0fd27dc33

View File

@@ -604,15 +604,9 @@ static void do_stop_input_hook(struct work_struct *work)
unregister_kprobe(&input_event_kp); unregister_kprobe(&input_event_kp);
} }
#else #else
/* static int ksu_common_execve_ksud(const char __user *filename_user,
* ksu_handle_execve_ksud, execve_ksud handler for non kprobe struct user_arg_ptr *argv)
* adapted from sys_execve_handler_pre
* https://github.com/tiann/KernelSU/commit/2027ac3
*/
__maybe_unused int ksu_handle_execve_ksud(const char __user *filename_user,
const char __user *const __user *__argv)
{ {
struct user_arg_ptr argv = { .ptr.native = __argv };
struct filename filename_in, *filename_p; struct filename filename_in, *filename_p;
char path[32]; char path[32];
@@ -631,8 +625,25 @@ __maybe_unused int ksu_handle_execve_ksud(const char __user *filename_user,
filename_in.name = path; filename_in.name = path;
filename_p = &filename_in; filename_p = &filename_in;
return ksu_handle_execveat_ksud(AT_FDCWD, &filename_p, &argv, NULL, NULL); return ksu_handle_execveat_ksud(AT_FDCWD, &filename_p, argv, NULL, NULL);
} }
int __maybe_unused ksu_handle_execve_ksud(const char __user *filename_user,
const char __user *const __user *__argv)
{
struct user_arg_ptr argv = { .ptr.native = __argv };
return ksu_common_execve_ksud(filename_user, &argv);
}
#if defined(CONFIG_COMPAT) && defined(CONFIG_64BIT)
int __maybe_unused ksu_handle_compat_execve_ksud(const char __user *filename_user,
const compat_uptr_t __user *__argv)
{
struct user_arg_ptr argv = { .ptr.compat = __argv };
return ksu_common_execve_ksud(filename_user, &argv);
}
#endif /* COMPAT & 64BIT */
#endif #endif
static void stop_vfs_read_hook() static void stop_vfs_read_hook()