Commit Graph

2415 Commits

Author SHA1 Message Date
ShirkNeko
2f2d6aeecf kernel: bump KPM version
Co-authored-by: AlexLiuDev233 <wzylin11@outlook.com>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-11-08 18:33:36 +08:00
ShirkNeko
f6657fdbfd clean 2025-11-08 12:54:13 +08:00
Azyr Ruthless
5782afe481 kernel: add __poll_t compat for pre-4.16 and backported kernels (#194)
__poll_t was introduced in v4.16-rc1. Add Makefile header check to detect and provide fallback for older kernels and those with backports.

Signed-off-by: AzyrRuthless <azyrruthless@tutamail.com>
2025-11-08 12:11:35 +08:00
Faris
2ab373d146 kernel: Clean up mess
Signed-off-by: Faris <rissu.ntk@gmail.com>
2025-11-08 12:11:29 +08:00
Faris
eba286ef7e kernel: fix redeclared __poll_t
* Probably useful in Ultra-Legacy kernel.

Signed-off-by: Faris <rissu.ntk@gmail.com>
2025-11-08 12:10:54 +08:00
ShirkNeko
2a89159a3d fix build 2025-11-08 12:10:12 +08:00
Faris
29c6e2dbcc kernel, ksud: clean headers and add fd wrapper for devpts (#193)
* Now Official KernelSU devpts compat is questionable
Squashed commits:
4893fad235
e7c3d4a6a6
4bb2dae3f5

Signed-off-by: Faris <rissu.ntk@gmail.com>
Co-authored-by: 5ec1cff <56485584+5ec1cff@users.noreply.github.com>
Co-authored-by: weishu <twsxtd@gmail.com>
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-11-08 12:08:54 +08:00
Faris
968c3f7d57 kernel: sepolicy: fix incompatible pointer type
Signed-off-by: Faris <rissu.ntk@gmail.com>
2025-11-08 11:54:22 +08:00
Faris
a8cdd014dc kernel: fix wrong non-kprobe sucompat handler
* Oops, i should read the code correctly..

Signed-off-by: Faris <rissu.ntk@gmail.com>
2025-11-08 11:54:05 +08:00
Faris
4d7dd32b11 kernel: selinux: Use switch-case instead of if-else
Signed-off-by: Faris <rissu.ntk@gmail.com>
2025-11-08 11:51:45 +08:00
Fanuel Berhanu
97b57de3d0 Update sucompat.c (#535) 2025-11-08 01:42:43 +08:00
ShirkNeko
c53cb0afb1 fix 2025-11-08 01:22:31 +08:00
Ylarod
699852009c ksud, kernel: fix sepolicy patch hint (#2872) 2025-11-07 17:30:08 +08:00
ShirkNeko
a8302120c4 fix 2025-11-07 17:28:13 +08:00
ShirkNeko
8d535fa03a kernel: Resolve compilation errors 2025-11-06 04:07:43 +08:00
ShirkNeko
2b97c77a6d Use a more appropriate minor version number 2025-11-06 03:56:52 +08:00
ShirkNeko
68f3be2cbe kernel, ksud, manager: New supercalls implementations
* This commit squashes new supercall impl:
3138651a38..562a3b9be7

Thanks to these people below:

Official KernelSU:
Co-authored-by: Wang Han <416810799@qq.com>
Co-authored-by: weishu <twsxtd@gmail.com>
Co-authored-by: Ylarod <me@ylarod.cn>
Co-authored-by: YuKongA <70465933+YuKongA@users.noreply.github.com>

xxKSU maintainer:
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
MMRL maintainer:
Co-authored-by: Der_Googler <54764558+dergoogler@users.noreply.github.com>
KSUN maintainer:
Co-authored-by: Rifat Azad <33044977+rifsxd@users.noreply.github.com>
KOWSU maintainer:
Co-authored-by: KOWX712 <leecc0503@gmail.com>
2025-11-06 03:54:44 +08:00
ShirkNeko
c55a918957 Kernel(Makefile): Add KSU_SRC to set path correctly #483
try Fix version define for 6.12 Kernel

Co-authored-by: YC酱luyancib <luyancib@qq.com>
2025-10-21 16:38:59 +08:00
Sultan Alsawaf
3cdb8fd057 kernel: Fix kernel panics caused by thread info flag corruption
Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
2025-10-21 16:38:53 +08:00
ShirkNeko
2fdb933acc Kernel: Add support for 6.12
Filtered from tiann/KernelSU #2793

Co-authored-by: libingxuan <84086386+aaaaaaaa-815@users.noreply.github.com>
2025-10-08 15:00:44 +08:00
ShirkNeko
cd05d49a7a kernel: Simplified Logic 2025-10-08 14:37:25 +08:00
unknow-tech
bcb38274f9 Add support for 6.13 (#454)
Fiz issue https://github.com/SukiSU-Ultra/SukiSU-Ultra/issues/364

cdd30ebb1b
2025-10-08 14:34:59 +08:00
backslashxx
1f468f35f4 kernel: align prctl harden commit from backslashxx/KernelSU
SQUASHED:
* kernel: harden barriers for arm/arm64
* kernel: core_hook: harden prctl handler

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-07 16:50:37 +08:00
rsuntk
1d4d23d2c9 kernel: add guard for avoiding LKM being builded on Linux 6.8+
* Due to numerous changes on LSM (Linux Security Module) in Linux 6.8+
* This is temporary guard until a working solution exist.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-07 16:50:01 +08:00
rsuntk
994999c8ce kernel: refine prctl harden
* I am not sure if this gonna defeats the main purpose or not,
but it fix prctl issue.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-07 16:49:52 +08:00
Faris
f05b20dbce [skip ci] kernel: restore original from_root logic 2025-10-07 16:48:56 +08:00
backslashxx
6af2da13ae kernel: migrate barriers to spec barriers and code style thing
overkill, but yeah, might as well move on to the real deal.

[ rsuntk: Rename original variable name ]
Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-07 16:48:38 +08:00
Huy Minh
fd8e3c35bb kernel: add initial 6.8+/6.14 kernel support
* This is a squashed of un-merged pull requests of Official KernelSU
* LKM support are not available.
* Require this additional patch to avoid kernel panic because of "Too many LSMs registered":
7042991a5c

* Un-merged pull requests of Official KernelSU:
https://github.com/tiann/KernelSU/pull/1785
https://github.com/tiann/KernelSU/pull/2662

* This commit probably not 100% completed.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-07 16:47:46 +08:00
rsuntk
04586ccb96 kernel: make apk_sign_key as a typedef instead
Style preference.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-07 16:47:34 +08:00
backslashxx
b537b957bd kernel: harden prctl check
Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-07 16:46:04 +08:00
rifsxd
c02b42d7de kernel: handle throned UID change if manager is reinstall or changed
drop old UID and throne the new one when the manager is reinstalled or changed

- Add dynamic manager lock

Co-authored-by: rifsxd <rifat.44.azad.rifs@gmail.com>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-10-07 00:06:47 +08:00
Natsume324
3f4293e69a Fixed an error in the SukiSU integration of the Kirin 970 HarmonyOS2 kernel source code:
- Error: In the Kirin 970 HarmonyOS2 kernel source code, integrating SukiSU requires disabling the CONFIG_HKIP_SELINUX_PROT configuration option. Disabling this option will enable the use of flex_array. However, in the add_type and add_typeattribute_raw functions in kernel/selinux/sepolicy.c, if a Huawei HISI device is detected, ebitmap not flex_array is used, causing an error.

- Fix: Added conditional checks to the add_type and add_typeattribute_raw functions in kernel/selinux/sepolicy.c. Because the Kirin 970 EMUI10 kernel source code does not use flex_array, an option defined only in the EMUI10 kernel configuration is added to determine the kernel source code version.
2025-10-02 01:18:57 +08:00
ShirkNeko
8943bab810 kernel: Revert partial changes 2025-09-27 23:02:40 +08:00
ShirkNeko
99898203a3 kernel: fmt ,optimization Log 2025-09-27 21:11:05 +08:00
ShirkNeko
27fba0d48b kernel: Use the prctl command to provide switches for scanning functionality in user space 2025-09-27 19:41:31 +08:00
ShirkNeko
07320d9e11 bump KSU_VERSION_API to 3.2.0 2025-09-24 22:35:59 +08:00
ShirkNeko
90611232ed kernel: Bump tracepoint_hooks to version v1.1
Remove `devpts_hook` and `execveat_hook` from `tracepoint_hooks`
2025-09-24 22:03:22 +08:00
ShirkNeko
868b1e655f Revert "kernel: throne_tracker: offload to kthread tiann #2632"
This reverts commit 86ccca18eb.
2025-09-24 16:26:08 +08:00
backslashxx
f7d055c9e1 pullout envp 2025-09-24 16:22:02 +08:00
backslashxx
c63186cad2 move debug back up 2025-09-24 16:21:52 +08:00
ShirkNeko
86ccca18eb kernel: throne_tracker: offload to kthread tiann #2632
Run throne_tracker() in kthread instead of blocking the caller.
Prevents full lockup during installation and removing the manager.

By default, first run remains synchronous for compatibility purposes
(FDE, FBEv1, FBEv2)

Features:
- looks and waits for manager UID in /data/system/packages.list
- run track_throne() in a kthread after the first synchronous run
- prevent duplicate thread creation with a single-instance check
- spinlock-on-d_lock based polling adressing possible race conditions.

Race conditions adressed
- single instance kthread lock, smp_mb()
- track_throne_function, packages.list, spinlock-on-d_lock based polling
- is_manager_apk, apk, spinlock-on-d_lock based polling

This is a squash of:
https://github.com/tiann/KernelSU/pull/2632

Original skeleton based on:
`kernelsu: move throne_tracker() to kthread`
`kernelsu: check locking before accessing files and dirs during searching manager`
`kernelsu: look for manager UID in /data/system/packages.list, not /data/system/packages.list.tmp`
0b05e927...8783badd

Co-Authored-By: backslashxx <118538522+backslashxx@users.noreply.github.com>
Co-Authored-By: Yaroslav Zviezda <10716792+acroreiser@users.noreply.github.com>
Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-09-24 01:50:49 +08:00
ShirkNeko
23dde3f863 kernel: sys_execve bprm simplified
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-09-23 23:53:48 +08:00
ShirkNeko
4a5119a80c kernel ksud: Attempt registration with bprm_check_kp first. If it fails, fall back to sys_execve_kp.
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-09-23 17:26:24 +08:00
ShirkNeko
f0fec48050 kernel: Add the missing endif 2025-09-23 00:08:00 +08:00
ShirkNeko
b4bdd17e4e kernel: core_hook: intercept devpts via security_inode_permission LSM
`ksu handles devpts with selinux lsm hook` - aviraxp

- no, not yet, but yes we can, thats a good idea.

This change tries to do that, so instead of hooking pts_unix98_lookup or
devpts_get_priv, we just watch security_inode_permission, if its devpts,
pass it along to the original handler.

EDIT: define devpts super magic if its undefined
- yeah I aint gonna include a conditional include of a header just for this
- while we can just fully remove the macro and inline, readability loss is bad

Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-09-22 23:54:51 +08:00
ShirkNeko
de92cc4bad 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

Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-09-22 23:34:19 +08:00
backslashxx
d288b8f24f ksud: migrate ksud execution to security_bprm_check (tiann#2653)
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 6efcd8193e
- old version2 37d5938e66
- 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:
16e5dce9e7...16c1f5f521
28642e60d7...728de0c571

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: https://github.com/tiann/KernelSU/pull/2653

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-09-22 23:21:47 +08:00
ShirkNeko
1b732f62e8 kernel: Added legacy throne tracker support, using packages.list to scan application UIDs 2025-09-21 17:37:43 +08:00
JackAltman
36742cc17e feat: detect proc_ops support via header parsing instead of version check. (#411)
Some kernels (e.g. 5.4 with backports) include proc_ops despite being
older than 5.6.0. Replace hardcoded version check with runtime header
detection to handle these cases.

- Check for "struct proc_ops" in include/linux/proc_fs.h
- Use KSU_COMPAT_HAS_PROC_OPS macro for conditional compilation
- Fixes build failures on kernels with backported proc_ops

Signed-off-by: JackAltman
2025-09-20 13:31:18 +08:00
ShirkNeko
3a61da7f45 Add vfs_getattr compatibility for kernels < 4.14
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-09-20 13:24:29 +08:00