Skip to content

Commit 9d2a473

Browse files
committed
kernel: sucompat: sucompat toggle support for non-kp (tiann#2506)
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 likely unneeded, It keeps feature parity to non-kprobe builds. adapted from upstream: kernel: Allow to re-enable sucompat - tiann@4593ae8 Rejected: tiann#2506 Signed-off-by: backslashxx <[email protected]>
1 parent bdd0b50 commit 9d2a473

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

kernel/sucompat.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
extern void escape_to_root();
2727

28+
static bool ksu_sucompat_non_kp __read_mostly = true;
29+
2830
static void __user *userspace_stack_buffer(const void *d, size_t len)
2931
{
3032
/* To avoid having to mmap a page in userspace, just write below the stack
@@ -53,6 +55,10 @@ int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
5355
{
5456
const char su[] = SU_PATH;
5557

58+
if (!ksu_sucompat_non_kp) {
59+
return 0;
60+
}
61+
5662
if (!ksu_is_allow_uid(current_uid().val)) {
5763
return 0;
5864
}
@@ -74,6 +80,10 @@ int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags)
7480
// const char sh[] = SH_PATH;
7581
const char su[] = SU_PATH;
7682

83+
if (!ksu_sucompat_non_kp) {
84+
return 0;
85+
}
86+
7787
if (!ksu_is_allow_uid(current_uid().val)) {
7888
return 0;
7989
}
@@ -103,6 +113,10 @@ int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
103113
const char sh[] = KSUD_PATH;
104114
const char su[] = SU_PATH;
105115

116+
if (!ksu_sucompat_non_kp){
117+
return 0;
118+
}
119+
106120
if (unlikely(!filename_ptr))
107121
return 0;
108122

@@ -132,6 +146,10 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
132146
const char su[] = SU_PATH;
133147
char path[sizeof(su) + 1];
134148

149+
if (!ksu_sucompat_non_kp){
150+
return 0;
151+
}
152+
135153
if (unlikely(!filename_user))
136154
return 0;
137155

@@ -154,6 +172,10 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
154172

155173
int ksu_handle_devpts(struct inode *inode)
156174
{
175+
if (!ksu_sucompat_non_kp) {
176+
return 0;
177+
}
178+
157179
if (!current->mm) {
158180
return 0;
159181
}
@@ -185,8 +207,12 @@ int ksu_handle_devpts(struct inode *inode)
185207
// sucompat: permited process can execute 'su' to gain root access.
186208
void ksu_sucompat_init()
187209
{
210+
ksu_sucompat_non_kp = true;
211+
pr_info("ksu_sucompat_init: hooks enabled: execve/execveat_su, faccessat, stat, devpts\n");
188212
}
189213

190214
void ksu_sucompat_exit()
191215
{
216+
ksu_sucompat_non_kp = false;
217+
pr_info("ksu_sucompat_exit: hooks disabled: execve/execveat_su, faccessat, stat, devpts\n");
192218
}

0 commit comments

Comments
 (0)