Skip to content

kernel: escape to ksu domain in execve hook, remove sepolicy between …#3031

Merged
aviraxp merged 2 commits into
mainfrom
ksudpriv
Dec 3, 2025
Merged

kernel: escape to ksu domain in execve hook, remove sepolicy between …#3031
aviraxp merged 2 commits into
mainfrom
ksudpriv

Conversation

@5ec1cff

@5ec1cff 5ec1cff commented Dec 3, 2025

Copy link
Copy Markdown
Collaborator

…init and adb_data_file

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors SELinux domain and context handling by centralizing constant definitions and adds kernel-level SELinux context switching when init executes ksud, eliminating the need for explicit SELinux policy rules between init and adb_data_file.

Key changes:

  • Centralized SELinux domain/context constants in selinux.h to eliminate duplication across multiple files
  • Added kernel hook to automatically transition to KSU domain when init executes ksud
  • Removed SELinux policy rules allowing init access to adb_data_file, as the new kernel hook handles the context switch directly

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
kernel/selinux/selinux.h Added centralized definitions for KERNEL_SU_DOMAIN, KERNEL_SU_FILE, KERNEL_SU_CONTEXT, and KSU_FILE_CONTEXT constants
kernel/selinux/selinux.c Updated to use new KERNEL_SU_CONTEXT and KSU_FILE_CONTEXT constants from selinux.h
kernel/selinux/rules.c Removed duplicate constant definitions and deleted init/adb_data_file policy rules (replaced by kernel hook)
kernel/ksud.c Updated init.rc strings to use KERNEL_SU_DOMAIN constant instead of hardcoded "su"
kernel/allowlist.c Updated default SELinux domain to use KERNEL_SU_DOMAIN constant
kernel/app_profile.h Added declaration for new escape_to_root_for_init() function
kernel/app_profile.c Implemented escape_to_root_for_init() to set KSU SELinux context
kernel/syscall_hook_manager.c Added logic to detect ksud execution by init and call escape_to_root_for_init() to transition SELinux context

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kernel/syscall_hook_manager.c Outdated
Comment thread kernel/syscall_hook_manager.c Outdated
Comment thread kernel/app_profile.c
Comment thread kernel/app_profile.h
Comment thread kernel/syscall_hook_manager.c Outdated
@aviraxp aviraxp merged commit 6e918fc into main Dec 3, 2025
15 checks passed
@aviraxp aviraxp deleted the ksudpriv branch December 3, 2025 11:30
KOWX712 pushed a commit to KOWX712/KernelSU that referenced this pull request Dec 3, 2025
larpedd pushed a commit to larpedd/KernelSU that referenced this pull request Dec 20, 2025
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 1, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 1, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 1, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 1, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 2, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 3, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
u9521 pushed a commit to u9521/KernelSU that referenced this pull request Jan 5, 2026
u9521 pushed a commit to u9521/KernelSU that referenced this pull request Jan 5, 2026
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 5, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 5, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 5, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 6, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 6, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 7, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 7, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 7, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 7, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 10, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 10, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 10, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 10, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 10, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 11, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 12, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 12, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
u9521 pushed a commit to u9521/KernelSU that referenced this pull request Jan 13, 2026
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 13, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 14, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 14, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 14, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 14, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 15, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 15, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Jan 17, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: backslashxx@f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
backslashxx@ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 18, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 18, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 18, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jan 19, 2026
This migrates ksud execution decision-making to bprm_check_security.
This requires passing proper argv and envp to a modified _ksud handler
aptly named 'ksu_handle_bprm_ksud'.

Introduces:
int ksu_handle_bprm_ksud(const char *filename, const char *argv1,
	const char *envp, size_t envp_len)

which is adapted from:
int ksu_handle_execveat_ksud(int *fd,
	struct filename **filename_ptr, struct user_arg_ptr *argv,
	struct user_arg_ptr *envp, int *flags)

ksu_handle_bprm_ksud handles all the decision making, it decides when it is
time to apply_kernelsu_rules depending if it sees "second_stage".

For LSM hook, turns out we can pull out argv and envp from mm_struct.
The code in here explains itself on how to do it.

whole blob exists on arg_start to arg_end, so we just pull it out and grab next
array after the first null terminator.

as for envp, we pass the pointer then hunt for it when needed

This now provides a small helper function, ksu_copy_from_user_retry, which explains
itself. First we attempt a _nofault copy, if that fails, we try plain.

With that, It also provides an inlined copy_from_user_nofault for < 5.8.

While using strncpy_from_user_nofault was considered, this wont do, this will
only copy up to the first \0.

EDIT: properly move selinux init rules to this commit, its this thing that actually needs it
- ref: f8244dd
- removed on: tiann#3031

devlog:
ximi-libra-test/android_kernel_xiaomi_libra@16e5dce...16c1f5f
ximi-mojito-test/mojito_krenol@28642e6...728de0c
ac73056 *

Stale: tiann#2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants