Commit Graph

259 Commits

Author SHA1 Message Date
F-19-F
9034358385 kernel: provide is_ksu_transition check
context: this is known by many as `selinux hook`, `4.9 hook`

add is_ksu_transition check which allows ksud execution under nosuid.
it also eases up integration on 3.X kernels that does not have check_nnp_nosuid.

this also adds a `ksu_execveat_hook` check since this transition is NOT needed
anymore once ksud ran.

Usage:
	if (check_ksu_transition(old_tsec, new_tsec))
		return 0;

on either check_nnp_nosuid or selinux_bprm_set_creds (after execve sid reset)

reference: dfe003c9fd

taken from:
`allow init exec ksud under nosuid`
- 3df9df42a6
- https://github.com/tiann/KernelSU/pull/166#issue-1565872173

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-12 15:24:27 +08:00
rsuntk
467bbeb74e kernel: Remove more stray backslash in grep regex and move path_umount as optional backport 2025-06-12 15:22:30 +08:00
Tashfin Shakeer Rhythm
8996cb9f4a kernel: Makefile: Remove stray backslash from path_umount grep regex (#103)
Signed-off-by: Tashfin Shakeer Rhythm <tashfinshakeerrhythm@gmail.com>
2025-06-12 15:19:57 +08:00
YC酱luyancib
56bfe55c3d Drop auto backport path_umount (#124)
Since https://github.com/backslashxx/KernelSU/commit/4f8943a and https://github.com/rsuntk/KernelSU/commit/0eab5ae , so auto backport `path_umount` is no longer needed.
2025-06-01 00:55:22 +08:00
ShirkNeko
b14a6edb15 kernel: remove SELinux Makefile and add manager to .gitignore 2025-05-28 14:16:53 +08:00
ShirkNeko
788e4c2f2f kernel: refactor umount functions for improved logging and clarity
Co-authored-by: rsuntk <rsuntk@yukiprjkt.my.id>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-05-27 15:21:42 +08:00
rsuntk
61e3a9bcf2 kernel: fix ksu_sys_umount compatibility
* Some people reports about undefined reference to `sys_umount`
* Since ksys_umount exist on Linux 4.17-rc1, then we gonna use that one.

Rev 2: Use correct int instead of long for ksys_umount

Signed-off-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-05-27 01:13:54 +08:00
rsuntk
1ce706823e kernel: guard nuke_ext4_sysfs
Rather than using depends on / select,
i just prefer this way, although, yes, it is
an ifdef hell.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-05-24 15:03:24 +08:00
rsuntk
84a0ab78fb kernel: make path_umount backporting as optional
Since https://github.com/backslashxx/KernelSU/commit/4f8943a, path_umount is no longer needed.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-05-24 15:02:40 +08:00
backslashxx
cd32ee21be kernel: core_hook: screw path_umount backport, call sys_umount directly
I am repasting here what I posted on the source code originally:

/*
 * turns out path_umount backport is completely unneeded
 * we copy the trick used on strncpy_from_unsafe_user / strncpy_from_user_nofault
 * https://elixir.bootlin.com/linux/v4.4.302/source/mm/maccess.c#L184
 * basically
 *
 *     mm_segment_t old_fs = get_fs();     // remember original fs segment
 *     set_fs(USER_DS);                    // or KERNEL_DS *
 *     do_whatever_in_userspace();
 *     set_fs(old_fs);                     // restore fs segment
 *
 *  * kernel -> user, KERNEL_DS, user -> kernel, USER_DS
 *
 * so yes, we can try to straight up call a syscall from kernel space
 *
 * NOTE: on newer kernels you can use force_uaccess_begin + force_uaccess_end
 * ref: https://elixir.bootlin.com/linux/v5.10.237/source/mm/maccess.c#L250
 *
 */

path_umount backport now optional — neat trick, werks, what can I say.

Backports? Nah, we’re good.

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-05-24 14:43:07 +08:00
backslashxx
5aed2c2d2d kernel: sucompat: increase reliability of execve_sucompat
On plain ARMv8.0 devices (A53,A57,A73), strncpy_from_user_nofault() sometimes
fails to copy `filename_user` string correctly. This breaks su ofc, breaking
some apps like Termux (Play Store ver), ZArchiver and Root Explorer.

This does NOT seem to affect newer ARMv8.2+ CPUs (A75/A76 and newer)

My speculation? ARMv8.0 has weak speculation :)

here we replace `strncpy_from_user_nofault()` with another routine:
 - access_ok() to validate the pointer
 - strncpy_from_user() to copy and validate string
 - manual null-termination just in case, as strncpy_from_user_nofault also does it
 - remove that memset, seems useless as it is an strncpy, not strncat

Kind of mimicking _nofault, but yes with this one we allow pagefaults.

Tested on:
- ARMv8.0 A73.a53, A57.a53, A53.a53
- ARMv8.2 A76.a55

Tested-by: iDead XD <rafifirdaus12bb@gmail.com>
Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-05-24 14:37:51 +08:00
ShirkNeko
bbb072b776 Refactoring KPM support to check KPM status using CMD_ENABLE_KPM 2025-05-24 14:36:41 +08:00
ShirkNeko
fe305e4219 Fix the clone address of the KernelSU repository in setup.sh 2025-05-20 12:53:31 +08:00
YC酱luyancib
6ee558d52a kernel:fix missing auto backport can_mount #85 2025-05-18 18:39:20 +08:00
ShirkNeko
1d1a404fa1 Updating the KPM configuration
- We don't know if KPM can run on arm32-bit devices, so to avoid some problems, add a dependency on 64-bit architectures

Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-05-17 18:36:42 +08:00
ShirkNeko
95c47b8602 Fixed misspelling of CONFIG_KSU_HOOK_KPROBES to CONFIG_KSU_KPROBES_HOOK in Makefile and related files. 2025-05-17 18:33:29 +08:00
ShirkNeko
a5d6978b32 kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
This is done like how vfs_read_hook, input_hook and execve_hook is disabled.
While this is not exactly the same thing, this CAN achieve the same results.
The complete disabling of all KernelSU hooks.

While this is likely unneeded, It keeps feature parity to non-kprobe builds.

adapted from upstream:
	kernel: Allow to re-enable sucompat - tiann/KernelSU@4593ae8

Rejected: tiann/KernelSU#2506

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-05-17 18:30:19 +08:00
ShirkNeko
fb94ea9dfd 修正Makefile中关于CONFIG_KSU_HOOK_KPROBES的拼写错误 2025-05-16 23:48:37 +08:00
由崎黑板
8db72cc414 修正Makefile中关于CONFIG_KSU_HOOK_KPROBES的错误 #78 2025-05-16 23:45:12 +08:00
ShirkNeko
986a706f25 Remove checks on atomic functions to simplify the Makefile 2025-05-16 11:32:44 +08:00
sidex15
ba71b410db kernel: kpm: add compatibility for kernel 4.14 and lower (#76)
`thread_pid` is not defined in kernel 4.14 and lower, leading to compilation issue.
To fix this, use `pids[PIDTYPE_PID].pid` for kernel versions 4.14 and lower.
Else use `thread_pid` for kernel versions 4.19 and higher.

Reference: 107717913b/tracee/tracee.bpf.c (L354)
2025-05-15 23:05:03 +08:00
ShirkNeko
049865daea Remove duplicate get_cred_rcu backport 2025-05-15 21:26:12 +08:00
backslashxx
e3b6f4d35d kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
kernel/selinux: fix pointer mismatch with 32-bit ksud on 64-bit kernels
Since KernelSU Manager can now be built for 32-bit, theres this problematic
setup where userspace is 32-bit (armeabi-v7a) and kernel is 64bit (aarch64).

On 64-bit kernels with CONFIG_COMPAT=y, 32-bit userspace passes 32-bit pointers.
These values are interpreted as 64-bit pointers without proper casting and that
results in invalid or near-null memory access.

This patch adds proper compat-mode handling with the ff changes:
- introduce a dedicated struct (`sepol_compat_data`) using u32 fields
- use `compat_ptr()` to safely convert 32-bit user pointers to kernel pointers
- adding a runtime `ksu_is_compat` flag to dynamically select between struct layouts

This prevents a near-null pointer dereference when handling SELinux
policy updates from 32-bit ksud in a 64-bit kernel.

Truth table:

kernel 32 + ksud 32, struct is u32, no compat_ptr
kernel 64 + ksud 32, struct is u32, yes compat_ptr
kernel 64 + ksud 64, struct is u64, no compat_ptr

Preprocessor check

64BIT=y COMPAT=y: define both structs, select dynamically
64BIT=y COMPAT=n: struct u64
64BIT=n: struct u32

kernel/throne_tracker: we just uninstalled the manager, stop looking for it
When the manager UID disappears from packages.list, we correctly
invalidate it — good. But, in the very next breath, we start scanning
/data/app hoping to find it again?

This event is just unnecessary I/O, exactly when we should be doing less.
Apparently this causes hangups and stuckups which is REALLY noticeable
on Ultra-Legacy devices.

Skip the scan — we’ll catch the reinstall next time packages.list updates.

This is done like how vfs_read_hook, input_hook and execve_hook is disabled.
While this is not exactly the same thing, this CAN achieve the same results.
The complete disabling of all KernelSU hooks.

While this is likely unneeded, It keeps feature parity to non-kprobe builds.

adapted from upstream:
	kernel: Allow to re-enable sucompat - 4593ae81c7

Rejected: https://github.com/tiann/KernelSU/pull/2506

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-05-15 20:23:18 +08:00
ShirkNeko
682fdf0afe Prioritize sukisu recognition.
Simplified manual hooks
2025-05-10 14:38:45 +08:00
ShirkNeko
d77ee31bce Add support for KERNEL_VERSION_4_10 in super_access.c and move variable declarations in for loops outside the loop to improve code readability 2025-04-25 19:12:53 +08:00
ShirkNeko
41b8f854a4 Add KSU_CMDLINE configuration to enable the KernelSU command line option and implement the corresponding status read function
Co-authored-by: rsuntk <rsuntk@yukiprjkt.my.id>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-04-24 15:03:09 +08:00
ShirkNeko
069a671bf1 Remove unnecessary conditional compilation code to simplify the definition of kprobe structures 2025-04-23 17:26:00 +08:00
ShirkNeko
13c5aae85e Move variable declarations in the for loop outside the loop in sucompat.c 2025-04-23 17:16:10 +08:00
ShirkNeko
d9063377af Rearrange KSU related conditional compilation support in core_hook.c to improve code readability 2025-04-23 15:35:19 +08:00
ShirkNeko
527d362b85 Add support for Kprobe, extend su_kps array to 6 elements to accommodate more hook functions 2025-04-23 15:08:05 +08:00
ShirkNeko
dfaada7134 Patch update SuSFS version to 1.5.6 2025-04-22 16:20:41 +08:00
ShirkNeko
2c65af9e80 Add a dependency for KPM in Kconfig to ensure that KPM functionality can only be activated when KSU is enabled 2025-04-21 10:42:52 +08:00
ShirkNeko
f0a14e54e6 在core_hook.c中添加对KPM的条件编译支持 2025-04-21 10:31:50 +08:00
ShirkNeko
970e7651a5 Refactoring Kconfig and Makefile to optimize KernelSU configuration logic and simplify kernel type determination 2025-04-19 16:02:18 +08:00
ShirkNeko
1a563bb3e1 Update Makefile to add support for kernel version 6 and optimize KERNEL_TYPE judgment logic. 2025-04-19 14:44:49 +08:00
ShirkNeko
bd56bcf538 Refactoring Kconfig to optimize KernelSU-related configuration and simplify conditional dependency logic 2025-04-19 14:02:12 +08:00
ShirkNeko
6c2e67cd50 更新Makefile,添加内核类型判断逻辑并输出相关信息 2025-04-17 20:07:02 +08:00
ShirkNeko
be8d6ca052 重构Makefile中的KPROBES钩子逻辑,简化条件编译信息输出 2025-04-17 19:53:21 +08:00
ShirkNeko
b72ab79e06 简化Makefile中的内核版本判断逻辑,移除冗余的条件编译代码 2025-04-17 19:52:50 +08:00
ShirkNeko
28f006ed39 Refactor Kconfig and Makefile, update KPROBES related configurations, simplify conditional compilation logic 2025-04-17 19:46:14 +08:00
ShirkNeko
140ebd196f Add support for kernel version 6.12, update conditional compilation definitions in super_access.c 2025-04-15 16:13:16 +08:00
ShirkNeko
8ada7757ea Update Makefile 2025-04-15 15:14:20 +08:00
liankong
b7b739824e 添加super_access对task_struct的支持 2025-04-13 14:23:53 +08:00
ShirkNeko
e2f89709d1 Remove macro definitions in super_access.c for kernel version 4.14 to simplify structural definitions 2025-04-12 19:31:39 +08:00
ShirkNeko
546929da55 Remove conditional compilation for kernel version 4.14 in super_access.c to simplify kprobe structure definition 2025-04-12 19:30:55 +08:00
ShirkNeko
97aaea7d86 Remove macro definitions for kernel versions 5.0 and 5.10 in super_access.c, and adjust conditional compilation to support kernel versions 4.14 and 5.15. 2025-04-12 19:07:33 +08:00
ShirkNeko
2cbe1b9e9a Update kernel version macro definitions to add support for kernel version 5.0 and adjust conditional compilation for newer versions 2025-04-12 19:02:52 +08:00
ShirkNeko
51a0357f0f 在 super_access.c 中添加对内核版本 6.6 和 5.15 的宏定义,并调整条件编译以适应新的内核版本 2025-04-12 16:23:27 +08:00
ShirkNeko
44d85cfdd7 在 super_access.c 中添加对内核版本 4.14 的宏定义,并根据内核版本条件编译相关成员 2025-04-12 16:16:06 +08:00
ShirkNeko
662d5494b2 更新内核版本宏定义为 6.1,并相应调整条件编译的成员定义 2025-04-12 16:12:28 +08:00