Skip to content

Commit 109442f

Browse files
committed
docs: Add devpts description for non gki
1 parent a943528 commit 109442f

File tree

3 files changed

+101
-32
lines changed

3 files changed

+101
-32
lines changed

kernel/sucompat.c

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,37 @@ int ksu_handle_execve_sucompat(int *fd, const char __user **filename_user,
168168
return 0;
169169
}
170170

171+
int ksu_handle_devpts(struct inode *inode)
172+
{
173+
if (!current->mm) {
174+
return 0;
175+
}
176+
177+
uid_t uid = current_uid().val;
178+
if (uid % 100000 < 10000) {
179+
// not untrusted_app, ignore it
180+
return 0;
181+
}
182+
183+
if (!ksu_is_allow_uid(uid))
184+
return 0;
185+
186+
if (ksu_devpts_sid) {
187+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
188+
struct inode_security_struct *sec = selinux_inode(inode);
189+
#else
190+
struct inode_security_struct *sec = (struct inode_security_struct *) inode->i_security;
191+
#endif
192+
if (sec) {
193+
sec->sid = ksu_devpts_sid;
194+
inode->i_uid.val = 0;
195+
inode->i_gid.val = 0;
196+
}
197+
}
198+
199+
return 0;
200+
}
201+
171202
#ifdef CONFIG_KPROBES
172203

173204
__maybe_unused static int faccessat_handler_pre(struct kprobe *p,
@@ -292,19 +323,6 @@ static struct kprobe execve_kp = {
292323

293324
static int devpts_get_priv_pre(struct kprobe *p, struct pt_regs *regs)
294325
{
295-
if (!current->mm) {
296-
return 0;
297-
}
298-
299-
uid_t uid = current_uid().val;
300-
if (uid % 100000 < 10000) {
301-
// not untrusted_app, ignore it
302-
return 0;
303-
}
304-
305-
if (!ksu_is_allow_uid(uid))
306-
return 0;
307-
308326
struct inode *inode;
309327
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
310328
struct dentry *dentry = (struct dentry *)PT_REGS_PARM1(regs);
@@ -313,16 +331,7 @@ static int devpts_get_priv_pre(struct kprobe *p, struct pt_regs *regs)
313331
inode = (struct inode *)PT_REGS_PARM1(real_regs);
314332
#endif
315333

316-
if (ksu_devpts_sid) {
317-
struct inode_security_struct *sec = selinux_inode(inode);
318-
if (sec) {
319-
sec->sid = ksu_devpts_sid;
320-
inode->i_uid.val = 0;
321-
inode->i_gid.val = 0;
322-
}
323-
}
324-
325-
return 0;
334+
return ksu_handle_devpts(inode);
326335
}
327336

328337
static struct kprobe devpts_get_priv_kp = { .symbol_name = "devpts_get_priv",

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ index 2ff887661237..e758d7db7663 100644
264264
return -EINVAL;
265265
```
266266

267+
### Safe Mode
268+
267269
To enable KernelSU's builtin SafeMode, You should also modify `input_handle_event` in `drivers/input/input.c`:
268270

269271
:::tip
@@ -297,6 +299,38 @@ index 45306f9ef247..815091ebfca4 100755
297299
add_input_randomness(type, code, value);
298300
```
299301

302+
:::info Entering safe mode accidiently?
303+
If you use manual integration and do not disable `CONFIG_KPROBES`, then the user may trigger safe mode by pressing the volume down button after booting! Therefore if using manual integration you need to disable `CONFIG_KPROBES`!
304+
:::
305+
306+
### Failed to execute `pm` in terminal?
307+
308+
You should modify `fs/devpts/inode.c`, reference:
309+
310+
```diff
311+
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
312+
index 32f6f1c68..d69d8eca2 100644
313+
--- a/fs/devpts/inode.c
314+
+++ b/fs/devpts/inode.c
315+
@@ -602,6 +602,8 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
316+
return dentry;
317+
}
318+
319+
+extern int ksu_handle_devpts(struct inode*);
320+
+
321+
/**
322+
* devpts_get_priv -- get private data for a slave
323+
* @pts_inode: inode of the slave
324+
@@ -610,6 +612,7 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
325+
*/
326+
void *devpts_get_priv(struct dentry *dentry)
327+
{
328+
+ ksu_handle_devpts(dentry->d_inode);
329+
if (dentry->d_sb->s_magic != DEVPTS_SUPER_MAGIC)
330+
return NULL;
331+
return dentry->d_fsdata;
332+
```
333+
300334
### How to backport path_umount
301335

302336
You can get module umount feature working on pre-GKI kernels by manually backporting `path_umount` from 5.9. You can use this patch as reference:
@@ -347,7 +381,3 @@ You can get module umount feature working on pre-GKI kernels by manually backpor
347381
```
348382

349383
Finally, build your kernel again, KernelSU should work well.
350-
351-
:::info Entering safe mode accidiently?
352-
If you use manual integration and do not disable `CONFIG_KPROBES`, then the user may trigger safe mode by pressing the volume down button after booting! Therefore if using manual integration you need to disable `CONFIG_KPROBES`!
353-
:::

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,18 @@ index 2ff887661237..e758d7db7663 100644
258258
return -EINVAL;
259259
```
260260

261+
### 安全模式
262+
261263
要使用 KernelSU 内置的安全模式,你还需要修改 `drivers/input/input.c` 中的 `input_handle_event` 方法:
262264

263265
:::tip
264266
强烈建议开启此功能,对用户救砖会非常有帮助!
265267
:::
266268

269+
:::info 莫名其妙进入安全模式?
270+
如果你采用手动集成的方式,并且没有禁用`CONFIG_KPROBES`,那么用户在开机之后按音量下,也可能触发安全模式!因此如果使用手动集成,你需要关闭 `CONFIG_KPROBES`
271+
:::
272+
267273
```diff
268274
diff --git a/drivers/input/input.c b/drivers/input/input.c
269275
index 45306f9ef247..815091ebfca4 100755
@@ -291,7 +297,35 @@ index 45306f9ef247..815091ebfca4 100755
291297
add_input_randomness(type, code, value);
292298
```
293299

294-
### 如何backport(向旧版本移植) path_umount {#how-to-backport-path-umount}
300+
### pm 命令执行失败?
301+
302+
你需要同时修改 `fs/devpts/inode.c`,补丁如下:
303+
304+
```diff
305+
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
306+
index 32f6f1c68..d69d8eca2 100644
307+
--- a/fs/devpts/inode.c
308+
+++ b/fs/devpts/inode.c
309+
@@ -602,6 +602,8 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
310+
return dentry;
311+
}
312+
313+
+extern int ksu_handle_devpts(struct inode*);
314+
+
315+
/**
316+
* devpts_get_priv -- get private data for a slave
317+
* @pts_inode: inode of the slave
318+
@@ -610,6 +612,7 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
319+
*/
320+
void *devpts_get_priv(struct dentry *dentry)
321+
{
322+
+ ksu_handle_devpts(dentry->d_inode);
323+
if (dentry->d_sb->s_magic != DEVPTS_SUPER_MAGIC)
324+
return NULL;
325+
return dentry->d_fsdata;
326+
```
327+
328+
### path_umount {#how-to-backport-path-umount}
295329

296330
你可以通过从K5.9向旧版本移植`path_umount`,在GKI之前的内核上获得卸载模块的功能。你可以通过以下补丁作为参考:
297331

@@ -341,7 +375,3 @@ index 45306f9ef247..815091ebfca4 100755
341375
```
342376

343377
改完之后重新编译内核即可。
344-
345-
:::info 莫名其妙进入安全模式?
346-
如果你采用手动集成的方式,并且没有禁用`CONFIG_KPROBES`,那么用户在开机之后按音量下,也可能触发安全模式!因此如果使用手动集成,你需要关闭 `CONFIG_KPROBES`
347-
:::

0 commit comments

Comments
 (0)