Commit Graph

675 Commits

Author SHA1 Message Date
Ylarod
61f85a029e ksud, kernel: Pick some upstream changes and remove unused functions
* Upstream commit:
f130f7572f

Signed-off-by: Faris <rsuntk@yukiprjkt.my.id>
2025-10-19 18:41:30 +08:00
ShirkNeko
9c1ff635e3 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:04 +08:00
rsuntk
ef97f0e4d9 kernel: make apk_sign_key as a typedef instead
Style preference.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-10-08 14:50:50 +08:00
ShirkNeko
2e394903cc kernel: Simplified Logic 2025-10-08 14:46:58 +08:00
unknow-tech
7978cbafa5 Add support for 6.13 (#454)
Fiz issue https://github.com/SukiSU-Ultra/SukiSU-Ultra/issues/364

cdd30ebb1b
2025-10-08 14:46:50 +08:00
rsuntk
c89a3dbcd9 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-08 14:46:00 +08:00
Huy Minh
13c7912320 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-08 14:45:36 +08:00
saitama-droid
abbe385382 kernel: core_hook: add config guard for manual SU escalation (#453)
Wrap manual SU escalation handling in CONFIG_KSU_MANUAL_SU
conditional compilation to allow builds without this functionality.

This affects:
- CMD_SU_ESCALATION_REQUEST
- CMD_ADD_PENDING_ROOT

When CONFIG_KSU_MANUAL_SU is disabled, these prctl commands
will not be compiled into the kernel.
2025-10-08 14:33:17 +08:00
rifsxd
ce3a7ec189 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:08:30 +08:00
ShirkNeko
59cd8d1c3b kernel: core_hook: harden prctl handler
detection is done by comparing a 0xDEADBEEF call to a non-0xDEADBEEF one.
which yeah, you will see that the non-0xDEADBEEF one returns early.

yes I know this causes delays for all prctl calls, as we straight up check uid,
but this keeps the delay consistent, which is what we want.

another is that we only should only perform this recrowning logic for multiuser

- temp fix for cimb octo's prctl abuse

Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-10-06 00:19:37 +08:00
ShirkNeko
36617bf0a1 kernel: For cmd_su, bypass the susfs_is_current_proc_umounted check only for system processes. 2025-10-05 20:08:51 +08:00
unknow-tech
5b49054055 Merge pull request #445 from unknow-tech/patch-1
Fix wrong function
2025-10-05 00:37:59 +08:00
ShirkNeko
d4dcf610c9 kernel: Fixed disable_seccomp compatibility issues 2025-10-01 00:16:35 +08:00
ShirkNeko
78e0dc6da2 kernel: Add CONFIG_KSU_MANUAL_SU configuration
- Use random passphrase protection for manual su functionality
2025-09-30 23:29:29 +08:00
ShirkNeko
a9a10466b3 Kernel: Enhanced temporary record UID functionality and elevated privileges 2025-09-30 23:27:02 +08:00
ShirkNeko
65d5d6a494 kernel: Add the ability to manually elevate privileges for programs using prctl by specifying UID or PID. 2025-09-30 23:26:28 +08:00
ShirkNeko
a20a89da03 kernel: Revert partial changes 2025-09-27 23:04:14 +08:00
ShirkNeko
9551ca4fe8 kernel: fmt ,optimization Log 2025-09-27 21:12:02 +08:00
ShirkNeko
a2431d50ce kernel: Enhance the user space scanning functionality 2025-09-27 19:47:22 +08:00
ShirkNeko
23ed4384e6 Revert "Unmount isolated process which forks from zygote unconditionally (#2747)"
This reverts commit 695e749e3e.
2025-09-25 16:13:07 +08:00
ShirkNeko
c664aa66af bump KSU_VERSION_API to 3.2.0 2025-09-24 22:34:47 +08:00
ShirkNeko
7a449345d1 kernel: fmt 2025-09-24 22:32:58 +08:00
ShirkNeko
f1f7c61aee kernel: Bump tracepoint_hooks to version v1.1
Remove `devpts_hook` and `execveat_hook` from `tracepoint_hooks`
2025-09-24 22:18:14 +08:00
ShirkNeko
ccc5cb74bf 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-24 22:17:12 +08:00
Cloud_Yun
75fe8c9b6a kpm: remove incorrect "<" to fix compilation error (#418)
i'm so sorry

Signed-off-by: Cloud_Yun <1770669041@qq.com>
2025-09-24 21:48:03 +09:00
ShirkNeko
a12c78d213 Revert "kernel: throne_tracker: offload to kthread tiann #2632"
This reverts commit d5d2bb35d2.
2025-09-24 16:25:47 +08:00
backslashxx
6c145179d4 pullout envp 2025-09-24 16:17:38 +08:00
backslashxx
ac05038e64 move debug back up 2025-09-24 16:17:12 +08:00
ShirkNeko
d5d2bb35d2 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:51:28 +08:00
ShirkNeko
cb01bf428d kernel: Simplify and remove user_arg_ptr ksu_handle_execveat_ksud
- Migrate `ksu_handle_execveat` to sucompat
2025-09-24 01:27:04 +08:00
ShirkNeko
7146210192 kernel: sys_execve bprm simplified
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-09-23 23:58:41 +08:00
ShirkNeko
8a14f64964 kernel: sys_execve_kp remains the preferred choice for the first registration. 2025-09-23 21:22:34 +08:00
ShirkNeko
763ce7e86c 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:20:48 +08:00
backslashxx
c64d196a10 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

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-09-22 23:01:38 +08:00
backslashxx
c690d9c02c 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:01:38 +08:00
ShirkNeko
9a9623f578 kernel: Use /data/user_de/ for rollback instead of packages.list
manager: Fix path and permission issues
2025-09-19 21:21:10 +08:00
ShirkNeko
cc1c66bb6f Add UID scanner functionality and related infrastructure
- Introduced a new module `uid_scanner` in userspace for managing UID scanning.
- Created a new GitHub Actions workflow for building the `user_scanner`.
- Implemented kernel communication in `throne_comm.c` and `throne_comm.h` to handle user space updates and rescan requests.
- Developed the `uid_scanner` daemon in C to scan user directories and manage UID whitelists.
- Added configuration management for the UID scanner with support for multiple users and auto-scanning.
- Implemented logging and error handling throughout the UID scanning process.
- Created necessary build files for the `user_scanner` JNI integration.
- Added a `.gitignore` file to exclude build artifacts.
2025-09-19 21:01:01 +08:00
Wang Han
695e749e3e Unmount isolated process which forks from zygote unconditionally (#2747)
Rethink about this patch, isolated process which directly forks from
zygote is just like normal app, so there is no reason apps won't crash
but Isolated process will. Also zygote reopens fd before actually fork,
so it should be fine.

This reverts commit 2a1741de96a789957555053cf5a397cbef1eb3e4.
2025-09-17 20:01:38 +08:00
Cloud_Yun
ed7dc01fb2 kpm: fix compilation errors (#396)
Sorry, I made another mistake

Signed-off-by: Cloud_Yun <1770669041@qq.com>
2025-09-17 20:01:12 +08:00
Cloud_Yun
7d475e642f kpm: 改进可读性 (#392)
* kpm: improving readability
Honestly, this format is really messy

Signed-off-by: Cloud_Yun <1770669041@qq.com>

* kpm: fix missing int label
my bad (((

Signed-off-by: Cloud_Yun <1770669041@qq.com>

---------

Signed-off-by: Cloud_Yun <1770669041@qq.com>
2025-09-17 20:01:05 +08:00
ShirkNeko
415555aef8 kernel: Add the real UID by parsing the UID from the /data/user_de/0/[app] directory fix #356]
Prioritize retrieving the application UID from /data/user_de. If this fails, fall back to retrieving it from packages.list.

Fix unstable application UID acquisition

Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-09-12 14:02:00 +08:00
ShirkNeko
067ced4a8c kernel: Reworking Dynamic Manager Index Configuration 2025-09-06 15:25:03 +08:00
nobody202222
41d21e994c fix 'for' loop problem (#376)
fix ‘for’ loop initial declarations are only allowed in c99 or c11 mode
2025-09-05 21:52:41 +08:00
rsuntk
9b37ec4a84 kernel: stop intercepting devpts inode permission via LSM
* Somehow, it just does not work properly. (sometimes)

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-09-04 16:25:27 +08:00
dabao1955
662a2b1237 kernel: Removs extra strip for hook choice (#361)
* kernel: Removs extra strip for hook choice 

extra changes for #353

* kernel: Fix Makefile
2025-08-28 10:18:11 +08:00
ShirkNeko
ea602be270 kernel: Remove the ksu_ prefix from the dynamic manager signature. 2025-08-25 20:16:51 +08:00
ShirkNeko
b8b75349e0 kernel: Bump KSU_VERSION_API to 3.1.9 2025-08-24 11:45:08 +08:00
dabao1955
3f3e520641 kernel: Remove unnecessary strip in CONFIG_KSU_TRACEPOINT_HOOK check (#353)
The 'strip' function is redundant when checking Kconfig variables, as
values from CONFIG options (like CONFIG_KSU_TRACEPOINT_HOOK) are already
trimmed and do not contain leading/trailing whitespace.

Simplify the condition for better readability and maintainability:
  - Remove unnecessary $(strip ...)
  - Add consistent spacing around the comma

This change aligns with kernel Makefile conventions and improves code clarity
without altering behavior.

Signed-off-by: dabao1955 <dabao1955@163.com>
2025-08-24 11:41:18 +08:00
ShirkNeko
da164ebeed kernel: Modified dynamic signature All files have been renamed to the correct names: Dynamic Manager 2025-08-24 11:00:17 +08:00
ShirkNeko
106c10d6f8 Kernel: Improved permission tracking logic when dynamic signature manager existence checks are enabled
- Fixed a panic issue caused by repeated scans in certain cases where dynamic signatures were not enabled

Revert: setup.sh: cleanup symlink & config logic (#338)
2025-08-19 18:16:09 +08:00