Skip to content

[backslashxx's KernelSU] Better KSU integration for non-gki devices - #1

Open
ketikai wants to merge 79 commits into
kyasu:lineage-23.2from
ketikai:lineage-23.2
Open

[backslashxx's KernelSU] Better KSU integration for non-gki devices#1
ketikai wants to merge 79 commits into
kyasu:lineage-23.2from
ketikai:lineage-23.2

Conversation

@ketikai

@ketikai ketikai commented May 27, 2026

Copy link
Copy Markdown

KernelSU Integration

'''

  • The official KSU has not supported non-gki devices for a long time.

  • So we chose the more reliable KSU fork.

'''

Backslashxx's KernelSU


'''

'''

How To Setup


# 1. into workdir
cd android_kernel_xiaomi_sdm710

# 2. setup with backslashxx's KernelSU
curl -LSs https://raw.githubusercontent.com/backslashxx/KernelSU/master/kernel/setup.sh  | bash -s master

Quick Build (Github Actions)


'''

  1. fork this repository

  2. enable github actions

  3. create a repository's secret of actions (optional)

    name: SIGNING_KEY

    content: like certs/signing_key.pem

         -----BEGIN PRIVATE KEY-----
         MIIJQw...more content...0zxuI=
         -----END PRIVATE KEY-----
         -----BEGIN CERTIFICATE-----
         MIIFKD...more content...R8gw==
         -----END CERTIFICATE-----
    
  4. manual run workflow (build kernel)

    check With KernelSU

'''

Related


'''

'''

ketikai and others added 18 commits May 28, 2026 01:16
…efconfig: grus: Enable KernelSU"'"

b09a17b^..8f5409a

This reverts commit b09a17b.

Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
This refactors original KSU hooks to replace deep kernel function hooks with targeted hooks.
This backports KernelSU pr#1657 and having pr#2084 elements (32-bit sucompat).
It reduces the scope of kernel function interception and still maintains full fucntionality.

This commit is a squash of the following:
*	fs/exec: do_execve: ksu_handle_execveat hook
*	fs/exec: compat_do_execve: ksu_handle_execveat_sucompat hook
	fs/open: sys_faccessat: ksu_handle_faccessat hook
*	fs/read_write: sys_read: ksu_handle_sys_read hook
*	fs/stat: sys_newfstatat: ksu_handle_stat hook
*	fs/stat: sys_fstatat64: ksu_handle_stat hook
*	drivers: input: input_event: ksu_handle_input_handle_event hook
*	drivers: tty/pty.c: pts_unix98_lookup: ksu_handle_devpts hook

references: KernelSU pr#1657, pr#2084
	https://kernelsu.org/guide/how-to-integrate-for-non-gki.html

Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
* 添加可选补丁 'policy_rwlock' 。
* 为 'grus_defconfig' 显式配置 'CONFIG_KSU' 子项。
* 为 'grus_defconfig' 显式留空 'CONFIG_LOCALVERSION' 值。

Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
CONFIG_KSU=n

Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
@ketikai
ketikai marked this pull request as draft June 27, 2026 03:37
@ketikai
ketikai marked this pull request as ready for review June 27, 2026 03:38
@ketikai
ketikai marked this pull request as draft June 27, 2026 03:38
@ketikai
ketikai marked this pull request as ready for review June 27, 2026 03:38
@ketikai

ketikai commented Jun 27, 2026

Copy link
Copy Markdown
Author

@kyasu CR

@ketikai ketikai changed the title The official KSU has not supported non-gki devices for a long time. [backslashxx's KernelSU] Better KSU integration for non-gki devices Jul 7, 2026
ketikai and others added 30 commits July 17, 2026 13:18
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
…ctor(build-kernel-ksu) feat(build-kernel-ksu-test): 修复、更新、重构和细化与 `ksu` 相关的工作流。

Signed-off-by: ketikai <ketikai@idealstate.team>
…所须的令牌。

Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
… 到 `RELEASE_TAG` 仓库,修复发布仓库未明确的问题。

Signed-off-by: ketikai <ketikai@idealstate.team>
…ase` 下没有写权限的问题,为构建添加 `ccache` 支持。

Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
Signed-off-by: ketikai <ketikai@idealstate.team>
[ Upstream commit 54da6a0924311c7cf5015533991e44fb8eb12773 ]

Use __attribute__((__cleanup__(func))) to build:

 - simple auto-release pointers using __free()

 - 'classes' with constructor and destructor semantics for
   scope-based resource management.

 - lock guards based on the above classes.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230612093537.614161713%40infradead.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

[@acroreiser: port common and spinlock parts of the original patch (backport to 4.9)]
…er()

remove_waiter() is used by the slowlock paths, but it is also used for
proxy-lock rollback in rt_mutex_start_proxy_lock() when invoked from
futex_requeue().

In the latter case waiter::task is not current, but remove_waiter()
operates on current for the dequeue operation. That results in several
problems:

  1) the rbtree dequeue happens without waiter::task::pi_lock being held

  2) the waiter task's pi_blocked_on state is not cleared, which leaves a
     dangling pointer primed for UAF around.

  3) rt_mutex_adjust_prio_chain() operates on the wrong top priority waiter
     task

Use waiter::task instead of current in all related operations in
remove_waiter() to cure those problems.

[ tglx: Fixup rt_mutex_adjust_prio_chain(), add a comment and amend the
  	changelog ]

Fixes: 8161239 ("rtmutex: Simplify PI algorithm and make highest prio task get lock")
Reported-by: Yuan Tan <yuantan098@gmail.com>
Reported-by: Yifan Wu <yifanwucs@gmail.com>
Reported-by: Juefei Pu <tomapufckgml@gmail.com>
Reported-by: Xin Liu <bird@lzu.edu.cn>
Signed-off-by: Keenan Dong <keenanat2000@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Cc: stable@vger.kernel.org

[
 @acroreiser: backport to 4.9, switch kernel/locking/rtmutex.c to gnu99 to avoid build error below.

include/linux/cleanup.h:112:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
  112 |         for (CLASS(_name, scope)(args),
]
…aiter() on self-deadlock

When FUTEX_CMP_REQUEUE_PI requeues a non-top waiter that already owns the
target PI futex, task_blocks_on_rt_mutex() returns -EDEADLK before setting
waiter->task.

The subsequent remove_waiter() in rt_mutex_start_proxy_lock() dereferences
the NULL waiter->task, causing a kernel crash.

Add a self-deadlock check for non-top waiters before calling
rt_mutex_start_proxy_lock(), analogous to the top-waiter check in
futex_lock_pi_atomic().

Fixes: 3bfdc63936dd4773109b7b8c280c0f3b5ae7d349 ("rtmutex: Use waiter::task instead of current in remove_waiter()")
Signed-off-by: Ji'an Zhou <eilaimemedsnaimel@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Cc: stable@vger.kernel.org

[@acroreiser: backport to 4.9]
…queued

syzbot triggered the following splat in remove_waiter() via
FUTEX_CMP_REQUEUE_PI:

  KASAN: null-ptr-deref in range [0x0000000000000a88-0x0000000000000a8f]
   class_raw_spinlock_constructor
   remove_waiter+0x159/0x1200 kernel/locking/rtmutex.c:1561
   rt_mutex_start_proxy_lock+0x103/0x120
   futex_requeue+0x10e4/0x20d0
   __x64_sys_futex+0x34f/0x4d0

task_blocks_on_rt_mutex() does not arm the waiter upon deadlock detection,
leaving waiter->task nil, where 3bfdc63936dd ("rtmutex: Use waiter::task instead
of current in remove_waiter()") made this fatal.

Furthermore, rt_mutex_start_proxy_lock() should not be calling into remove_waiter()
upon a successfully grabbing the rtmutex. 1a1fb985f2e2 ("futex: Handle early deadlock
return correctly"), moved the remove_waiter() out of __rt_mutex_start_proxy_lock()
(where 'ret' was only ever 0 or < 0) into the wrapper. Tighten this check to
account for try_to_take_rt_mutex().

Fixes: 3bfdc63936dd ("rtmutex: Use waiter::task instead of current in remove_waiter()")
Reported-by: syzbot+78147abe6c524f183ee9@syzkaller.appspotmail.com
Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Cc: stable@vger.kernel.org
Closes: https://lore.kernel.org/all/69f114ac.050a0220.ac8b.0003.GAE@google.com/
Link: https://patch.msgid.link/20260507112913.1019537-1-dave@stgolabs.net

[@acroreiser: backport to 4.9]
Signed-off-by: ketikai <ketikai@idealstate.team>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants