Skip to content

Commit de7f274

Browse files
backslashxxanotherjin
authored andcommitted
kernel: ksud: add commonized execve/compat_execve hooks for ksud
This commit squashes the following: - kernel: ksud: commonize execve_ksud handlers - kernel: ksud: provide ksu_handle_compat_execve_ksud v2 - kernel: ksud: add ksu_handle_execve_ksud v2 This finalizes syscall-only hooking for KernelSU as we provide both native and compat. - sys_execve - ksu_handle_execve_ksud - compat_sys_execve - ksu_handle_compat_execve_ksud since these two share common logic, we commonize them to ksu_common_execve_ksud sinc only the argv field is different. (.native vs .compat) usage: ksu_handle_execve_ksud(filename, argv); // for sys_execve ksu_handle_compat_execve_ksud(filename, argv); // for compat_sys_execve This implementations avoids any dependency on struct filename making it also usable on Ultra-Legacy. Requires: - kernel: ksud: dont create structs just to deconstruct them for a string (tiann#2595) original logic was taken from sys_execve_handler_pre upstream: tiann@2027ac3 Tested-by: selfmusing <[email protected]> Tested-by: Adam W. Willis <[email protected]> Tested-by: alternoegraha <[email protected]> Tested-by: iDead XD <[email protected]> Tested-by: rsuntk <[email protected]> Signed-off-by: backslashxx <[email protected]> Co-Authored-By: Another Guy <[email protected]>
1 parent e99a1b8 commit de7f274

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

kernel/ksud.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,41 @@ bool ksu_is_safe_mode()
484484
return false;
485485
}
486486

487+
// execve_ksud handlers for non kprobe
488+
static int ksu_common_execve_ksud(const char __user *filename_user,
489+
struct user_arg_ptr *argv)
490+
{
491+
char path[32];
492+
493+
// return early if disabled.
494+
if (!ksu_execveat_hook)
495+
return 0;
496+
497+
if (!filename_user)
498+
return 0;
499+
500+
memset(path, 0, sizeof(path));
501+
ksu_strncpy_from_user_nofault(path, filename_user, 32);
502+
503+
return __ksu_handle_execveat_ksud(AT_FDCWD, path, argv, NULL, NULL);
504+
}
505+
506+
int ksu_handle_execve_ksud(const char __user *filename_user,
507+
const char __user *const __user *__argv)
508+
{
509+
struct user_arg_ptr argv = { .ptr.native = __argv };
510+
return ksu_common_execve_ksud(filename_user, &argv);
511+
}
512+
513+
#if defined(CONFIG_COMPAT)
514+
int ksu_handle_compat_execve_ksud(const char __user *filename_user,
515+
const compat_uptr_t __user *__argv)
516+
{
517+
struct user_arg_ptr argv = { .ptr.compat = __argv };
518+
return ksu_common_execve_ksud(filename_user, &argv);
519+
}
520+
#endif
521+
487522
static void stop_vfs_read_hook()
488523
{
489524
ksu_vfs_read_hook = false;

0 commit comments

Comments
 (0)