Skip to content

Commit 81da296

Browse files
committed
Add KernelSU Next to the kernel
Signed-off-by: IverCoder <ivercoder@proton.me>
1 parent 4332ae2 commit 81da296

File tree

11 files changed

+112
-3
lines changed

11 files changed

+112
-3
lines changed

arch/arm64/configs/a3core_eur_open_defconfig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ CONFIG_SLUB_CPU_PARTIAL=y
237237
CONFIG_SYSTEM_DATA_VERIFICATION=y
238238
CONFIG_PROFILING=y
239239
CONFIG_TRACEPOINTS=y
240-
CONFIG_KPROBES=y
240+
# CONFIG_KPROBES is not set
241241
CONFIG_JUMP_LABEL=y
242242
# CONFIG_STATIC_KEYS_SELFTEST is not set
243243
# CONFIG_UPROBES is not set
244244
# CONFIG_HAVE_64BIT_ALIGNED_ACCESS is not set
245245
CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y
246246
CONFIG_KRETPROBES=y
247-
CONFIG_HAVE_KPROBES=y
247+
# CONFIG_HAVE_KPROBES is not set
248248
CONFIG_HAVE_KRETPROBES=y
249249
CONFIG_HAVE_ARCH_TRACEHOOK=y
250250
CONFIG_HAVE_DMA_CONTIGUOUS=y
@@ -4201,6 +4201,15 @@ CONFIG_SEC_QPNP_PON_SPARE_BITS=7
42014201
# CONFIG_SEC_QUEST_UEFI_USER is not set
42024202
# CONFIG_SEC_QUEST_DDR_SCAN_USER is not set
42034203

4204+
#
4205+
# KernelSU
4206+
#
4207+
CONFIG_KSU=y
4208+
# CONFIG_KSU_KPROBES_HOOK is not set
4209+
# CONFIG_KSU_DEBUG is not set
4210+
# CONFIG_KSU_ALLOWLIST_WORKAROUND is not set
4211+
CONFIG_KSU_LSM_SECURITY_HOOKS=y
4212+
42044213
#
42054214
# Firmware Drivers
42064215
#
@@ -4601,7 +4610,7 @@ CONFIG_BRANCH_PROFILE_NONE=y
46014610
# CONFIG_PROFILE_ALL_BRANCHES is not set
46024611
# CONFIG_STACK_TRACER is not set
46034612
# CONFIG_BLK_DEV_IO_TRACE is not set
4604-
CONFIG_KPROBE_EVENTS=y
4613+
# CONFIG_KPROBE_EVENTS is not set
46054614
# CONFIG_UPROBE_EVENTS is not set
46064615
CONFIG_BPF_EVENTS=y
46074616
CONFIG_PROBE_EVENTS=y

drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,5 @@ source "drivers/mux/Kconfig"
218218
source "drivers/trusty/Kconfig"
219219

220220
source "drivers/samsung/Kconfig"
221+
source "drivers/kernelsu/Kconfig"
221222
endmenu

drivers/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,5 @@ obj-$(CONFIG_TEE) += tee/
188188
obj-$(CONFIG_MULTIPLEXER) += mux/
189189
obj-$(CONFIG_TRUSTY) += trusty/
190190
obj-$(CONFIG_GNSS) += gnss/
191+
192+
obj-$(CONFIG_KSU) += kernelsu/

drivers/input/input.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,21 @@ static int input_get_disposition(struct input_dev *dev,
367367
return disposition;
368368
}
369369

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

380+
#ifdef CONFIG_KSU
381+
if (unlikely(ksu_input_hook))
382+
ksu_handle_input_handle_event(&type, &code, &value);
383+
#endif
384+
375385
if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
376386
add_input_randomness(type, code, value);
377387

drivers/kernelsu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../KernelSU-Next/kernel

fs/devpts/inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,10 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
602602
return dentry;
603603
}
604604

605+
#ifdef CONFIG_KSU
606+
extern int ksu_handle_devpts(struct inode*);
607+
#endif
608+
605609
/**
606610
* devpts_get_priv -- get private data for a slave
607611
* @pts_inode: inode of the slave
@@ -610,6 +614,9 @@ struct dentry *devpts_pty_new(struct pts_fs_info *fsi, int index, void *priv)
610614
*/
611615
void *devpts_get_priv(struct dentry *dentry)
612616
{
617+
#ifdef CONFIG_KSU
618+
ksu_handle_devpts(dentry->d_inode);
619+
#endif
613620
if (dentry->d_sb->s_magic != DEVPTS_SUPER_MAGIC)
614621
return NULL;
615622
return dentry->d_fsdata;

fs/exec.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,14 @@ static int exec_binprm(struct linux_binprm *bprm)
16901690
return ret;
16911691
}
16921692

1693+
#ifdef CONFIG_KSU
1694+
extern bool ksu_execveat_hook __read_mostly;
1695+
extern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
1696+
void *envp, int *flags);
1697+
extern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
1698+
void *argv, void *envp, int *flags);
1699+
#endif
1700+
16931701
/*
16941702
* sys_execve() executes a new program.
16951703
*/
@@ -1704,6 +1712,13 @@ static int do_execveat_common(int fd, struct filename *filename,
17041712
struct files_struct *displaced;
17051713
int retval;
17061714

1715+
#ifdef CONFIG_KSU
1716+
if (unlikely(ksu_execveat_hook))
1717+
ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
1718+
else
1719+
ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp, &flags);
1720+
#endif
1721+
17071722
if (IS_ERR(filename))
17081723
return PTR_ERR(filename);
17091724

fs/namespace.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,42 @@ static inline bool may_mandlock(void)
17831783
return capable(CAP_SYS_ADMIN);
17841784
}
17851785

1786+
#ifdef CONFIG_KSU
1787+
static int can_umount(const struct path *path, int flags)
1788+
{
1789+
struct mount *mnt = real_mount(path->mnt);
1790+
1791+
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
1792+
return -EINVAL;
1793+
if (!may_mount())
1794+
return -EPERM;
1795+
if (path->dentry != path->mnt->mnt_root)
1796+
return -EINVAL;
1797+
if (!check_mnt(mnt))
1798+
return -EINVAL;
1799+
if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */
1800+
return -EINVAL;
1801+
if (flags & MNT_FORCE && !capable(CAP_SYS_ADMIN))
1802+
return -EPERM;
1803+
return 0;
1804+
}
1805+
1806+
int path_umount(struct path *path, int flags)
1807+
{
1808+
struct mount *mnt = real_mount(path->mnt);
1809+
int ret;
1810+
1811+
ret = can_umount(path, flags);
1812+
if (!ret)
1813+
ret = do_umount(mnt, flags);
1814+
1815+
/* we mustn't call path_put() as that would clear mnt_expiry_mark */
1816+
dput(path->dentry);
1817+
mntput_no_expire(mnt);
1818+
return ret;
1819+
}
1820+
#endif
1821+
17861822
/*
17871823
* Now umount can handle mount points as well as block devices.
17881824
* This is important for filesystems which use unnamed block devices.

fs/open.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
354354
return error;
355355
}
356356

357+
#ifdef CONFIG_KSU
358+
extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
359+
int *flags);
360+
#endif
361+
357362
/*
358363
* access() needs to use the real uid/gid, not the effective uid/gid.
359364
* We do this by temporarily clearing all FS-related capabilities and
@@ -369,6 +374,10 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
369374
int res;
370375
unsigned int lookup_flags = LOOKUP_FOLLOW;
371376

377+
#ifdef CONFIG_KSU
378+
ksu_handle_faccessat(&dfd, &filename, &mode, NULL);
379+
#endif
380+
372381
if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
373382
return -EINVAL;
374383

fs/read_write.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,21 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
429429
}
430430
EXPORT_SYMBOL(kernel_read);
431431

432+
#ifdef CONFIG_KSU
433+
extern bool ksu_vfs_read_hook __read_mostly;
434+
extern int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,
435+
size_t *count_ptr, loff_t **pos);
436+
#endif
437+
432438
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
433439
{
434440
ssize_t ret;
435441

442+
#ifdef CONFIG_KSU
443+
if (unlikely(ksu_vfs_read_hook))
444+
ksu_handle_vfs_read(&file, &buf, &count, &pos);
445+
#endif
446+
436447
if (!(file->f_mode & FMODE_READ))
437448
return -EBADF;
438449
if (!(file->f_mode & FMODE_CAN_READ))

0 commit comments

Comments
 (0)