Commit Graph

55 Commits

Author SHA1 Message Date
weishu
2f3862b1cc kernel: truncate allowlist before save 2023-12-29 18:32:45 +08:00
weishu
8197ddb359 kernel: fix out of bound reading. close #1227 2023-12-27 20:19:21 +08:00
weishu
165e450f4e kernel: prune allowlist with package name and uid 2023-10-12 15:44:43 +08:00
longhuan1999
b14ea03dc4 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
c62c5f1d78 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
Ikko Eltociear Ashimine
3863d19745 kernel: fix typo in allowlist.c (#663)
creat -> create
2023-06-20 11:03:09 +08:00
weishu
0eb960826d kernel: allow uid 1000(system_uid) to grant root. close #645 2023-06-18 13:00:37 +08:00
Juhyung Park
9fa6a0ce85 Hook improvements (take 2) (#563)
Hi @tiann.

Thanks for the great project, I had great fun playing around with it.

This PR mainly tries to further minimize the possible delays caused by
KernelSU hooking.

There are 3 major changes:
- Processes with 0 < UID < 2000 are blocked straight-up before going
through the allow_list.
I don't see any need for such processes to be interested in root, and
this allows returning early before going through a more expensive
lookup.
If there's an expected breakage due to this change, I'll remove it. Let
me know.
- A page-sized (4K) bitmap is added.
This allows O(1) lookup for UID <= 32767.
This speeds up `ksu_is_allow_uid()` by about 4.8x by sacrificing a 4K
memory. IMHO, a good trade-off.
Most notably, this reduces the 99.999% result previously from worrying
milliseconds scale to microseconds scale.
For UID > 32767, another page-sized (4K) sequential array is used to
cache allow_list.

Compared to the previous PR #557, this new approach gives another nice
25% performance boost in average, 63-96% boost in worst cases.

Benchmark results are available at
https://docs.google.com/spreadsheets/d/1w_tO1zRLPNMFRer49pL1TQfL6ndEhilRrDU1XFIcWXY/edit?usp=sharing

Thanks!

---------

Signed-off-by: Juhyung Park <qkrwngud825@gmail.com>
2023-06-16 19:53:15 +08:00
weishu
ba229c9e4d kernel: use macro for default domain 2023-06-06 21:07:25 +08:00
weishu
109472ae22 kernel: Fix shell permission under KSU_DEBUG 2023-06-06 21:05:37 +08:00
weishu
6a11cb706d kernel: bump format version to force clear allowlist, prepare to release a new version 2023-06-06 20:49:39 +08:00
weishu
bacd16a68c kernel: support setting selinux context for profile 2023-06-06 16:35:25 +08:00
weishu
893aebca4f kernel: support settings supplementary groups for profile 2023-06-06 13:19:11 +08:00
weishu
fc96172655 kernel: make the profile uid, gid, capabilities really work 2023-06-04 17:29:12 +08:00
weishu
9abe9687ab kernel: fix set app profile may override other user's 2023-06-04 13:59:22 +08:00
weishu
27cca2a264 kernel: Fixing the issue of a delay in updating the default profile. 2023-06-04 09:47:31 +08:00
weishu
20a9c6ec0f kernel: use uid instead of package to compare allowlist, fix #580 2023-06-04 09:18:39 +08:00
diphons
da45d90605 Fixup: build under linux 4.14 (#581)
Split compiler_types.h from compiler.h only available for linux 4.14
2023-06-04 09:15:03 +08:00
weishu
395711c942 kernel: dont prune uid used for app profile 2023-06-04 01:01:39 +08:00
weishu
0e539ccee1 kernel: support load/restore default profiles 2023-06-03 23:57:05 +08:00
weishu
14b1386879 kernel: support CMD_IS_UID_GRANTED_ROOT and CMD_IS_UID_SHOULD_UMOUNT 2023-06-03 22:44:01 +08:00
weishu
e030ca48db kernel: fix CMD_GET_ALLOW_LIST error 2023-06-03 19:23:51 +08:00
weishu
f8b18c06c8 kernel: minor fixes for profiles 2023-06-03 10:18:11 +08:00
weishu
cb5cd08098 kernel: don't fill default value for app profile 2023-06-03 00:06:58 +08:00
weishu
e8d234ae66 kernel: baby version of profile 2023-06-03 00:01:00 +08:00
weishu
976f2610cb kernel: fix format warnning 2023-05-22 10:39:54 +08:00
tiann
6b8b02c475 Revert "kernel: don't save allowlist in worker"
This reverts commit 54461bc4c9.
2023-04-18 13:19:49 +08:00
tiann
7965522922 kernel: don't show log when get allowlist 2023-04-18 13:19:49 +08:00
tiann
54461bc4c9 kernel: don't save allowlist in worker 2023-04-18 09:18:06 +08:00
tiann
8cd4ccf728 kernel: remove unused poll wait becuase we always call this in post-fs-data, no need to wait for /data mounted 2023-03-08 15:45:56 +08:00
weishu
4f5c35c364 kernel: add prefix to avoid symbol confliction 2023-02-20 18:51:59 +07:00
f19
9b8f8fac99 kernel: fix filp_open on older kernel's kworker (#205)
On older kernel, kworker missing keyring from init process , and this
keyring is related to FBE , which causes filp_open return ENOKEY or
other errors.To fix this,just install init's keyring to per
kworkers.This works on Kernel 4.4 and 4.9.
2023-02-05 07:14:59 +08:00
f19
b085db50dc 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
skbeh
d163200127 kernel, ksud: collect binaries into /data/adb/ksu (#161) 2023-02-01 17:58:58 +08:00
Ylarod
443c5867cd kernel: precise trigger timing of post-fs-data (#118)
* kernel: add report_event cmd

* ksud: report event

* kernel: trigger on_post_fs_data

* ksud: comment unused code

* [skip ci] run clang-format

Signed-off-by: Ylarod <me@ylarod.cn>

* ci: use custom key to sign official bootimgs

* format ksud

* reject non root

* remove

Signed-off-by: Ylarod <me@ylarod.cn>
2023-01-26 11:29:02 +08:00
Ylarod
21ecb29d41 kernel: opt allowlist persist and log (#119)
* kernel: persist on need

* kernel: opt log for ksu_allow_uid
2023-01-26 08:55:27 +08:00
Ylarod
9fe636cd47 kernel: fix missing log tag (#117) 2023-01-25 22:24:00 +08:00
Ylarod
3d07b7285b 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
weishu
a9dd171f0d kernel: unify workqueue 2023-01-18 18:37:27 +07:00
weishu
aa6ab8fcb9 kernel: don't use 0(root uid) as manager init uid 2023-01-17 13:49:30 +07:00
weishu
7da5189377 kernel: add uid observer, correctly prune uid allowlist when app is installed/uninstalled. 2023-01-17 12:44:38 +07:00
Ylarod
6ad3f47dbd [skip ci] minor fixup (#72)
1. update README_CN.md
2. indent fixup
2023-01-15 17:05:08 +08:00
Ylarod
c4cfd45f2c 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
95656d61ad 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
weishu
5f1d813635 kernel: add selinux rules for allowlist 2022-12-23 08:15:35 +07:00
weishu
fa4362ddd6 kernel: avoding other root process being kprobed 2022-12-21 20:50:55 +07:00
weishu
5ccaa58448 kernel: fix compile errors & warnings on android13-5.15 gki 2022-12-20 10:51:40 +07:00
Nullptr
7194c7b3df Fix su file not found after su (#5) 2022-12-19 19:37:26 +08:00
weishu
bb91686c3c kernel: load_allow_list when /data prepared 2022-12-15 16:06:07 +07:00
weishu
44af9c5d2b kernel: add su compat mode 2022-12-14 14:55:29 +07:00