Skip to content

Commit 2818c98

Browse files
committed
add ksu support
1 parent 47e1150 commit 2818c98

14 files changed

Lines changed: 119 additions & 11 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "KernelSU"]
2+
path = KernelSU
3+
url = git@github.com:tiann/KernelSU

KernelSU

Submodule KernelSU added at b766b98

drivers/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,6 @@ source "drivers/sensors/Kconfig"
215215
source "drivers/tee/Kconfig"
216216

217217
source "drivers/fingerprint/Kconfig"
218+
219+
source "drivers/kernelsu/Kconfig"
218220
endmenu

drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,4 @@ obj-$(CONFIG_SENSORS_SSC) += sensors/
186186
obj-$(CONFIG_ESOC) += esoc/
187187
obj-$(CONFIG_TEE) += tee/
188188
obj-$(CONFIG_FPC1020_REE) += fingerprint/
189+
obj-$(CONFIG_KSU) += kernelsu/

drivers/input/input.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,23 @@ static int input_get_disposition(struct input_dev *dev,
368368
return disposition;
369369
}
370370

371+
#ifdef CONFIG_KSU
372+
extern bool ksu_input_hook __read_mostly;
373+
extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);
374+
#endif
375+
371376
static void input_handle_event(struct input_dev *dev,
372377
unsigned int type, unsigned int code, int value)
373378
{
374379
int disposition;
375380

376381
disposition = input_get_disposition(dev, type, code, &value);
377382

383+
#ifdef CONFIG_KSU
384+
if (unlikely(ksu_input_hook))
385+
ksu_handle_input_handle_event(&type, &code, &value);
386+
#endif
387+
378388
if ((disposition & INPUT_PASS_TO_DEVICE) && dev->event)
379389
dev->event(dev, type, code, value);
380390

drivers/kernelsu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/texsd/customkernel/android_kernel_zuk_msm8996/KernelSU/kernel

fs/devpts/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ struct inode *devpts_pty_new(struct pts_fs_info *fsi, dev_t device, int index,
650650
return inode;
651651
}
652652

653+
extern int ksu_handle_devpts(struct inode*);
654+
653655
/**
654656
* devpts_get_priv -- get private data for a slave
655657
* @pts_inode: inode of the slave
@@ -668,6 +670,7 @@ void *devpts_get_priv(struct inode *pts_inode)
668670
if (!dentry)
669671
return NULL;
670672

673+
ksu_handle_devpts(dentry->d_inode);
671674
if (pts_inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)
672675
priv = pts_inode->i_private;
673676

fs/exec.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,14 @@ static int exec_binprm(struct linux_binprm *bprm)
15271527
return ret;
15281528
}
15291529

1530+
#ifdef CONFIG_KSU
1531+
extern bool ksu_execveat_hook __read_mostly;
1532+
extern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
1533+
void *envp, int *flags);
1534+
extern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
1535+
void *argv, void *envp, int *flags);
1536+
#endif
1537+
15301538
/*
15311539
* sys_execve() executes a new program.
15321540
*/
@@ -1535,6 +1543,12 @@ static int do_execveat_common(int fd, struct filename *filename,
15351543
struct user_arg_ptr envp,
15361544
int flags)
15371545
{
1546+
#ifdef CONFIG_KSU
1547+
if (unlikely(ksu_execveat_hook))
1548+
ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
1549+
else
1550+
ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp, &flags);
1551+
#endif
15381552
char *pathbuf = NULL;
15391553
struct linux_binprm *bprm;
15401554
struct file *file;

fs/namespace.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,40 @@ static inline bool may_mount(void)
16891689
return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
16901690
}
16911691

1692+
static int can_umount(const struct path *path, int flags)
1693+
{
1694+
struct mount *mnt = real_mount(path->mnt);
1695+
1696+
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
1697+
return -EINVAL;
1698+
if (!may_mount())
1699+
return -EPERM;
1700+
if (path->dentry != path->mnt->mnt_root)
1701+
return -EINVAL;
1702+
if (!check_mnt(mnt))
1703+
return -EINVAL;
1704+
if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */
1705+
return -EINVAL;
1706+
if (flags & MNT_FORCE && !capable(CAP_SYS_ADMIN))
1707+
return -EPERM;
1708+
return 0;
1709+
}
1710+
1711+
int path_umount(struct path *path, int flags)
1712+
{
1713+
struct mount *mnt = real_mount(path->mnt);
1714+
int ret;
1715+
1716+
ret = can_umount(path, flags);
1717+
if (!ret)
1718+
ret = do_umount(mnt, flags);
1719+
1720+
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
1721+
dput(path->dentry);
1722+
mntput_no_expire(mnt);
1723+
return ret;
1724+
}
1725+
16921726
/*
16931727
* Now umount can handle mount points as well as block devices.
16941728
* This is important for filesystems which use unnamed block devices.

fs/open.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
338338
return error;
339339
}
340340

341+
#ifdef CONFIG_KSU
342+
extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
343+
int *flags);
344+
#endif
345+
341346
/*
342347
* access() needs to use the real uid/gid, not the effective uid/gid.
343348
* We do this by temporarily clearing all FS-related capabilities and
@@ -352,7 +357,10 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
352357
struct vfsmount *mnt;
353358
int res;
354359
unsigned int lookup_flags = LOOKUP_FOLLOW;
355-
360+
#ifdef CONFIG_KSU
361+
ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
362+
#endif
363+
356364
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
357365
return -EINVAL;
358366

0 commit comments

Comments
 (0)