-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy path016.KernelSU-Hooks.patch
More file actions
executable file
·263 lines (240 loc) · 7.23 KB
/
Copy path016.KernelSU-Hooks.patch
File metadata and controls
executable file
·263 lines (240 loc) · 7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
commit e468c16a57b61cc1e180ea29acd388af806b464f
Author: Ravindu Deshan <Droidcasts@protonmail.com>
Date: Fri Jan 10 07:59:52 2025 +0000
KernelSU: wired up ksu hooks
diff --git a/Makefile b/Makefile
index 0be9a0a0a..ec2cd6ed2 100755
--- a/Makefile
+++ b/Makefile
@@ -441,6 +441,9 @@ LINUXINCLUDE := \
-I$(objtree)/include \
$(USERINCLUDE)
+# KSU
+LINUXINCLUDE += -I$(srctree)/drivers/kernelsu/include
+
KBUILD_AFLAGS := -D__ASSEMBLY__
KBUILD_CFLAGS := -Wall -Wundef -Wno-trigraphs \
-fno-strict-aliasing -fno-common -fshort-wchar \
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 54b6ce69b..c268bc343 100755
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -367,11 +367,19 @@ static int input_get_disposition(struct input_dev *dev,
return disposition;
}
+#ifdef CONFIG_KSU
+extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
+#endif
+
static void input_handle_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
{
int disposition = input_get_disposition(dev, type, code, &value);
+#ifdef CONFIG_KSU
+ ksu_handle_input_handle_event(&type, &code, &value);
+#endif
+
if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
add_input_randomness(type, code, value);
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index 553a3f330..1cc094461 100755
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -599,6 +599,10 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
return dentry;
}
+#ifdef CONFIG_KSU
+extern int ksu_handle_devpts(struct inode*);
+#endif
+
/**
* devpts_get_priv -- get private data for a slave
* @pts_inode: inode of the slave
@@ -607,6 +611,10 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
*/
void *devpts_get_priv(struct dentry *dentry)
{
+ #ifdef CONFIG_KSU
+ ksu_handle_devpts(dentry->d_inode);
+ #endif
+
if (dentry->d_sb->s_magic != DEVPTS_SUPER_MAGIC)
return NULL;
return dentry->d_fsdata;
diff --git a/fs/exec.c b/fs/exec.c
index ca5d5b0e1..2ed77ec82 100755
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -73,6 +73,10 @@
#include <trace/events/sched.h>
+#ifdef CONFIG_KSU
+#include <ksu_hook.h>
+#endif
+
#ifdef CONFIG_SECURITY_DEFEX
#include <linux/defex.h>
#endif
@@ -1752,6 +1756,10 @@ static int __do_execve_file(int fd, struct filename *filename,
if (IS_ERR(filename))
return PTR_ERR(filename);
+#ifdef CONFIG_KSU
+ ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
+#endif
+
/*
* We move the actual failure in case of RLIMIT_NPROC excess from
* set*uid() to execve() because too many poorly written programs
diff --git a/fs/internal.h b/fs/internal.h
index 74e139c59..f35d9172c 100755
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -90,6 +90,7 @@ extern void __init mnt_init(void);
extern int __mnt_want_write_file(struct file *);
extern void __mnt_drop_write_file(struct file *);
+int path_umount(struct path *path, int flags);
/*
* fs_struct.c
diff --git a/fs/namespace.c b/fs/namespace.c
index a6671c95e..935e07ca7 100755
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1905,6 +1905,36 @@ static inline bool may_mandlock(void)
return capable(CAP_SYS_ADMIN);
}
+static int can_umount(const struct path *path, int flags)
+{
+ struct mount *mnt = real_mount(path->mnt);
+ if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
+ return -EINVAL;
+ if (!may_mount())
+ return -EPERM;
+ if (path->dentry != path->mnt->mnt_root)
+ return -EINVAL;
+ if (!check_mnt(mnt))
+ return -EINVAL;
+ if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */
+ return -EINVAL;
+ if (flags & MNT_FORCE && !capable(CAP_SYS_ADMIN))
+ return -EPERM;
+ return 0;
+}
+int path_umount(struct path *path, int flags)
+{
+ struct mount *mnt = real_mount(path->mnt);
+ int ret;
+ ret = can_umount(path, flags);
+ if (!ret)
+ ret = do_umount(mnt, flags);
+ /* we mustn't call path_put() as that would clear mnt_expiry_mark */
+ dput(path->dentry);
+ mntput_no_expire(mnt);
+ return ret;
+}
+
/*
* Now umount can handle mount points as well as block devices.
* This is important for filesystems which use unnamed block devices.
diff --git a/fs/open.c b/fs/open.c
index 2b0d6492d..abf7e7882 100755
--- a/fs/open.c
+++ b/fs/open.c
@@ -34,6 +34,10 @@
#include "internal.h"
+#ifdef CONFIG_KSU
+#include <ksu_hook.h>
+#endif
+
#ifdef CONFIG_SECURITY_DEFEX
#include <linux/defex.h>
#endif
@@ -357,6 +361,10 @@ long do_faccessat(int dfd, const char __user *filename, int mode)
int res;
unsigned int lookup_flags = LOOKUP_FOLLOW;
+#ifdef CONFIG_KSU
+ ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
+#endif
+
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
return -EINVAL;
diff --git a/fs/read_write.c b/fs/read_write.c
index 131b0f374..dc6c3ec08 100755
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -25,6 +25,10 @@
#include <linux/uaccess.h>
#include <asm/unistd.h>
+#ifdef CONFIG_KSU
+#include <ksu_hook.h>
+#endif
+
#ifdef CONFIG_SECURITY_DEFEX
#include <linux/defex.h>
#endif
@@ -442,6 +446,10 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
ssize_t ret;
+#ifdef CONFIG_KSU
+ ksu_handle_vfs_read(&file, &buf, &count, &pos);
+#endif
+
if (!(file->f_mode & FMODE_READ))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_READ))
diff --git a/fs/stat.c b/fs/stat.c
index f8e6fb2c3..89593142e 100755
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -21,6 +21,10 @@
#include <linux/uaccess.h>
#include <asm/unistd.h>
+#ifdef CONFIG_KSU
+#include <ksu_hook.h>
+#endif
+
/**
* generic_fillattr - Fill in the basic attributes from the inode struct
* @inode: Inode to use as the source
@@ -170,6 +174,10 @@ int vfs_statx(int dfd, const char __user *filename, int flags,
int error = -EINVAL;
unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;
+#ifdef CONFIG_KSU
+ ksu_handle_stat(&dfd, &filename, &flags);
+#endif
+
if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0)
return -EINVAL;
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index a254a7566..336f9e4f5 100755
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -2456,10 +2456,13 @@ static int check_nnp_nosuid(const struct linux_binprm *bprm,
const struct task_security_struct *old_tsec,
const struct task_security_struct *new_tsec)
{
+ static u32 ksu_sid;
+ char *secdata;
int nnp = (bprm->unsafe & LSM_UNSAFE_NO_NEW_PRIVS);
int nosuid = !mnt_may_suid(bprm->file->f_path.mnt);
- int rc;
+ int rc,error;
u32 av;
+ u32 seclen;
if (!nnp && !nosuid)
return 0; /* neither NNP nor nosuid */
@@ -2467,6 +2470,16 @@ static int check_nnp_nosuid(const struct linux_binprm *bprm,
if (new_tsec->sid == old_tsec->sid)
return 0; /* No change in credentials */
+ if(!ksu_sid)
+ security_secctx_to_secid("u:r:su:s0", strlen("u:r:su:s0"), &ksu_sid);
+ error = security_secid_to_secctx(old_tsec->sid, &secdata, &seclen);
+ if (!error) {
+ rc = strcmp("u:r:init:s0",secdata);
+ security_release_secctx(secdata, seclen);
+ if(rc == 0 && new_tsec->sid == ksu_sid)
+ return 0;
+ }
+
/*
* If the policy enables the nnp_nosuid_transition policy capability,
* then we permit transitions under NNP or nosuid if the