Commit Graph

63 Commits

Author SHA1 Message Date
backslashxx
15371bb1d6 kernel: add non-kprobe support for sucompat disable/enable
I have no idea if this is needed or any useful for manual fs hooks users.
Upstream, this is likely to, well, simply disable hooking of those functions,
to remove and mitigate timing issues as some detection methods can actually
differentiate these.

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 probably not so useful for us, honestly, I have no idea for shit
what I am doing, but lets still port it for the sake of feature parity.

cherry pick from:
	kernel: backport support for sucompat disable/enable
	https://github.com/backslashxx/KernelSU/commit/20ffabb

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-02-23 22:11:50 +06:00
backslashxx
097451d578 kernel: guard functionality that requires kprobes
Since upstream is now making kprobes a requirement, we adapt this tree to still allow
building with manual hooks in an easier way. Furthermore, this also allows a user to
build with manual hooks even with kprobes enabled.

Offending commit:
	kernel: remove unused CONFIG guard becuase GKI kernel enable kprobe by default
	upstream: https://github.com/tiann/KernelSU/commit/500ff9b

Other changes:
	ksud.c, stop_input_hook(), short-circuit redundant logic left by this change.
	cherry pick from: https://github.com/backslashxx/KernelSU/commit/a3d3e93

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-02-23 21:00:59 +06:00
weishu
85866848ea kernel: Allow to re-enable sucompat 2025-02-23 20:37:34 +06:00
Rifat Azad
8fbddc959a Revert "kernel: added susfs v1.5.3"
This reverts commit bdf81c0880.
2024-12-24 08:21:10 +06:00
Rifat Azad
bdf81c0880 kernel: added susfs v1.5.3 2024-12-24 07:34:30 +06:00
Rifat Azad
1a84f69f5c Revert "[1.0] Drop Non-GKI Support (#1483)"
This reverts commit 97d70b40fc.
2024-12-24 06:54:08 +06:00
Rifat Azad
8d2b017c96 kernel: sync with upstream 2024-12-24 06:53:54 +06:00
Rifat Azad
a545a3e81c kernel: slightly polish up code 2024-12-16 02:42:33 +06:00
Rifat Azad
f2fcb3687b kernel: cleaned up remaining susfs code 2024-12-16 00:14:07 +06:00
Rifat Azad
e1d30d55af kernel: implement SuSFS v1.5.2 2024-12-04 16:30:28 +06:00
Ylarod
97d70b40fc [1.0] Drop Non-GKI Support (#1483)
Co-authored-by: weishu <twsxtd@gmail.com>
2024-06-01 14:50:46 +08:00
weishu
8e973bcbd5 kernel: replace devpts kprobe 2024-05-16 17:16:00 +08:00
weishu
81033bcc48 kernel: fix devpts permission. close #1727 2024-05-16 10:32:48 +08:00
weishu
0e656dd339 kernel: Fix compile error on 4.4. close #1720 2024-05-10 15:01:05 +08:00
weishu
1bec08eacf docs: Add devpts description for non gki 2024-05-09 12:05:10 +08:00
weishu
89818cf85f kernel: transition devpts in kernel 2024-05-08 21:15:49 +08:00
weishu
2efefcea72 kernel: use library import 2024-04-27 09:55:24 +08:00
weishu
cd73307cd4 kernel: refactor PR_REAL_REGS 2024-04-26 13:25:29 +08:00
buildbot
2dc2dbfd45 kernel: use syscall hook for all version, remove code next version if works well 2024-04-26 11:42:24 +08:00
Another Guy
e2b0721af5 Hook syscalls and stable symbols (#1657)
1. Replace `do_execveat_common` with `sys_execve` and `sys_execveat`
2. Replace `input_handle_event` with `input_event` and
`input_inject_event`

Tested on android12-5.10-2024-04, android13-5.15-2024-04.
android14-6.1-2024-04
2024-04-26 11:27:48 +08:00
CallMESuper
2cc2312409 kernel: fix issue with dfd parameter retrieval (#1543)
Although in most cases, this system call might not be used, or when
called, AT_FDCWD(-100) is passed in.
2024-03-27 16:29:53 +08:00
weishu
d8671b14d1 kernel: clean memory when exit 2024-03-24 16:41:53 +08:00
weishu
895ad601d2 kernel: remove unused headers 2024-03-20 23:14:30 +08:00
weishu
fdb6b6a88a kernel: fix panic cast 2024-03-20 15:39:07 +08:00
weishu
f69abf1e51 kernel: hook newfstatat/faccessat syscall instead of unstable symbol 2024-03-20 15:15:26 +08:00
weishu
62117c6017 kernel: fix su not working in shell for 6.1 kernel 2023-11-13 15:06:25 +08:00
Levi Zim
c8d0f01ce4 Copy one extra byte from userspace filename (#958)
Otherwise we will rewrite paths for filenames that begins with
`/system/bin/su`.

This fix copies one extra byte from userspace filename so that when we
encounter filenames like `/system/bin/suasf`,
`/system/bin/su\0` gets compared with `/system/bin/sua`, which correctly
prevents the `su -> sh` path rewriting.

Close #957
2023-09-16 12:23:04 +08:00
4qwerty7
cd19ce2e86 Distinguish different PT_REGS_PARM4 under x86 (#711)
1. `PT_REGS_CCALL_PARM4` 表示存放C调用约定的第4个参数的寄存器
2. `PT_REGS_SYSCALL_PARM4` 表示存放linux syscall调用约定的第4个参数的寄存器
3. 将原有 `PT_REGS_PARM4` 改为上述之一
4. 将原有 `ksu_handle_execveat_ksud` 和 `ksu_handle_execveat_sucompat` 可能被
kprobe 传递错误实参、且不使用的形参标记为 never_used 并传递 `NULL`
5. 为 `ksu_handle_execveat_ksud` 提供正确的 argv 参数用以在 x86 下也能正确识别 `init
second_stage`

---------

Co-authored-by: weishu <twsxtd@gmail.com>
2023-07-06 09:01:35 +08:00
weishu
c7c5a07f0a kernel: fix compile err on lower kernel 2023-06-27 20:46:09 +08:00
weishu
8b7dcc674a kernel: copy filename ourself instead of getname 2023-06-26 19:28:40 +08:00
weishu
a0abe9db68 Revert "kernel: use vfs_fstatat on kernel 5.10+, vfs_statx may have cfi."
This reverts commit d2647b2f4d.
2023-06-22 14:37:17 +08:00
weishu
22e3e1fc0e Revert "kernel: getname might sleep in kprobe handler (#670)"
This reverts commit 7fa7b5b875.
2023-06-22 12:54:30 +08:00
weishu
7fa7b5b875 kernel: getname might sleep in kprobe handler (#670) 2023-06-22 10:54:50 +08:00
weishu
d2647b2f4d kernel: use vfs_fstatat on kernel 5.10+, vfs_statx may have cfi. 2023-06-20 18:42:41 +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
tiann
978839da6b kernel: use ksud as root shell instead of /system/bin/sh 2023-04-03 20:29:10 +08:00
小さい猫
4a811576fc fix some typos introduced in #166 (#181)
Signed-off-by: Ookiineko <chiisaineko@protonmail.com>
Co-authored-by: f19 <58457605+F-19-F@users.noreply.github.com>
Co-authored-by: Scirese <nuclearlight91@gmail.com>
2023-02-02 23:38:04 +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
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
SlightlyLookAround
7be4d88752 kernel: Migrate the reference of task_stack() (#102)
- task_stack() had been separated when it was in Linux 4.11, so let's do
  our migration when KernelSU facing the old version of kernel.
- See f3ac606719

Signed-off-by: Calling <KeternalGithub@163.com>

Signed-off-by: Calling <KeternalGithub@163.com>
2023-01-22 11:32:28 +08:00
weishu
0b14cac87e kernel: 1. use prctl lsm hook; 2. refine sucompat hook 2023-01-19 13:31:55 +07:00
Ylarod
a1aa564406 kernel: fix typo 2023-01-16 12:42:40 +08:00
weishu
d776da4df5 kernel: support ksud services 2023-01-16 11:19:59 +07:00
weishu
cbb1cb39ea kernel: fix stack frame size exceeds 2023-01-16 10:21:10 +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
chen2021-web
9150cfedd7 backport to 4.14 (#59) 2023-01-15 15:34:15 +08:00
weishu
0caaf53c52 kernel: backport to 4.19 (#36) 2023-01-10 23:20:32 +08:00
weishu
0e847f1a81 kernel: change vold.rc to atrace.rc temporarily 2023-01-04 21:42:50 +07:00
weishu
a66328ddaa kernel: Add boot_completed init event 2023-01-04 13:43:37 +07:00