Commit Graph

346 Commits

Author SHA1 Message Date
ShirkNeko
8c9692c350 kernel/Makefile: enhance version retrieval logic with GitHub commit count 2025-06-24 22:53:12 +08:00
ShirkNeko
f876a523f6 kernel: Rewrite kernle version code management
Co-authored-by: lamadaemon <i@lama.icu>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-06-24 20:07:56 +08:00
Prslc
0f3a9de958 Kernel: use main branch commit count for consistent versioning (#209) 2025-06-23 20:05:16 +08:00
ShirkNeko
3437c7cf3b kernel: remove deprecated CONFIG_KSU_SUSFS_SUS_OVERLAYFS state initialization checks 2025-06-21 18:20:44 +08:00
ShirkNeko
8716b764ee kernel/Makefile: check kernelsu driver version from online git repo first, if fails then check local .git and if that also fails then use hardcoded fallback
Co-authored-by: rifsxd <rifat.44.azad.rifs@gmail.com>
2025-06-21 17:12:03 +08:00
ShirkNeko
4a215511aa kernel: refactor SUSFS feature status retrieval for improved readability and maintainability 2025-06-20 04:08:04 +08:00
ShirkNeko
8283b5597d kernel: swap CONFIG_KSU_SUSFS_SUS_SU and CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT feature flags 2025-06-20 01:32:49 +08:00
rsuntk
103217755b kernel: allow GKI kprobes to use LSM hook for ksu_handle_devpts
* Also minor changes on comments

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-20 00:30:15 +08:00
rsuntk
4502a52e1b kernel: selinux: expose is_ksu_transition to all linux version
* Allow newer kernel to use is_ksu_transition function.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-20 00:30:10 +08:00
rsuntk
babc50c048 [skip ci] kernel: just search for ksu_handle_devpts
* only to make 100% sure?

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-19 18:26:24 +08:00
backslashxx
aa80661186 kernel: intercept devpts via security_inode_permission LSM
* This changes:
  + Avoid conflicts with other devpts hooks.
  + We keep pts_unix98_pre for KPROBES for simplifying things.

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-19 18:26:15 +08:00
rsuntk
9e8fdc35c4 [skip ci] kernel: remove and fmt
* People who understands kernel, likely the didn't need this.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-19 18:25:28 +08:00
ShirkNeko
bce28cc3ca kernel: add CMD_GET_SUSFS_FEATURE_STATUS command to get the correct functional state of SUSFS 2025-06-16 20:17:11 +08:00
古塵
20fa0a4a62 kernel: core_hook: Fix and complete try_umount renaming and usage (#165)
Fixed function definition and restored missing ksu_try_umount calls that were unintentionally removed in previous commits. This includes unmounts for:

- /debug_ramdisk
- /sbin
- /system/etc/hosts
- /apex/com.android.art/bin/dex2oat64
- /apex/com.android.art/bin/dex2oat32

Fixes: b443b11df9 ("kernel: Refactoring the mount point unloading logic")
Fixes: da7632470d ("kernel: 使用 try_umount 替换 ksu_try_umount 以统一卸载逻辑")

Signed-off-by: schqiushui <orochi9999@gmail.com>
2025-06-14 02:42:21 +08:00
ShirkNeko
15d1253d64 kernel: 使用 try_umount 替换 ksu_try_umount 以统一卸载逻辑 2025-06-13 19:50:53 +08:00
ShirkNeko
36cca65af3 kernel: Add CMD_HOOK_TYPE handling to core_hook.c to support state lookups for manual hooks
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
Co-authored-by: rifsxd <rifat.44.azad.rifs@gmail.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-06-13 15:42:34 +08:00
ShirkNeko
a873411a07 kernel: Bump SuSFS version to v1.5.8 2025-06-13 02:18:29 +08:00
rsuntk
ff328ed65a kernel: mayfix freeze and reboot issue.
* When ksys_umount/sys_umount/path_umount were called,
we shouldn't call path_put again.

References:
https://elixir.bootlin.com/linux/v4.19.325/source/fs/namespace.c#L1671
https://elixir.bootlin.com/linux/v5.15.185/source/fs/namespace.c#L1759

Reported-by: NVG-064 <aryslow92@gmail.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-12 18:24:15 +08:00
rsuntk
f709b0c232 [skip ci] kernel: core_hook: add missing path_put
[  101.572296] CPU: 0 PID: 8674 Comm: main Tainted: G        WC OE     5.15.148-Ghost@NVG-064-gce02b349fb2b #1
[  101.572305] Hardware name: Qualcomm Technologies, Inc. KHAJE IDP nopmi topaz (DT)
[  101.572309] pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[  101.572315] pc : mntput_no_expire+0x25c/0x300
[  101.572328] lr : mntput_no_expire+0x134/0x300
[  101.572334] sp : ffffffc01d163c10
[  101.572336] x29: ffffffc01d163c30 x28: ffffffdb2c74bff0 x27: 0000000000000000
[  101.572345] x26: ffffff806cf11200 x25: ffffff806cf11200 x24: ffffffdb2db93000
[  101.572353] x23: ffffff807df66da0 x22: ffffff807df66d80 x21: ffffff807df66d80
[  101.572361] x20: ffffffdb2db89380 x19: ffffff806cf11200 x18: ffffffc013aad068
[  101.572369] x17: 0000000000000001 x16: ffffffa6c928b000 x15: 0000000000000000
[  101.572378] x14: 0000000000000020 x13: ffffffdb2db9f860 x12: 0000000000000020
[  101.572385] x11: ffffffffffffffff x10: 00000000000000ff x9 : 0000000000000008
[  101.572393] x8 : ffffff807df66d80 x7 : 61705f75736b203a x6 : 55536c656e72654b
[  101.572401] x5 : ffffffdb2de14332 x4 : ffffff81f6c435c1 x3 : 0000000000000000
[  101.572409] x2 : 0000000200000000 x1 : 0000000000000000 x0 : 00000000ffffffff
[  101.572418] Call trace:
[  101.572422] mntput_no_expire+0x25c/0x300
[  101.572431] path_put+0x3c/0x58
[  101.572438] ksu_try_umount+0x14c/0x174
[  101.572445] susfs_try_umount_all+0x6c/0x190
[  101.572450] ksu_handle_setuid+0x20c/0x320
[  101.572454] ksu_task_fix_setuid+0x18/0x2c
[  101.572459] __sys_setresuid+0x1e0/0x3dc
[  101.572466] __arm64_sys_setresuid+0x28/0x38
[  101.572472] invoke_syscall+0x64/0x154
[  101.572479] el0_svc_common+0x90/0xf4
[  101.572484] do_el0_svc+0x2c/0x9c
[  101.572489] el0_svc+0x28/0x60
[  101.572496] el0t_64_sync_handler+0xd4/0xf0
[  101.572501] el0t_64_sync+0x1b8/0x1bc
[  101.572508] ---[ end trace b57c69edb246930f ]---
[  101.572626] ------------[ cut here ]------------

Suggested-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-12 18:24:05 +08:00
backslashxx
70b4551936 kernel: core_hook: fix missed path_put
make sure to path_put() on all codepaths after kern_path() success

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-06-12 18:23:36 +08:00
backslashxx
1726d0da58 kernel: core_hook: refactor escape_to_root
- Remove BUG_ON, bail out when failed
- Add put_cred

Signed-off-by: rsuntk <rissu.ntk@gmail.com>
2025-06-12 18:22:58 +08:00
backslashxx
0a5a024dc8 kernel: throne_tracker: avoid cross-fs traversal using s_magic check (#2633)
Skip directories that does NOT have the same magic as /data/app.
This is to avoid scanning incfs and any other stacked filesystems.

While this is way dumber, it's way cheaper.
no kern_path(), no missable path_put(), no ref handling.

This supercedes
`throne_tracker: avoid cross fs access
(https://github.com/tiann/KernelSU/pull/2626)`
- upstream
0b6998b474

Signed-off-by: backslashxx
<118538522+backslashxx@users.noreply.github.com>
2025-06-12 18:21:05 +08:00
ShirkNeko
b443b11df9 kernel: Refactoring the mount point unloading logic 2025-06-12 18:17:52 +08:00
ShirkNeko
17905c71b6 kernel: sucompat: improve error handling and add conditional hooks 2025-06-12 16:55:20 +08:00
ShirkNeko
37f238f674 kernel: 移除 Makefile 中不必要的签名写入选项 2025-06-12 15:55:49 +08:00
ShirkNeko
65cf6ac632 kernel: Remove unsupported UID check from profile validation in allowlist.c
Co-authored-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-06-12 15:54:55 +08:00
ShirkNeko
87b57d9eba kernel: Update sucompat.c to improve hook state management and code clarity
Co-authored-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-06-12 15:53:17 +08:00
ShirkNeko
ad2721c050 kernel: Refactor compatibility checks in kernel_compat.c for clarity and maintainability
Co-authored-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-06-12 15:51:14 +08:00
ShirkNeko
514adfe86e Optimize compilation flags in Makefile, remove redundant options and add Samsung SELinux porting support
Co-authored-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-06-12 15:50:24 +08:00
ShirkNeko
22db54c5d3 kernel: Fix compilation flags in Makefiles and optimize SELinux rule handling
Co-authored-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-06-12 15:43:24 +08:00
rsuntk
80678a4475 kernel: ksud: commonize handle_execve_ksud and add support for compat_execve_ksud (#109)
* This is only for 32bit userspace, 64bit kernel
* Adapt from backslashxx KernelSU repository (our fork still using struct)
* Sync-up with baskslashxx's scope minimized hook.

Signed-off-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
Co-authored-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-06-12 15:35:42 +08:00
rsuntk
dc0026c10b [skip ci] kernel: move is_ksu_transition to selinux.c
* SELinux stuff on ksud? Does something like this is offtopic?

Signed-off-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-06-12 15:34:23 +08:00
rsuntk
5053f04640 kernel: Remove ksu_execveat_hook from is_ksu_transition
* Doesn't work well

Ref: c40e3512b5

Reported-by: edenadversary <143865198+edenadversary@users.noreply.github.com>
2025-06-12 15:33:47 +08:00
rsuntk
9cbfe80640 [skip ci] kernel: minor changes on ksu_sys_umount
* Simplify value for 'ret', adding some comments

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-12 15:24:54 +08:00
rsuntk
5d36d1a801 kernel: mark is_ksu_transition as maybe_unused
* Probably this hook is not needed much

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-12 15:24:37 +08:00
F-19-F
9034358385 kernel: provide is_ksu_transition check
context: this is known by many as `selinux hook`, `4.9 hook`

add is_ksu_transition check which allows ksud execution under nosuid.
it also eases up integration on 3.X kernels that does not have check_nnp_nosuid.

this also adds a `ksu_execveat_hook` check since this transition is NOT needed
anymore once ksud ran.

Usage:
	if (check_ksu_transition(old_tsec, new_tsec))
		return 0;

on either check_nnp_nosuid or selinux_bprm_set_creds (after execve sid reset)

reference: dfe003c9fd

taken from:
`allow init exec ksud under nosuid`
- 3df9df42a6
- https://github.com/tiann/KernelSU/pull/166#issue-1565872173

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-06-12 15:24:27 +08:00
rsuntk
467bbeb74e kernel: Remove more stray backslash in grep regex and move path_umount as optional backport 2025-06-12 15:22:30 +08:00
Tashfin Shakeer Rhythm
8996cb9f4a kernel: Makefile: Remove stray backslash from path_umount grep regex (#103)
Signed-off-by: Tashfin Shakeer Rhythm <tashfinshakeerrhythm@gmail.com>
2025-06-12 15:19:57 +08:00
YC酱luyancib
56bfe55c3d Drop auto backport path_umount (#124)
Since https://github.com/backslashxx/KernelSU/commit/4f8943a and https://github.com/rsuntk/KernelSU/commit/0eab5ae , so auto backport `path_umount` is no longer needed.
2025-06-01 00:55:22 +08:00
ShirkNeko
b14a6edb15 kernel: remove SELinux Makefile and add manager to .gitignore 2025-05-28 14:16:53 +08:00
ShirkNeko
788e4c2f2f kernel: refactor umount functions for improved logging and clarity
Co-authored-by: rsuntk <rsuntk@yukiprjkt.my.id>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-05-27 15:21:42 +08:00
rsuntk
61e3a9bcf2 kernel: fix ksu_sys_umount compatibility
* Some people reports about undefined reference to `sys_umount`
* Since ksys_umount exist on Linux 4.17-rc1, then we gonna use that one.

Rev 2: Use correct int instead of long for ksys_umount

Signed-off-by: rsuntk <90097027+rsuntk@users.noreply.github.com>
2025-05-27 01:13:54 +08:00
rsuntk
1ce706823e kernel: guard nuke_ext4_sysfs
Rather than using depends on / select,
i just prefer this way, although, yes, it is
an ifdef hell.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-05-24 15:03:24 +08:00
rsuntk
84a0ab78fb kernel: make path_umount backporting as optional
Since https://github.com/backslashxx/KernelSU/commit/4f8943a, path_umount is no longer needed.

Signed-off-by: rsuntk <rsuntk@yukiprjkt.my.id>
2025-05-24 15:02:40 +08:00
backslashxx
cd32ee21be kernel: core_hook: screw path_umount backport, call sys_umount directly
I am repasting here what I posted on the source code originally:

/*
 * turns out path_umount backport is completely unneeded
 * we copy the trick used on strncpy_from_unsafe_user / strncpy_from_user_nofault
 * https://elixir.bootlin.com/linux/v4.4.302/source/mm/maccess.c#L184
 * basically
 *
 *     mm_segment_t old_fs = get_fs();     // remember original fs segment
 *     set_fs(USER_DS);                    // or KERNEL_DS *
 *     do_whatever_in_userspace();
 *     set_fs(old_fs);                     // restore fs segment
 *
 *  * kernel -> user, KERNEL_DS, user -> kernel, USER_DS
 *
 * so yes, we can try to straight up call a syscall from kernel space
 *
 * NOTE: on newer kernels you can use force_uaccess_begin + force_uaccess_end
 * ref: https://elixir.bootlin.com/linux/v5.10.237/source/mm/maccess.c#L250
 *
 */

path_umount backport now optional — neat trick, werks, what can I say.

Backports? Nah, we’re good.

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-05-24 14:43:07 +08:00
backslashxx
5aed2c2d2d kernel: sucompat: increase reliability of execve_sucompat
On plain ARMv8.0 devices (A53,A57,A73), strncpy_from_user_nofault() sometimes
fails to copy `filename_user` string correctly. This breaks su ofc, breaking
some apps like Termux (Play Store ver), ZArchiver and Root Explorer.

This does NOT seem to affect newer ARMv8.2+ CPUs (A75/A76 and newer)

My speculation? ARMv8.0 has weak speculation :)

here we replace `strncpy_from_user_nofault()` with another routine:
 - access_ok() to validate the pointer
 - strncpy_from_user() to copy and validate string
 - manual null-termination just in case, as strncpy_from_user_nofault also does it
 - remove that memset, seems useless as it is an strncpy, not strncat

Kind of mimicking _nofault, but yes with this one we allow pagefaults.

Tested on:
- ARMv8.0 A73.a53, A57.a53, A53.a53
- ARMv8.2 A76.a55

Tested-by: iDead XD <rafifirdaus12bb@gmail.com>
Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
2025-05-24 14:37:51 +08:00
ShirkNeko
bbb072b776 Refactoring KPM support to check KPM status using CMD_ENABLE_KPM 2025-05-24 14:36:41 +08:00
ShirkNeko
fe305e4219 Fix the clone address of the KernelSU repository in setup.sh 2025-05-20 12:53:31 +08:00
YC酱luyancib
6ee558d52a kernel:fix missing auto backport can_mount #85 2025-05-18 18:39:20 +08:00
ShirkNeko
1d1a404fa1 Updating the KPM configuration
- We don't know if KPM can run on arm32-bit devices, so to avoid some problems, add a dependency on 64-bit architectures

Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
2025-05-17 18:36:42 +08:00