Skip to content

Conversation

@backslashxx
Copy link
Contributor

@backslashxx backslashxx commented Jun 25, 2025

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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that  _nofault copy on a spinlock as a way to mimic preempt_disable/enable
without actually doing it. As per user reports, no failed _nofault copies anyway
but we have-to-have a fallback for resilience.

References:
- old version https://github.com/backslashxx/KernelSU/commit/6efcd8193e62d13a4e62cda0ce54d6770260c680
- bad usercopy https://github.com/backslashxx/KernelSU/issues/21

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.

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

for LKM, we just need sys_execve for the filename. same method works as-is.
using lsm_hook_hack wasnt checked, but compatibility via sys_execve kprobe is kept.

devlog:
https://github.com/ximi-libra-test/android_kernel_xiaomi_libra/compare/16e5dce9e7e...16c1f5f521a
https://github.com/backslashxx/mojito_krenol/compare/28642e60d7b...728de0c571c

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Signed-off-by: backslashxx <[email protected]>

@backslashxx
Copy link
Contributor Author

backslashxx commented Jun 25, 2025

context:
kernel: ksud, core_hook: migrate ksud execution to security_bprm_check

logs on lkm mode (via sys_execve)
ksu_lkm_log.log
from @ukriu

dmesg_6.1.txt from fergus
logs2electricboogaloo.log from @ukriu again
logs for ab23da8

LKM demo
https://github.com/backslashxx/KernelSU/actions/runs/15898080119

LSM / GKI demo prolly unneeded

--

I havent tested lsm hook hack but this can be hooked on different places

5.8+ bprm_creds_for_exec + bprm_creds_from_file?
2.6.29 - 5.7 bprm_set_creds (tested)
2.6.0 - 6.15 bprm_check_security (tested)

however for my purposes, I chose bprm_check_security since

  1. max compatibility
  2. bprm->buf is filled so backslashxx@ca22487

@backslashxx backslashxx changed the title refactor execve/at_ksud handling kernel: ksud, core_hook: migrate ksud execution to security_bprm_check Jun 26, 2025
@backslashxx backslashxx force-pushed the bprm_ksud branch 5 times, most recently from e4b852c to ce728be Compare June 27, 2025 08:13
as per upstream, we only mostly need top 32 bytes and top 256 bytes anyway
since these are good enough allowances, we can allocate this on stack.

Signed-off-by: backslashxx <[email protected]>
@backslashxx backslashxx closed this Jul 2, 2025
@backslashxx backslashxx deleted the bprm_ksud branch July 2, 2025 13:43
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 2, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 6efcd81
- old version2 37d5938
- bad usercopy #21

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.

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

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 2, 2025
Added from 5ec1cff@16e13ae (+24)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	use module dir name as real id
	allow restore uninstalled module
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	ksud: probe for more workdir candidates (5ec1cff#12)
	app: persist show system app settings

Other changes: (+49)
	manager: show module id on module page (tiann#2365)
	workflows: debloat
	ksud: add armeabi-v7a support
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: handle backports
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: core_hook: automate and refactor umount (tiann#2531)
	kernel: core_hook: only umount when unmountable > 0
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: dont create structs just to deconstruct them for a string (tiann#2595)
	kernel: ksud: add commonized execve/compat_execve hooks for ksud
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: opt-out of struct filename use when unused
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: sucompat: dummify devpts hook
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: sucompat: strncpy_from_user -> copy_from_user
	kernel: ksud: reuse bprm_ksud logic on old handlers
	kernel: ksud: deadcode / no-op old hooks
	kernel: core_hook: fixup 32-on-64 compat detection via linux_binprm
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: selinux: rules: Fix illegal RCU lock usage in apply_kernelsu_rules() (tiann#2646)
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for <= 3.18
	kernel: ksud: provide is_ksu_transition check v2
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: throne_tracker: add strscpy/strlcpy compat
	kernel: ksud: d_is_reg to IS_REG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle read_iter requirement conditionally
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: inline iterate_dir -> vfs_readdir compat
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	KernelSU v1.0.5+magic

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 3, 2025
Added from 5ec1cff@16e13ae (+24)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	use module dir name as real id
	allow restore uninstalled module
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	ksud: probe for more workdir candidates (5ec1cff#12)
	app: persist show system app settings

Other changes: (+49)
	manager: show module id on module page (tiann#2365)
	workflows: debloat
	ksud: add armeabi-v7a support
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: handle backports
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: core_hook: automate and refactor umount (tiann#2531)
	kernel: core_hook: only umount when unmountable > 0
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: dont create structs just to deconstruct them for a string (tiann#2595)
	kernel: ksud: add commonized execve/compat_execve hooks for ksud
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: opt-out of struct filename use when unused
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: sucompat: dummify devpts hook
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: sucompat: strncpy_from_user -> copy_from_user
	kernel: ksud: reuse bprm_ksud logic on old handlers
	kernel: ksud: deadcode / no-op old hooks
	kernel: core_hook: fixup 32-on-64 compat detection via linux_binprm
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: selinux: rules: Fix illegal RCU lock usage in apply_kernelsu_rules() (tiann#2646)
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for <= 3.18
	kernel: ksud: provide is_ksu_transition check v2
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: throne_tracker: add strscpy/strlcpy compat
	kernel: ksud: d_is_reg to IS_REG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle read_iter requirement conditionally
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: inline iterate_dir -> vfs_readdir compat
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	KernelSU v1.0.5+magic

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 3, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 6efcd81
- old version2 37d5938
- bad usercopy #21

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.

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

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 3, 2025
Added from 5ec1cff@16e13ae (+24)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	use module dir name as real id
	allow restore uninstalled module
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	ksud: probe for more workdir candidates (5ec1cff#12)
	app: persist show system app settings

Other changes: (+49)
	manager: show module id on module page (tiann#2365)
	workflows: debloat
	ksud: add armeabi-v7a support
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: handle backports
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: core_hook: automate and refactor umount (tiann#2531)
	kernel: core_hook: only umount when unmountable > 0
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: dont create structs just to deconstruct them for a string (tiann#2595)
	kernel: ksud: add commonized execve/compat_execve hooks for ksud
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: opt-out of struct filename use when unused
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: sucompat: dummify devpts hook
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: sucompat: strncpy_from_user -> copy_from_user
	kernel: ksud: reuse bprm_ksud logic on old handlers
	kernel: ksud: deadcode / no-op old hooks
	kernel: core_hook: fixup 32-on-64 compat detection via linux_binprm
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: selinux: rules: Fix illegal RCU lock usage in apply_kernelsu_rules() (tiann#2646)
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for <= 3.18
	kernel: ksud: provide is_ksu_transition check v2
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: throne_tracker: add strscpy/strlcpy compat
	kernel: ksud: d_is_reg to IS_REG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle read_iter requirement conditionally
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: inline iterate_dir -> vfs_readdir compat
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	KernelSU v1.0.5+magic

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
pershoot added a commit to pershoot/KernelSU-Next that referenced this pull request Jul 3, 2025
-v1.5
__backslashxx/KernelSU#5
____kernel_compat: remove cond. check against ksu_access_ok in ksu_copy_from_user_retry

<><><>

Description addendum:
kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@1e5994d

...

References:
...
- old version2 backslashxx/KernelSU@37d5938
...

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.

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

...

Stale: tiann/KernelSU#2653

Signed-off-by: backslashxx <[email protected]>

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
pershoot added a commit to pershoot/KernelSU-Next that referenced this pull request Jul 3, 2025
-v1.5
__backslashxx/KernelSU#5
____kernel_compat: remove cond. check against ksu_access_ok in ksu_copy_from_user_retry

<><><>

Description addendum:
kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@1e5994d

...

References:
...
- old version2 backslashxx/KernelSU@37d5938
...

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.

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

...

Stale: tiann/KernelSU#2653

Signed-off-by: backslashxx <[email protected]>

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
pershoot added a commit to pershoot/KernelSU-Next that referenced this pull request Jul 4, 2025
-v1.5
__backslashxx/KernelSU#5
____kernel_compat: remove cond. check against ksu_access_ok in ksu_copy_from_user_retry

<><><>

Description addendum:
kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@1e5994d

...

References:
...
- old version2 backslashxx/KernelSU@37d5938
...

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.

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

...

Stale: tiann/KernelSU#2653

Signed-off-by: backslashxx <[email protected]>

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
pershoot added a commit to pershoot/KernelSU-Next that referenced this pull request Jul 4, 2025
-v1.5
__backslashxx/KernelSU#5
____kernel_compat: remove cond. check against ksu_access_ok in ksu_copy_from_user_retry

<><><>

Description addendum:
kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@1e5994d

...

References:
...
- old version2 backslashxx/KernelSU@37d5938
...

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.

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

...

Stale: tiann/KernelSU#2653

Signed-off-by: backslashxx <[email protected]>

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
pershoot added a commit to pershoot/KernelSU-Next that referenced this pull request Jul 4, 2025
-v1.5
__backslashxx/KernelSU#5
____kernel_compat: remove cond. check against ksu_access_ok in ksu_copy_from_user_retry; remove comment

<><><>

Description addendum:
kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@1e5994d

...

References:
...
- old version2 backslashxx/KernelSU@37d5938
...

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.

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

...

Stale: tiann/KernelSU#2653

Signed-off-by: backslashxx <[email protected]>

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 4, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 6efcd81
- old version2 37d5938
- bad usercopy #21

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.

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

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 4, 2025
Added from 5ec1cff@16e13ae (+24)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	use module dir name as real id
	allow restore uninstalled module
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	ksud: probe for more workdir candidates (5ec1cff#12)
	app: persist show system app settings

Other changes: (+49)
	manager: show module id on module page (tiann#2365)
	workflows: debloat
	ksud: add armeabi-v7a support
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: handle backports
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: core_hook: automate and refactor umount (tiann#2531)
	kernel: core_hook: only umount when unmountable > 0
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: dont create structs just to deconstruct them for a string (tiann#2595)
	kernel: ksud: add commonized execve/compat_execve hooks for ksud
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: opt-out of struct filename use when unused
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: sucompat: dummify devpts hook
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: sucompat: strncpy_from_user -> copy_from_user
	kernel: ksud: reuse bprm_ksud logic on old handlers
	kernel: ksud: deadcode / no-op old hooks
	kernel: core_hook: fixup 32-on-64 compat detection via linux_binprm
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: selinux: rules: Fix illegal RCU lock usage in apply_kernelsu_rules() (tiann#2646)
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for <= 3.18
	kernel: ksud: provide is_ksu_transition check v2
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: throne_tracker: add strscpy/strlcpy compat
	kernel: ksud: d_is_reg to IS_REG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle read_iter requirement conditionally
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: inline iterate_dir -> vfs_readdir compat
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	KernelSU v1.0.5+magic

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 4, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 6efcd81
- old version2 37d5938
- bad usercopy #21

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.

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

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Jul 4, 2025
Added from 5ec1cff@16e13ae (+24)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	use module dir name as real id
	allow restore uninstalled module
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	ksud: probe for more workdir candidates (5ec1cff#12)
	app: persist show system app settings

Other changes: (+49)
	manager: show module id on module page (tiann#2365)
	workflows: debloat
	ksud: add armeabi-v7a support
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: handle backports
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: core_hook: automate and refactor umount (tiann#2531)
	kernel: core_hook: only umount when unmountable > 0
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: dont create structs just to deconstruct them for a string (tiann#2595)
	kernel: ksud: add commonized execve/compat_execve hooks for ksud
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: opt-out of struct filename use when unused
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: sucompat: dummify devpts hook
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: sucompat: strncpy_from_user -> copy_from_user
	kernel: ksud: reuse bprm_ksud logic on old handlers
	kernel: ksud: deadcode / no-op old hooks
	kernel: core_hook: fixup 32-on-64 compat detection via linux_binprm
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: selinux: rules: Fix illegal RCU lock usage in apply_kernelsu_rules() (tiann#2646)
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for <= 3.18
	kernel: ksud: provide is_ksu_transition check v2
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: throne_tracker: add strscpy/strlcpy compat
	kernel: ksud: d_is_reg to IS_REG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle read_iter requirement conditionally
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: inline iterate_dir -> vfs_readdir compat
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	KernelSU v1.0.5+magic

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
AzyrRuthless pushed a commit to AzyrRuthless/KernelSU-Next that referenced this pull request Jul 4, 2025
-v1.5
__backslashxx/KernelSU#5
____kernel_compat: remove cond. check against ksu_access_ok in ksu_copy_from_user_retry; remove comment

<><><>

Description addendum:
kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@1e5994d

...

References:
...
- old version2 backslashxx/KernelSU@37d5938
...

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.

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

...

Stale: tiann/KernelSU#2653

Signed-off-by: backslashxx <[email protected]>

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
pershoot added a commit to pershoot/KernelSU-Next that referenced this pull request Oct 19, 2025
-v1.5
__backslashxx/KernelSU#5
____kernel_compat: remove cond. check against ksu_access_ok in ksu_copy_from_user_retry; remove comment

<><><>

Description addendum:
kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@1e5994d

...

References:
...
- old version2 backslashxx/KernelSU@37d5938
...

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.

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

...

Stale: tiann/KernelSU#2653

Signed-off-by: backslashxx <[email protected]>

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
pershoot added a commit to pershoot/KernelSU-Next that referenced this pull request Oct 19, 2025
-v1.5
__backslashxx/KernelSU#5
____sucompat: add is_su_allowed
____sucompat: ksu_sucompat_common -> ksu_sucompat_user_common
____sucompat: amend logic within ksu_handle_execveat_sucompat
____sucompat: move ksu_handle_execve_sucompat before ksu_handle_execveat_sucompat
____sucompat: retain some minute logic / style (ksu_sucompat_non_kp)
____sucompat: identify 'sh' (ksu_handle_execveat_sucompat)
____ksud: update comment

<><><>

Description addendums:
kernel: sucompat: increase reliability, commonize and micro-optimize (tiann/KernelSU#2656)
backslashxx/KernelSU@c4530ac

...

Stale: tiann/KernelSU#2656

<><><>

kernel: ksud: migrate ksud execution to security_bprm_check (tiann/KernelSU#2653)
backslashxx/KernelSU@cd07ae2

...

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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

...

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

...

<><><>

-https://gitlab.com/pershoot/susfs4ksu/-/tree/gki-android14-6.1-dev
0ctobot pushed a commit to 0ctobot/neutrino_kernel_google_caimito that referenced this pull request Oct 19, 2025
tiann/KernelSU#2653

This patch moves ksud execution logic to the bprm_creds_for_exec
LSM hook, enabling earlier and more consistent rule application
during the exec flow.

Introduce ksu_handle_bprm_ksud(), adapted from
ksu_handle_execveat_ksud(), this version takes pre-parsed argv/envp
data and centralizes the decision logic.

arg_start → arg_end: for argv[0] and argv[1]
env_start → env_end: for inline scanning of envp

Signed-off-by: backslashxx <[email protected]>
[@0ctobot: Drop non-relevant legacy init handling and squash the following:
backslashxx/KernelSU@f954df6
backslashxx/KernelSU@008b14a
backslashxx/KernelSU@4ad46be
backslashxx/KernelSU@11fde58]
Signed-off-by: Adam W. Willis <[email protected]>
0ctobot pushed a commit to 0ctobot/neutrino_kernel_google_caimito that referenced this pull request Oct 20, 2025
tiann/KernelSU#2653

This patch moves ksud execution logic to the bprm_creds_for_exec
LSM hook, enabling earlier and more consistent rule application
during the exec flow.

Introduce ksu_handle_bprm_ksud(), adapted from
ksu_handle_execveat_ksud(), this version takes pre-parsed argv/envp
data and centralizes the decision logic.

arg_start → arg_end: for argv[0] and argv[1]
env_start → env_end: for inline scanning of envp

Signed-off-by: backslashxx <[email protected]>
[@0ctobot: Drop non-relevant legacy init handling and squash the following:
backslashxx/KernelSU@f954df6
backslashxx/KernelSU@008b14a
backslashxx/KernelSU@4ad46be
backslashxx/KernelSU@11fde58]
Signed-off-by: Adam W. Willis <[email protected]>
KOWX712 pushed a commit to KOWX712/KernelSU that referenced this pull request Oct 20, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 backslashxx@6efcd81
- old version2 backslashxx@37d5938
- bad usercopy backslashxx#21

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.

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 20, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 6efcd81
- old version2 37d5938
- bad usercopy #21

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.

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 20, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
anzarfarooq pushed a commit to anzarfarooq/KernelSU that referenced this pull request Oct 20, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
anzarfarooq pushed a commit to anzarfarooq/KernelSU that referenced this pull request Oct 20, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 backslashxx@6efcd81
- old version2 backslashxx@37d5938
- bad usercopy backslashxx#21

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.

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
anzarfarooq pushed a commit to anzarfarooq/KernelSU that referenced this pull request Oct 20, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 21, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 21, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 21, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 21, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 22, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 22, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+62)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: intercept devpts via security_inode_permission LSM
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 22, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 6efcd81
- old version2 37d5938
- bad usercopy #21

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.

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 22, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+63)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	ksud/su: import devpts workaround
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: remove devpts workaround
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler >= 5.18
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
KOWX712 pushed a commit to KOWX712/KernelSU that referenced this pull request Oct 22, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 backslashxx@6efcd81
- old version2 backslashxx@37d5938
- bad usercopy backslashxx#21

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.

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 22, 2025
SQUASH:
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: remove devpts workaround
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler >= 5.18
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init

Signed-off-by: backslashxx <[email protected]>
Co-Authored-By: ExtremeXT <[email protected]>
Co-Authored-By: backslashxx <[email protected]>
Co-Authored-By: Yaroslav Zviezda <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 22, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+63)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	ksud/su: import devpts workaround
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: remove devpts workaround
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler >= 5.18
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Oct 22, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 backslashxx@6efcd81
- old version2 backslashxx@37d5938
- bad usercopy tiann#21

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.

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 23, 2025
SQUASH:
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: remove devpts workaround
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler >= 5.18
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init

Signed-off-by: backslashxx <[email protected]>
Co-Authored-By: ExtremeXT <[email protected]>
Co-Authored-By: Yaroslav Zviezda <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 23, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+63)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	ksud/su: import devpts workaround
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: remove devpts workaround
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler >= 5.18
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 23, 2025
SQUASH:
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: remove devpts workaround
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler >= 5.18
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init

Signed-off-by: backslashxx <[email protected]>
Co-Authored-By: ExtremeXT <[email protected]>
Co-Authored-By: Yaroslav Zviezda <[email protected]>
selfmusing pushed a commit to selfmusing/USlenreK that referenced this pull request Oct 23, 2025
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

My reasoning on adding a fallback on usercopy is that on some devices a fault
happens, and it copies garbled data. On my creation of this, I actually had to lock
that _nofault copy on a spinlock as a way to mimic preempt_disable/enable without
actually doing it. As per user reports, no failed _nofault copies anyway but we
have-to-have a fallback for resilience.

References:
- old version1 backslashxx@6efcd81
- old version2 backslashxx@37d5938
- bad usercopy tiann#21

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.

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

References:
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/mm_types.h#L429
https://elixir.bootlin.com/linux/v4.14.1/source/include/linux/lsm_hooks.h

Stale: tiann#2653

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 27, 2025
SQUASH:
	4f0d1750 - kernel: drop LKM and kprobes support
	0a5788d8 - Revert "kernel: transition devpts in kernel"
	6233f255 - kernel: restore compat code required for old kernels
	1c410df6 - kernel: selinux: force sepol_data.sepol to be u64
*	a4538e0e - kernel: expose allowlist workaround as Kconfig option
	812b5756 - kernel: core_hook: screw path_umount backport, call sys_umount directly
	1496ba99 - kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	ebfd6d50 - kernel: core_hook: add wipe umount list cmd
	9c28706c - kernel: core_hook: only umount when unmountable > 0
	9f0b8d1d - kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
*	19574f54 - kernel: throne_tracker: offload to kthread (tiann#2632)
	40f085b2 - kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	6543ab85 - kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	6ce66242 - kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	67ddeb57 - kernel: ksud: provide dummy handlers for old hooks
	3a99b1b8 - kernel: core_hook: earlier escape_to_root already-root check
	4c11e253 - kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	78054261 - kernel: sucompat: provide do_execve_common handler for < 3.14
	dd818818 - kernel: sucompat: provide getname_flags (user) ultimatum hook
	80881890 - kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	ae498de1 - kernel: sucompat: provide vfs_statx hook handler >= 5.18
	66858826 - kernel: core_hook: harden prctl handler
	f252aac0 - kernel: core_hook: add support for KernelNoSU v2
	7f5478f9 - kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	cf78f7f9 - kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	b9365735 - kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	b290b713 - kernel: extras: base implementation of avc log spoofing
	463e6104 - kernel: extras/avc_spoof: add kprobe support
	132fdd60 - kernel: ksud: provide is_ksu_transition check v2
	e12cb810 - kernel: apk_sign: casting to char for strcmp -> memcmp
	887c4de4 - kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	702c5c9d - kernel: core_hook: no ext4_unregister_sysfs, no problem
	9b29d58b - kernel: ksud: d_is_reg to S_ISREG
	1e1b586b - kernel: Makefile: remove overlayfs requirement
	221cf892 - kernel: throne_tracker: resolve s_magic for < 3.9
	2ab1d835 - kernel: ksud: handle conditional read_iter requirement for < 3.16
	16fa9ad5 - kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	e76dfa6b - kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	d61bd2a3 - kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	42ccee00 - kernel: apk_sign: provide bin2hex compat for < 3.18
	208b086f - kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	ade6dfa7 - kernel: apk_sign: fix return check for ksu_sha256
	38f75763 - kernel: handle backports
	5e1e0c64 - kernel: apk_sign: add more size/hash pairs
	4cad7156 - kernel: ksu: printout quirks / backports / etc on init

Co-Authored-By: ExtremeXT <[email protected]>
Co-Authored-By: Yaroslav Zviezda <[email protected]>
Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 27, 2025
Added from https://github.com/5ec1cff/KernelSU (+22)
	implement magic mount
	restorecon: set adb_file to system_file for module files
	magic_mount: use trusted.overlay.opaque
	chore: fmt
	magic_mount: supports whiteout
	chore: refine code
	magic_mount: fix
	log: make verbose logging optional
	magic_mount: refine
	ksud: fix disable / enable modules
	ksud: fix odm not magic-mounted
	manager: no need to check overlayfs
	ksud: fix partition link
	ksud: fix clone symlink
	ksud: refine tmpfs
	ksud: add KSU_MAGIC_MOUNT to env (5ec1cff#5)
	manager: remove shrink image
	ksud: make tmpfs and magic mount optional
	ksud: fix stat
	reformat rust codes
	app: persist show system app settings
	magic mount: make mount points read only

Other changes: (+63)
	ksud: move workdir to /mnt/vendor
	ksud: remove tmpfs mounting
	ksud: tell prctl interface about our mounts (5ec1cff#16)
	ksud: add cmd for add-try-umount (5ec1cff#16)
	ksud: add wipe umount list cmd
	ksud: add cmd for nuke-ext4-sysfs
	workflows: debloat
	workflows: debloat pt. 2
	ksud: add armeabi-v7a support
	manager:  failure mode dummy demo
	dummy.keystore
	manager: unofficial build
	manager: Add ABI and Kernel archirecture info into InfoCardItem
	ksud/su: import devpts workaround
	Reapply: "Handle unmount for isolated process correctly (tiann#2696)"
	kernel: drop LKM and kprobes support
	kernel: restore compat code required for old kernels
	kernel: expose allowlist workaround as Kconfig option
	kernel: core_hook: screw path_umount backport, call sys_umount directly
	kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	kernel: core_hook: add wipe umount list cmd
	kernel: core_hook: only umount when unmountable > 0
	kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
	kernel: throne_tracker: offload to kthread (tiann#2632)
	kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	kernel: core_hook: remove devpts workaround
	kernel: compat: migrate sucompat strncpy_from_user to copy_from_user
	kernel: selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
	kernel: ksud: provide dummy handlers for old hooks
	kernel: core_hook: earlier escape_to_root already-root check
	kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	kernel: sucompat: provide do_execve_common handler for < 3.14
	kernel: sucompat: provide getname_flags (user) ultimatum hook
	kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	kernel: sucompat: provide vfs_statx hook handler >= 5.18
	kernel: core_hook: harden prctl handler
	kernel: harden barriers for arm/arm64
	kernel: core_hook: add support for KernelNoSU v2
	kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	kernel: extras: base implementation of avc log spoofing
	kernel: extras/avc_spoof: add kprobe support
	kernel: ksud: provide is_ksu_transition check v2
	kernel: apk_sign: casting to char for strcmp -> memcmp
	kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	kernel: core_hook: no ext4_unregister_sysfs, no problem
	kernel: ksud: d_is_reg to S_ISREG
	kernel: Makefile: remove overlayfs requirement
	kernel: throne_tracker: resolve s_magic for < 3.9
	kernel: ksud: handle conditional read_iter requirement for < 3.16
	kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	kernel: apk_sign: provide bin2hex compat for < 3.18
	kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	kernel: apk_sign: fix return check for ksu_sha256
	kernel: handle backports
	kernel: apk_sign: add more size/hash pairs
	kernel: ksu: printout quirks / backports / etc on init
	KernelSU v1.0.5+

Warning: Managers built from this repo has a known keystore.
See dummy.keystore.

Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 27, 2025
SQUASH:
	4f0d1750 - kernel: drop LKM and kprobes support
	0a5788d8 - Revert "kernel: transition devpts in kernel"
	6233f255 - kernel: restore compat code required for old kernels
	1c410df6 - kernel: selinux: force sepol_data.sepol to be u64
*	a4538e0e - kernel: expose allowlist workaround as Kconfig option
	812b5756 - kernel: core_hook: screw path_umount backport, call sys_umount directly
	1496ba99 - kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	ebfd6d50 - kernel: core_hook: add wipe umount list cmd
	9c28706c - kernel: core_hook: only umount when unmountable > 0
	9f0b8d1d - kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
*	19574f54 - kernel: throne_tracker: offload to kthread (tiann#2632)
	40f085b2 - kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	6543ab85 - kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	6ce66242 - kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	67ddeb57 - kernel: ksud: provide dummy handlers for old hooks
	3a99b1b8 - kernel: core_hook: earlier escape_to_root already-root check
	4c11e253 - kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	78054261 - kernel: sucompat: provide do_execve_common handler for < 3.14
	dd818818 - kernel: sucompat: provide getname_flags (user) ultimatum hook
	80881890 - kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	ae498de1 - kernel: sucompat: provide vfs_statx hook handler >= 5.18
	66858826 - kernel: core_hook: harden prctl handler
	f252aac0 - kernel: core_hook: add support for KernelNoSU v2
	7f5478f9 - kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	cf78f7f9 - kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	b9365735 - kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	b290b713 - kernel: extras: base implementation of avc log spoofing
	463e6104 - kernel: extras/avc_spoof: add kprobe support
	132fdd60 - kernel: ksud: provide is_ksu_transition check v2
	e12cb810 - kernel: apk_sign: casting to char for strcmp -> memcmp
	887c4de4 - kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	702c5c9d - kernel: core_hook: no ext4_unregister_sysfs, no problem
	9b29d58b - kernel: ksud: d_is_reg to S_ISREG
	1e1b586b - kernel: Makefile: remove overlayfs requirement
	221cf892 - kernel: throne_tracker: resolve s_magic for < 3.9
	2ab1d835 - kernel: ksud: handle conditional read_iter requirement for < 3.16
	16fa9ad5 - kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	e76dfa6b - kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	d61bd2a3 - kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	42ccee00 - kernel: apk_sign: provide bin2hex compat for < 3.18
	208b086f - kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	ade6dfa7 - kernel: apk_sign: fix return check for ksu_sha256
	38f75763 - kernel: handle backports
	5e1e0c64 - kernel: apk_sign: add more size/hash pairs
	c9364cf2 - kernel: ksu: printout quirks / backports / etc on init

Co-Authored-By: ExtremeXT <[email protected]>
Co-Authored-By: Yaroslav Zviezda <[email protected]>
Signed-off-by: backslashxx <[email protected]>
backslashxx added a commit to backslashxx/KernelSU that referenced this pull request Oct 27, 2025
SQUASH:
	4f0d1750 - kernel: drop LKM and kprobes support
	0a5788d8 - Revert "kernel: transition devpts in kernel"
	6233f255 - kernel: restore compat code required for old kernels
	1c410df6 - kernel: selinux: force sepol_data.sepol to be u64
*	a4538e0e - kernel: expose allowlist workaround as Kconfig option
	812b5756 - kernel: core_hook: screw path_umount backport, call sys_umount directly
	1496ba99 - kernel: core_hook: expose prctl interface for umount list (5ec1cff#16)
	ebfd6d50 - kernel: core_hook: add wipe umount list cmd
	9c28706c - kernel: core_hook: only umount when unmountable > 0
	9f0b8d1d - kernel: core_hook: expose nuke_ext4_sysfs to prctl interface
*	19574f54 - kernel: throne_tracker: offload to kthread (tiann#2632)
	40f085b2 - kernel: ksud: migrate ksud execution to security_bprm_check (tiann#2653)
	6543ab85 - kernel: sucompat: increase reliability, commonize and micro-optimize (tiann#2656)
	6ce66242 - kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
	67ddeb57 - kernel: ksud: provide dummy handlers for old hooks
	3a99b1b8 - kernel: core_hook: earlier escape_to_root already-root check
	4c11e253 - kernel: expose KSU_LSM_SECURITY_HOOKS on Kconfig
	78054261 - kernel: sucompat: provide do_execve_common handler for < 3.14
	dd818818 - kernel: sucompat: provide getname_flags (user) ultimatum hook
	80881890 - kernel: sucompat: provide getname_flags (kernel) ultimatum hook
	ae498de1 - kernel: sucompat: provide vfs_statx hook handler >= 5.18
	66858826 - kernel: core_hook: harden prctl handler
	f252aac0 - kernel: core_hook: add support for KernelNoSU v2
	7f5478f9 - kernel: kp_ksud: restore kprobes for early-boot and used-once hooks
	cf78f7f9 - kernel: kp_ksud: add security_bounded_transition hook for < 4.14 (tiann#1704)
	b9365735 - kernel: rp_sucompat: add kretprobes-hooked getname_flags for sucompat
	b290b713 - kernel: extras: base implementation of avc log spoofing
	463e6104 - kernel: extras/avc_spoof: add kprobe support
	132fdd60 - kernel: ksud: provide is_ksu_transition check v2
	e12cb810 - kernel: apk_sign: casting to char for strcmp -> memcmp
	887c4de4 - kernel: apk_sign: migrate generic_file_llseek -> vfs_llseek
	702c5c9d - kernel: core_hook: no ext4_unregister_sysfs, no problem
	9b29d58b - kernel: ksud: d_is_reg to S_ISREG
	1e1b586b - kernel: Makefile: remove overlayfs requirement
	221cf892 - kernel: throne_tracker: resolve s_magic for < 3.9
	2ab1d835 - kernel: ksud: handle conditional read_iter requirement for < 3.16
	16fa9ad5 - kernel: throne_tracker: handle filldir_t ABI mismatch on <= 3.18
	e76dfa6b - kernel: compat: iterate_dir -> vfs_readdir compat for < 3.11
	d61bd2a3 - kernel: sucompat: bruteforce writeable stack from start_stack for < 3.8
	42ccee00 - kernel: apk_sign: provide bin2hex compat for < 3.18
	208b086f - kernel: throne_tracker: add strscpy pseudo-compat for < 4.3
	ade6dfa7 - kernel: apk_sign: fix return check for ksu_sha256
	38f75763 - kernel: handle backports
	5e1e0c64 - kernel: apk_sign: add more size/hash pairs
	c9364cf2 - kernel: ksu: printout quirks / backports / etc on init

Signed-off-by: backslashxx <[email protected]>
Co-Authored-By: ExtremeXT <[email protected]>
Co-Authored-By: Yaroslav Zviezda <[email protected]>
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.

1 participant