Skip to content

Commit 1101d01

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 df48c44 commit 1101d01

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
@@ -472,6 +472,41 @@ bool ksu_is_safe_mode()
472472
return false;
473473
}
474474

475+
// execve_ksud handlers for non kprobe
476+
static int ksu_common_execve_ksud(const char __user *filename_user,
477+
struct user_arg_ptr *argv)
478+
{
479+
char path[32];
480+
481+
// return early if disabled.
482+
if (!ksu_execveat_hook)
483+
return 0;
484+
485+
if (!filename_user)
486+
return 0;
487+
488+
memset(path, 0, sizeof(path));
489+
ksu_strncpy_from_user_nofault(path, filename_user, 32);
490+
491+
return __ksu_handle_execveat_ksud(AT_FDCWD, path, argv, NULL, NULL);
492+
}
493+
494+
int ksu_handle_execve_ksud(const char __user *filename_user,
495+
const char __user *const __user *__argv)
496+
{
497+
struct user_arg_ptr argv = { .ptr.native = __argv };
498+
return ksu_common_execve_ksud(filename_user, &argv);
499+
}
500+
501+
#if defined(CONFIG_COMPAT)
502+
int ksu_handle_compat_execve_ksud(const char __user *filename_user,
503+
const compat_uptr_t __user *__argv)
504+
{
505+
struct user_arg_ptr argv = { .ptr.compat = __argv };
506+
return ksu_common_execve_ksud(filename_user, &argv);
507+
}
508+
#endif
509+
475510
static void stop_vfs_read_hook()
476511
{
477512
ksu_vfs_read_hook = false;

0 commit comments

Comments
 (0)