Commit Graph

46 Commits

Author SHA1 Message Date
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
ed3536d5fd kernel: Reworking Dynamic Manager Index Configuration 2025-09-06 15:21:21 +08:00
ShirkNeko
8ca2a25535 kernel: Remove the ksu_ prefix from the dynamic manager signature. 2025-08-25 20:14:22 +08:00
ShirkNeko
605ef68b3a kernel: Modified dynamic signature All files have been renamed to the correct names: Dynamic Manager 2025-08-24 11:22:54 +08:00
Helium_Studio
ce58519e66 kernel: Reformat code using clang-format (#347)
* The coding format is too messy, reformat to improve readability
  and get closer to Linux kernel coding style.

* While at it, update .clang-format file to linux-mainline state.
2025-08-22 14:02:20 +08:00
backslashxx
210f61949f kernel: apk_sign: fix return check for ksu_sha256
upstream used IS_ERR to check for negative return and that is int,
so correct it.

This is one headache for old compilers.

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-08-21 13:04:34 +08:00
ShirkNeko
14b3449af2 kernel: refactor APK signature verification functions for clarity and efficiency 2025-08-17 23:11:22 +08:00
M. Faris
ff6a68221f kernel: add wrapper for creds, refine disable_seccomp, revert some changes (#131)
1. Wrapper for creds:
* Some older kernel does not have {.val}, so, for nicer compatibility support and clean code,
make some wrapper for credential use.
* After this change, do not use current_uid().val, instead, use ksu_current_uid(). For more
info, check kernel/include/ksu_creds.h.

2. Refine disable_seccomp (need to add k6.11+ support)
https://github.com/tiann/KernelSU/pull/2708
https://github.com/tiann/KernelSU/issues/2706

3. Revert "Handle unmount for isolated process correctly"
Reason: https://github.com/tiann/KernelSU/pull/2696#issuecomment-3181866301

4. consolidate most of the gaps

Co-authored-by: Wang Han <416810799@qq.com>
2025-08-16 13:11:58 +08:00
ShirkNeko
a9e3c1cc8f kermel: Refactoring and separating dynamic signature-related structures and functions and implement hot-signature updates 2025-08-03 22:51:38 +08:00
ShirkNeko
ac9acf6c0a kernel: simplified signature verification 2025-07-09 12:07:33 +08:00
ShirkNeko
6e0fb0b388 kernel: Add the ability to get active managers for multi-manager APKs 2025-07-06 00:53:47 +08:00
ShirkNeko
ed95981d09 kernel: add multi-manager support 2025-07-05 22:30:16 +08:00
ShirkNeko
942210459f Add dynamic signature support 2025-07-05 16:29:40 +08:00
WenHao2130
828290059d kernel: Drop Elysia key
The key owner has lost it

Change-Id: Id9e0037a490a545dc35b90312fc110b54465e153
Signed-off-by: WenHao2130 <wenhao2130@outlook.com>
2025-07-04 18:51:42 +08:00
WenHao2130
67c4111bbd kernel: fmt
Change-Id: Ie84bde7b2944152eb08f5e8f12df1c3aa86f8ca5
Signed-off-by: WenHao2130 <wenhao2130@outlook.com>
2025-06-28 21:26:56 +08:00
愛莉希雅
4908e3b633 愛莉希雅小姐嘅惠禮 (#226) 2025-06-28 14:43:59 +08:00
ShirkNeko
c1aa0690c5 Revert "kernel: add package whitelist check for manager APKs" 2025-06-12 15:14:37 +08:00
ShirkNeko
430a3504d4 Fix line breaks in code and clean up unnecessary includes 2025-06-11 15:08:43 +08:00
ShirkNeko
aec76a388f kernel: add package whitelist check for manager APKs
Co-authored-by: lamadaemon <i@lama.icu>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-06-07 00:48:06 +08:00
ShirkNeko
9d920e7cc5 kernel: added compatibility for non-GKI devices
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-05-10 13:19:30 +08:00
weishu
efbc07fde3 kernel: use library import 2024-04-27 09:55:24 +08:00
weishu
4a73672190 kernel: fix potential dead loop
Co-Authored-by: qwerty472123
2024-03-30 16:13:11 +08:00
weishu
942866d986 Revert "kernel: deny all unexpected signature block"
This reverts commit 869cd50b79.
2024-03-30 16:05:31 +08:00
weishu
d533c27e4f Revert "kernel: deny unexpected offset value for signing check"
This reverts commit 97ee114aa5.
2024-03-30 16:05:31 +08:00
weishu
97ee114aa5 kernel: deny unexpected offset value for signing check 2024-03-29 14:28:51 +08:00
weishu
869cd50b79 kernel: deny all unexpected signature block 2024-03-29 14:14:17 +08:00
weishu
9ffdd171f6 kernel: fix debug set manager 2024-03-27 17:58:47 +08:00
weishu
9a04211051 kernel: Let the kernel choose who is qualified to be the manager. 2024-03-23 21:48:03 +08:00
weishu
d24813b2c3 Merge pull request from GHSA-86cp-3prf-pwqq
* kernel: deny v2 signature blocks with incorrect number

* kernel: reject v1 signature

* kernel: enforce manager package name at compile time

* kernel: don't specific package name in source code, use it in ci
2023-10-23 12:59:30 +08:00
weishu
8828939994 kernel: reject v3 and v3.1 signature scheme for manager verification 2023-10-11 17:06:14 +08:00
weishu
a22959beae kernel: harden the signature check (#1027) 2023-10-11 02:53:11 -05:00
longhuan1999
54ee400dc5 kernel: Adapt to low version Android init process (#973)
1. Adapt to low version Android init process
2. Add stop hook output
3. Fix output with missing line breaks
2023-10-02 12:00:24 +08:00
4qwerty7
c0066b68f5 kernel: support the case that init_task.mnt_ns != zygote.mnt_ns(WSA) (#698)
Basic support for the case that init_task.mnt_ns != zygote.mnt_ns(WSA),
just copy nsproxy and fs pointers for solve #276.

Note the copy in `apk_sign.c` is not required but suggested for
secure(ensure the checked mnt_ns is what ns android running, not created
by user, although many distributions does not have user ns.).

Tested with latest release on Win10 19045.3086(with WSAPatch).

Further review required for:
- [x] Security of this operation (without locking).
- [x] The impact of these modifications on other Android distributions.
2023-07-02 00:20:01 +08:00
rhjdvsgsgks
5c3df7e7a5 kernel: make some compiler happy again (#279)
e743722449
still not fix #252
2023-02-26 22:08:50 +08:00
weishu
683ba112aa kernel: add prefix to avoid symbol confliction 2023-02-20 18:51:59 +07:00
weishu
e743722449 kernel: make some compiler happy 2023-02-20 18:51:59 +07:00
weishu
388d2b0b59 kernel: disable inofity for fd opened for manager 2023-02-12 12:15:58 +07:00
f19
4f2b8b7077 kernel: backport to 4.4 (#166)
These changes make KernelSU work on kernel4.4
[link](https://github.com/F-19-F/android_kernel_oneplus_msm8998).
LINUX_VERSION_CODE macro changes have been vertied on 4.4 4.9 4.14.
For kernel 4.4,just pick two commits
* [introduce
KernelSU](2993524f2f)
* [allow init exec ksud under
nosuid](3df9df42a6)
2023-02-01 19:48:36 +08:00
Ylarod
06aaae1335 kernel: fix missing log tag (#117) 2023-01-25 22:24:00 +08:00
Ylarod
2f970f7ab8 kernel: refact (#113)
* refact

* sort inlude

* update

* unregister execve kprobe

* update log

* don't unregister if not in kprobe

* opt for no kprobe

* opt for no kprobe

* stop debug

* don't forget to call ksu_uid_observer_exit

* rename core to core_hook

* direct call do_persistent_allow_list

* add prefix

* use getter, add warn

* add wrapper

* run clang-format

clang-format --style="{BasedOnStyle: InheritParentConfig, SortIncludes: true}" -i kernel/**/*.[ch]

* try fix wsa x64 build
2023-01-25 21:53:19 +08:00
Ylarod
a30aab1da6 [skip ci] minor fixup (#72)
1. update README_CN.md
2. indent fixup
2023-01-15 17:05:08 +08:00
Ylarod
5e77d1cd5b kernel: add CONFIG_KSU_DEBUG (#19)
* Kconfig: add KSU_DEBUG

* print alert on debug mode

* allow shell by default

* store signature to var on debug mode

* format

* export as module_param

* rename apk_sign to kernelsu
2023-01-14 21:45:34 +08:00
weishu
b427c86ab3 misc: code format(use kernel code stype: https://www.kernel.org/doc/html/v6.1/process/coding-style.html 2022-12-27 18:21:10 +07:00
Ylarod
8e89b90b80 Add ci for manager and userspace (#2)
* kernel: move EXPECTED_* macro to Makefile

* manager: add sign configs

* tools: add check_v2

* CI: build manager

* CI: build userspace
2022-12-15 12:22:43 +08:00
tiann
210d36f91c kernel: use release sign 2022-12-10 22:13:38 +08:00
tiann
51c84400cf Init 2022-12-09 22:04:40 +08:00