Skip to content

Commit c288f36

Browse files
anotherjinbackslashxx
authored andcommitted
kernel: ksud: add ksu_handle_execve_ksud
adapted from sys_execve_handler_pre() upstream, tiann@2027ac3 this completes the puzzle where all hooks are on syscalls ksu_handle_execve_ksud - sets argv to __argv, dunno what this is for, I just copied. - creates dummy struct `filename_in` to store filename in `filename_in.name` - strncpy filename to path, assign path to .name - simply a shim for ksu_handle_execveat_ksud usage: `ksu_handle_execve_ksud(filename, argv);` on sys_execve tested on 4.14, 6.1 Tested-by: selfmusing <[email protected]> Tested-by: Adam W. Willis <[email protected]> Signed-off-by: backslashxx <[email protected]>
1 parent 7a8436c commit c288f36

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

kernel/ksud.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,36 @@ bool ksu_is_safe_mode()
463463
return false;
464464
}
465465

466+
/*
467+
* ksu_handle_execve_ksud, execve_ksud handler for non kprobe
468+
* adapted from sys_execve_handler_pre
469+
* https://github.com/tiann/KernelSU/commit/2027ac3
470+
*/
471+
__maybe_unused int ksu_handle_execve_ksud(const char __user *filename_user,
472+
const char __user *const __user *__argv)
473+
{
474+
struct user_arg_ptr argv = { .ptr.native = __argv };
475+
struct filename filename_in, *filename_p;
476+
char path[32];
477+
478+
// return early if disabled.
479+
if (!ksu_execveat_hook) {
480+
return 0;
481+
}
482+
483+
if (!filename_user)
484+
return 0;
485+
486+
memset(path, 0, sizeof(path));
487+
ksu_strncpy_from_user_nofault(path, filename_user, 32);
488+
489+
// this is because ksu_handle_execveat_ksud calls it filename->name
490+
filename_in.name = path;
491+
filename_p = &filename_in;
492+
493+
return ksu_handle_execveat_ksud(AT_FDCWD, &filename_p, &argv, NULL, NULL);
494+
}
495+
466496
static void stop_vfs_read_hook()
467497
{
468498
ksu_vfs_read_hook = false;

0 commit comments

Comments
 (0)