Skip to content

Commit 199f5cc

Browse files
小さい猫F-19-FScirese
authored
fix some typos introduced in #166 (#181)
Signed-off-by: Ookiineko <[email protected]> Co-authored-by: f19 <[email protected]> Co-authored-by: Scirese <[email protected]>
1 parent 962649f commit 199f5cc

File tree

6 files changed

+90
-24
lines changed

6 files changed

+90
-24
lines changed

kernel/kernel_compat.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#ifndef __KSU_H_KERNEL_COMPAT
2+
#define __KSU_H_KERNEL_COMPAT
3+
14
#include "linux/fs.h"
5+
26
extern ssize_t kernel_read_compat(struct file *p, void* buf, size_t count, loff_t *pos);
3-
extern ssize_t kernel_write_compat(struct file *p, const void *buf, size_t count, loff_t *pos);
7+
extern ssize_t kernel_write_compat(struct file *p, const void *buf, size_t count, loff_t *pos);
8+
#endif

kernel/ksud.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,9 @@ static int read_handler_pre(struct kprobe *p, struct pt_regs *regs)
212212
static struct kprobe execve_kp = {
213213
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
214214
.symbol_name = "do_execveat_common",
215-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) && \
216-
LINUX_VERSION_CODE < KERNEL_VERSION(5, 9, 0)
215+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
217216
.symbol_name = "__do_execve_file",
218-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
219-
LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)
217+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
220218
.symbol_name = "do_execveat_common",
221219
#endif
222220
.pre_handler = execve_handler_pre,

kernel/selinux/selinux.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,36 +53,51 @@ if (!is_domain_permissive) {
5353

5454
void setenforce(bool enforce)
5555
{
56-
#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 14, 0)
5756
#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
57+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
5858
selinux_state.enforcing = enforce;
59-
#endif
6059
#else
61-
selinux_enabled = enforce;
60+
selinux_enabled = enforce;
61+
#endif
6262
#endif
6363
}
6464

6565
bool getenforce()
6666
{
67-
#if LINUX_VERSION_CODE > KERNEL_VERSION(4, 14, 0)
6867
#ifdef CONFIG_SECURITY_SELINUX_DISABLE
68+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
6969
if (selinux_state.disabled) {
70+
#else
71+
if (selinux_disabled) {
72+
#endif
7073
return false;
7174
}
7275
#endif
7376

7477
#ifdef CONFIG_SECURITY_SELINUX_DEVELOP
78+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
7579
return selinux_state.enforcing;
7680
#else
77-
return false;
81+
return selinux_enabled;
7882
#endif
7983
#else
80-
return selinux_enabled;
84+
return true;
8185
#endif
86+
}
8287

88+
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
89+
/*
90+
* get the subjective security ID of the current task
91+
*/
92+
static inline u32 current_sid(void)
93+
{
94+
const struct task_security_struct *tsec = current_security();
95+
96+
return tsec->sid;
8397
}
98+
#endif
8499

85100
bool is_ksu_domain()
86101
{
87102
return ksu_sid && current_sid() == ksu_sid;
88-
}
103+
}

kernel/sucompat.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,15 @@ static int faccessat_handler_pre(struct kprobe *p, struct pt_regs *regs)
134134

135135
static int newfstatat_handler_pre(struct kprobe *p, struct pt_regs *regs)
136136
{
137-
// static int vfs_statx(int dfd, const char __user *filename, int flags,struct kstat *stat, u32 request_mask)
138137
int *dfd = (int *)&PT_REGS_PARM1(regs);
139138
const char __user **filename_user = (const char **)&PT_REGS_PARM2(regs);
140-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
139+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
140+
// static int vfs_statx(int dfd, const char __user *filename, int flags, struct kstat *stat, u32 request_mask)
141141
int *flags = (int *)&PT_REGS_PARM3(regs);
142142
#else
143143
// int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,int flag)
144144
int *flags = (int *)&PT_REGS_PARM4(regs);
145145
#endif
146-
147146

148147
return ksu_handle_stat(dfd, filename_user, flags);
149148
}
@@ -172,25 +171,20 @@ static struct kprobe faccessat_kp = {
172171
};
173172

174173
static struct kprobe newfstatat_kp = {
175-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
174+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
176175
.symbol_name = "vfs_statx",
177176
#else
178-
.symbol_name = "vfs_fstatat",
177+
.symbol_name = "vfs_fstatat",
179178
#endif
180179
.pre_handler = newfstatat_handler_pre,
181180
};
182181

183182
static struct kprobe execve_kp = {
184183
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
185184
.symbol_name = "do_execveat_common",
186-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) && \
187-
LINUX_VERSION_CODE < KERNEL_VERSION(5, 9, 0)
185+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0)
188186
.symbol_name = "__do_execve_file",
189-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) && \
190-
LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)
191-
.symbol_name = "do_execveat_common",
192-
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) && \
193-
LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
187+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
194188
.symbol_name = "do_execveat_common",
195189
#endif
196190
.pre_handler = execve_handler_pre,

website/docs/guide/how-to-integrate-for-non-gki.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,31 @@ You should found the four functions in kernel source:
142142
3. vfs_read, usually in `fs/read_write.c`
143143
4. vfs_statx, usually in `fs/stat.c`
144144

145+
If your kernel does not have the `vfs_statx`, use `vfs_fstatat` instead:
146+
147+
```diff
148+
diff --git a/fs/stat.c b/fs/stat.c
149+
index 068fdbcc9e26..5348b7bb9db2 100644
150+
--- a/fs/stat.c
151+
+++ b/fs/stat.c
152+
@@ -87,6 +87,8 @@ int vfs_fstat(unsigned int fd, struct kstat *stat)
153+
}
154+
EXPORT_SYMBOL(vfs_fstat);
155+
156+
+extern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);
157+
+
158+
int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,
159+
int flag)
160+
{
161+
@@ -94,6 +96,8 @@ int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,
162+
int error = -EINVAL;
163+
unsigned int lookup_flags = 0;
164+
165+
+ ksu_handle_stat(&dfd, &filename, &flag);
166+
+
167+
if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
168+
AT_EMPTY_PATH)) != 0)
169+
goto out;
170+
```
171+
145172
Finally, build your kernel again, KernelSU should works well.

website/docs/zh_CN/guide/how-to-integrate-for-non-gki.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,31 @@ index 376543199b5a..82adcef03ecc 100644
142142
3. vfs_read,通常位于 `fs/read_write.c`
143143
4. vfs_statx,通常位于 `fs/stat.c`
144144

145+
如果你的内核没有 `vfs_statx`, 使用 `vfs_fstatat` 来代替它:
146+
147+
```diff
148+
diff --git a/fs/stat.c b/fs/stat.c
149+
index 068fdbcc9e26..5348b7bb9db2 100644
150+
--- a/fs/stat.c
151+
+++ b/fs/stat.c
152+
@@ -87,6 +87,8 @@ int vfs_fstat(unsigned int fd, struct kstat *stat)
153+
}
154+
EXPORT_SYMBOL(vfs_fstat);
155+
156+
+extern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);
157+
+
158+
int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,
159+
int flag)
160+
{
161+
@@ -94,6 +96,8 @@ int vfs_fstatat(int dfd, const char __user *filename, struct kstat *stat,
162+
int error = -EINVAL;
163+
unsigned int lookup_flags = 0;
164+
165+
+ ksu_handle_stat(&dfd, &filename, &flag);
166+
+
167+
if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
168+
AT_EMPTY_PATH)) != 0)
169+
goto out;
170+
```
171+
145172
改完之后重新编译内核即可。

0 commit comments

Comments
 (0)