Skip to content
This repository was archived by the owner on Nov 1, 2025. It is now read-only.

Commit ae06152

Browse files
committed
refactor(ksu, kernel_patches): remove additional syscall hooks guard and add separate patch for SukiSU
Signed-off-by: bachnxuan <bachnxuan@gmail.com>
1 parent ae23f01 commit ae06152

4 files changed

Lines changed: 166 additions & 16 deletions

File tree

kernel_builder/config/variants.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"CONFIG_KSU": true,
4242
"CONFIG_KPM": true,
4343
"CONFIG_KSU_SUSFS": false,
44-
"CONFIG_KSU_KPROBES_HOOK": false,
4544
"CONFIG_KSU_TRACEPOINT_HOOK": true
4645
}
4746
},
@@ -66,7 +65,6 @@
6665
"config": {
6766
"CONFIG_KSU": true,
6867
"CONFIG_KSU_MANUAL_HOOK": true,
69-
"CONFIG_KSU_KPROBES_HOOK": false,
7068
"CONFIG_KSU_SUSFS": true,
7169
"CONFIG_KSU_SUSFS_SUS_SU": false
7270
}
@@ -80,7 +78,6 @@
8078
"config": {
8179
"CONFIG_KSU": true,
8280
"CONFIG_KPM": true,
83-
"CONFIG_KSU_KPROBES_HOOK": false,
8481
"CONFIG_KSU_TRACEPOINT_HOOK": true,
8582
"CONFIG_KSU_SUSFS": true,
8683
"CONFIG_KSU_SUSFS_SUS_SU": false

kernel_builder/pre_build/ksu.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ def _patch_manual_hooks(self) -> None:
6868
if self.variant.upper() in self.MANUAL_HOOK_UNSUPPORTED:
6969
log(f"Skipping manual hooks patch for variant: {self.variant}")
7070
return
71+
72+
hook_patch: Path
7173

72-
hook_patch: Path = PATCHES / "syscall_hooks_v1.5.patch"
74+
if self.variant.upper() == "NEXT":
75+
hook_patch = PATCHES / "next-syscall_hooks_v1.5.patch"
76+
else: # SUKI
77+
hook_patch = PATCHES / "suki-syscall_hooks_v1.5.patch"
7378

7479
apply_patch(hook_patch, check=False, cwd=WORKSPACE)
7580

kernel_patches/syscall_hooks_v1.5.patch renamed to kernel_patches/next-syscall_hooks_v1.5.patch

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ index 78be582b5766..c2045ade6ccc 100644
66
* to 'seed' initial state of a switch or initial position of absolute
77
* axis, etc.
88
*/
9-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
9+
+#ifdef CONFIG_KSU
1010
+extern bool ksu_input_hook __read_mostly;
1111
+extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
1212
+#endif
@@ -16,7 +16,7 @@ index 78be582b5766..c2045ade6ccc 100644
1616
{
1717
unsigned long flags;
1818

19-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
19+
+#ifdef CONFIG_KSU
2020
+ if (unlikely(ksu_input_hook))
2121
+ ksu_handle_input_handle_event(&type, &code, &value);
2222
+#endif
@@ -32,7 +32,7 @@ index 78e15a17c3e5..78d076116855 100644
3232
set_mask_bits(&mm->flags, MMF_DUMPABLE_MASK, value);
3333
}
3434

35-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
35+
+#ifdef CONFIG_KSU
3636
+__attribute__((hot))
3737
+extern int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
3838
+ void *__never_use_argv, void *__never_use_envp,
@@ -44,7 +44,7 @@ index 78e15a17c3e5..78d076116855 100644
4444
const char __user *const __user *, argv,
4545
const char __user *const __user *, envp)
4646
{
47-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
47+
+#ifdef CONFIG_KSU
4848
+ ksu_handle_execve_sucompat((int *)AT_FDCWD, &filename, NULL, NULL, NULL);
4949
+#endif
5050
return do_execve(getname(filename), argv, envp);
@@ -54,7 +54,7 @@ index 78e15a17c3e5..78d076116855 100644
5454
const compat_uptr_t __user *, argv,
5555
const compat_uptr_t __user *, envp)
5656
{
57-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK) // 32-bit su and 32-on-64 support
57+
+#ifdef CONFIG_KSU // 32-bit su and 32-on-64 support
5858
+ ksu_handle_execve_sucompat((int *)AT_FDCWD, &filename, NULL, NULL, NULL);
5959
+#endif
6060
return compat_do_execve(getname(filename), argv, envp);
@@ -68,15 +68,15 @@ index f5a50cc9cd12..fd694b702278 100644
6868
return res;
6969
}
7070

71-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
71+
+#ifdef CONFIG_KSU
7272
+__attribute__((hot))
7373
+extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user,
7474
+ int *mode, int *flags);
7575
+#endif
7676
+
7777
SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
7878
{
79-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
79+
+#ifdef CONFIG_KSU
8080
+ ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
8181
+#endif
8282
return do_faccessat(dfd, filename, mode, 0);
@@ -90,15 +90,15 @@ index 7a2ff6157eda..c7a5e8ec2988 100644
9090
return ret;
9191
}
9292

93-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
93+
+#ifdef CONFIG_KSU
9494
+extern bool ksu_vfs_read_hook __read_mostly;
9595
+extern int ksu_handle_sys_read(unsigned int fd, char __user **buf_ptr,
9696
+ size_t *count_ptr);
9797
+#endif
9898
+
9999
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
100100
{
101-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
101+
+#ifdef CONFIG_KSU
102102
+ if (unlikely(ksu_vfs_read_hook))
103103
+ ksu_handle_sys_read(fd, &buf, &count);
104104
+#endif
@@ -113,7 +113,7 @@ index daf28da335cd..3fa40c6d7446 100644
113113
return cp_new_stat(&stat, statbuf);
114114
}
115115

116-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
116+
+#ifdef CONFIG_KSU
117117
+__attribute__((hot))
118118
+extern int ksu_handle_stat(int *dfd, const char __user **filename_user,
119119
+ int *flags);
@@ -126,7 +126,7 @@ index daf28da335cd..3fa40c6d7446 100644
126126
struct kstat stat;
127127
int error;
128128

129-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK)
129+
+#ifdef CONFIG_KSU
130130
+ ksu_handle_stat(&dfd, &filename, &flag);
131131
+#endif
132132
error = vfs_fstatat(dfd, filename, &stat, flag);
@@ -136,7 +136,7 @@ index daf28da335cd..3fa40c6d7446 100644
136136
struct kstat stat;
137137
int error;
138138

139-
+#if defined(CONFIG_KSU) && !defined(CONFIG_KSU_KPROBES_HOOK) // 32-bit su
139+
+#ifdef CONFIG_KSU // 32-bit su
140140
+ ksu_handle_stat(&dfd, &filename, &flag);
141141
+#endif
142142
error = vfs_fstatat(dfd, filename, &stat, flag);
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
diff --git a/drivers/input/input.c b/drivers/input/input.c
2+
index 171f71bd4..8258f0a30 100644
3+
--- a/drivers/input/input.c
4+
+++ b/drivers/input/input.c
5+
@@ -446,11 +446,21 @@ static void input_handle_event(struct input_dev *dev,
6+
* to 'seed' initial state of a switch or initial position of absolute
7+
* axis, etc.
8+
*/
9+
+#ifdef CONFIG_KSU
10+
+extern bool ksu_input_hook __read_mostly;
11+
+extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
12+
+#endif
13+
+
14+
void input_event(struct input_dev *dev,
15+
unsigned int type, unsigned int code, int value)
16+
{
17+
unsigned long flags;
18+
19+
+#ifdef CONFIG_KSU
20+
+ if (unlikely(ksu_input_hook))
21+
+ ksu_handle_input_handle_event(&type, &code, &value);
22+
+#endif
23+
+
24+
if (is_event_supported(type, dev->evbit, EV_MAX)) {
25+
26+
spin_lock_irqsave(&dev->event_lock, flags);
27+
diff --git a/fs/exec.c b/fs/exec.c
28+
index b1b9db56a..9748c2315 100644
29+
--- a/fs/exec.c
30+
+++ b/fs/exec.c
31+
@@ -2031,12 +2031,22 @@ int kernel_execve(const char *kernel_filename,
32+
return retval;
33+
}
34+
35+
+#ifdef CONFIG_KSU
36+
+__attribute__((hot))
37+
+extern int ksu_handle_execveat(int *fd,
38+
+ struct filename **filename_ptr,
39+
+ void *argv, void *envp, int *flags);
40+
+#endif
41+
+
42+
static int do_execve(struct filename *filename,
43+
const char __user *const __user *__argv,
44+
const char __user *const __user *__envp)
45+
{
46+
struct user_arg_ptr argv = { .ptr.native = __argv };
47+
struct user_arg_ptr envp = { .ptr.native = __envp };
48+
+#ifdef CONFIG_KSU
49+
+ ksu_handle_execveat((int *)AT_FDCWD, &filename, &argv, &envp, 0);
50+
+#endif
51+
return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
52+
}
53+
54+
@@ -2064,6 +2074,9 @@ static int compat_do_execve(struct filename *filename,
55+
.is_compat = true,
56+
.ptr.compat = __envp,
57+
};
58+
+#ifdef CONFIG_KSU // 32-bit su and 32-on-64 support
59+
+ ksu_handle_execveat((int *)AT_FDCWD, &filename, &argv, &envp, 0);
60+
+#endif
61+
return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
62+
}
63+
64+
diff --git a/fs/open.c b/fs/open.c
65+
index 39779f1ba..bef45143c 100644
66+
--- a/fs/open.c
67+
+++ b/fs/open.c
68+
@@ -466,8 +466,17 @@ static long do_faccessat(int dfd, const char __user *filename, int mode, int fla
69+
return res;
70+
}
71+
72+
+#ifdef CONFIG_KSU
73+
+__attribute__((hot))
74+
+extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user,
75+
+ int *mode, int *flags);
76+
+#endif
77+
+
78+
SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
79+
{
80+
+#ifdef CONFIG_KSU
81+
+ ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
82+
+#endif
83+
return do_faccessat(dfd, filename, mode, 0);
84+
}
85+
86+
diff --git a/fs/read_write.c b/fs/read_write.c
87+
index 3f6818620..b2a45d215 100644
88+
--- a/fs/read_write.c
89+
+++ b/fs/read_write.c
90+
@@ -628,8 +628,18 @@ ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
91+
return ret;
92+
}
93+
94+
+#ifdef CONFIG_KSU
95+
+extern bool ksu_vfs_read_hook __read_mostly;
96+
+extern int ksu_handle_sys_read(unsigned int fd, char __user **buf_ptr,
97+
+ size_t *count_ptr);
98+
+#endif
99+
+
100+
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
101+
{
102+
+#ifdef CONFIG_KSU
103+
+ if (unlikely(ksu_vfs_read_hook))
104+
+ ksu_handle_sys_read(fd, &buf, &count);
105+
+#endif
106+
return ksys_read(fd, buf, count);
107+
}
108+
109+
diff --git a/fs/stat.c b/fs/stat.c
110+
index 357a1db41..d5087ca1f 100644
111+
--- a/fs/stat.c
112+
+++ b/fs/stat.c
113+
@@ -401,6 +401,12 @@ SYSCALL_DEFINE2(newlstat, const char __user *, filename,
114+
return cp_new_stat(&stat, statbuf);
115+
}
116+
117+
+#ifdef CONFIG_KSU
118+
+__attribute__((hot))
119+
+extern int ksu_handle_stat(int *dfd, const char __user **filename_user,
120+
+ int *flags);
121+
+#endif
122+
+
123+
#if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
124+
SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename,
125+
struct stat __user *, statbuf, int, flag)
126+
@@ -408,6 +414,9 @@ SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename,
127+
struct kstat stat;
128+
int error;
129+
130+
+#ifdef CONFIG_KSU
131+
+ ksu_handle_stat(&dfd, &filename, &flag);
132+
+#endif
133+
error = vfs_fstatat(dfd, filename, &stat, flag);
134+
if (error)
135+
return error;
136+
@@ -559,6 +568,9 @@ SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename,
137+
struct kstat stat;
138+
int error;
139+
140+
+#ifdef CONFIG_KSU // 32-bit su
141+
+ ksu_handle_stat(&dfd, &filename, &flag);
142+
+#endif
143+
error = vfs_fstatat(dfd, filename, &stat, flag);
144+
if (error)
145+
return error;
146+
--
147+
2.34.1
148+

0 commit comments

Comments
 (0)