Skip to content

Commit 2a28c2e

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 75bb3ab commit 2a28c2e

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

kernel/ksud.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code,
456456
return 0;
457457
}
458458

459-
bool ksu_is_safe_mode()
459+
bool ksu_is_safe_mode(void)
460460
{
461461
static bool safe_mode = false;
462462
if (safe_mode) {
@@ -478,6 +478,41 @@ bool ksu_is_safe_mode()
478478
return false;
479479
}
480480

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

0 commit comments

Comments
 (0)