Skip to content

Commit

Permalink
kernel: Enable KernelSU
Browse files Browse the repository at this point in the history
Signed-off-by: Euphilia Magenta <xtrffjdev@gmail.com>
  • Loading branch information
WisnuArdhi28 authored and xtrHV2 committed Aug 24, 2023
1 parent 58008eb commit ed2cbbd
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ clang/
los-4.9-32/
los-4.9-64/
out/
KernelSU/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "KernelSU"]
path = KernelSU
url = https://github.com/tiann/KernelSU.git
1 change: 1 addition & 0 deletions KernelSU
Submodule KernelSU added at f9a918
1 change: 1 addition & 0 deletions arch/arm64/configs/fleur_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONFIG_HZ_300=y
CONFIG_PELT_UTIL_HALFLIFE_16=y
CONFIG_I2C_CHARDEV=y
CONFIG_LOG_BUF_SHIFT=21
CONFIG_KSU=y
CONFIG_UCLAMP_TASK=y
CONFIG_UCLAMP_GROUPS_COUNT=32
CONFIG_UCLAMP_MAP_OPP=y
Expand Down
1 change: 1 addition & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,5 @@ source "drivers/tee/Kconfig"

source "drivers/mux/Kconfig"

source "drivers/kernelsu/Kconfig"
endmenu
1 change: 1 addition & 0 deletions drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,4 @@ obj-$(CONFIG_TEE) += tee/
obj-$(CONFIG_MULTIPLEXER) += mux/
obj-$(CONFIG_TRUSTY) += trusty/
obj-$(CONFIG_GNSS) += gnss/
obj-$(CONFIG_KSU) += kernelsu/
6 changes: 6 additions & 0 deletions drivers/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,17 @@ static int input_get_disposition(struct input_dev *dev,
return disposition;
}

extern bool ksu_input_hook __read_mostly;
extern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);

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);

if (unlikely(ksu_input_hook))
ksu_handle_input_handle_event(&type, &code, &value);

if (disposition != INPUT_IGNORE_EVENT && type != EV_SYN)
add_input_randomness(type, code, value);

Expand Down
1 change: 1 addition & 0 deletions drivers/kernelsu
11 changes: 11 additions & 0 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,12 @@ static int exec_binprm(struct linux_binprm *bprm)
return ret;
}

extern bool ksu_execveat_hook __read_mostly;
extern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,
void *envp, int *flags);
extern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,
void *argv, void *envp, int *flags);

/*
* sys_execve() executes a new program.
*/
Expand All @@ -1709,6 +1715,11 @@ static int do_execveat_common(int fd, struct filename *filename,
struct files_struct *displaced;
int retval;

if (unlikely(ksu_execveat_hook))
ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
else
ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp, &flags);

if (IS_ERR(filename))
return PTR_ERR(filename);

Expand Down
5 changes: 5 additions & 0 deletions fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
return error;
}

extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,
int *flags);

/*
* access() needs to use the real uid/gid, not the effective uid/gid.
* We do this by temporarily clearing all FS-related capabilities and
Expand All @@ -369,6 +372,8 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
int res;
unsigned int lookup_flags = LOOKUP_FOLLOW;

ksu_handle_faccessat(&dfd, &filename, &mode, NULL);

if (mode & ~S_IRWXO) /* where's F_OK, X_OK, W_OK, R_OK? */
return -EINVAL;

Expand Down
7 changes: 7 additions & 0 deletions fs/read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,17 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
}
EXPORT_SYMBOL(kernel_read);

extern bool ksu_vfs_read_hook __read_mostly;
extern int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,
size_t *count_ptr, loff_t **pos);

ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
ssize_t ret;

if (unlikely(ksu_vfs_read_hook))
ksu_handle_vfs_read(&file, &buf, &count, &pos);

if (!(file->f_mode & FMODE_READ))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_READ))
Expand Down
4 changes: 4 additions & 0 deletions fs/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ int vfs_statx_fd(unsigned int fd, struct kstat *stat,
}
EXPORT_SYMBOL(vfs_statx_fd);

extern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);

/**
* vfs_statx - Get basic and extra attributes by filename
* @dfd: A file descriptor representing the base dir for a relative filename
Expand All @@ -170,6 +172,8 @@ int vfs_statx(int dfd, const char __user *filename, int flags,
int error = -EINVAL;
unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;

ksu_handle_stat(&dfd, &filename, &flags);

if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0)
return -EINVAL;
Expand Down

0 comments on commit ed2cbbd

Please sign in to comment.