Skip to content

Commit

Permalink
ksu: patches: 4.19: add patches
Browse files Browse the repository at this point in the history
yes i still stay patching like this instead of kprobes so what
  • Loading branch information
fukiame committed Oct 15, 2023
1 parent 99763da commit c79e5ea
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ksu/patches/4.19/0001-fs-exec-add-ksu-execveat-hook.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 7fa742485f463ab9fcda4f4b191b901ed90becbf Mon Sep 17 00:00:00 2001
From: fukiame <fukiame@proton.me>
Date: Tue, 29 Aug 2023 21:29:32 +0700
Subject: [PATCH 1/5] fs/exec: add ksu execveat hook

---
fs/exec.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/fs/exec.c b/fs/exec.c
index 82d552981719..99841313cf0f 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1718,6 +1718,13 @@ 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.
*/
@@ -1726,6 +1733,12 @@ static int __do_execve_file(int fd, struct filename *filename,
struct user_arg_ptr envp,
int flags, struct file *file)
{
+
+ if (unlikely(ksu_execveat_hook))
+ ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
+ else
+ ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp, &flags);
+
char *pathbuf = NULL;
struct linux_binprm *bprm;
struct files_struct *displaced;
--
2.42.0

36 changes: 36 additions & 0 deletions ksu/patches/4.19/0002-fs-open-add-ksu-faccessat-hook.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From 728cb2b2aed7058cfcf7eeee31af6a16dbeb791f Mon Sep 17 00:00:00 2001
From: fukiame <fukiame@proton.me>
Date: Tue, 29 Aug 2023 21:30:52 +0700
Subject: [PATCH 2/5] fs/open: add ksu faccessat hook

---
fs/open.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/fs/open.c b/fs/open.c
index b14aef04ee01..ba3a3eb48841 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -348,6 +348,10 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
return ksys_fallocate(fd, mode, offset, len);
}

+
+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
@@ -363,6 +367,8 @@ long do_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;

--
2.42.0

32 changes: 32 additions & 0 deletions ksu/patches/4.19/0003-fs-read_write-add-ksu-vfs_read-hook.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From 0bacf4088928e19cbbd1c2dcaefaeb4df3a0d941 Mon Sep 17 00:00:00 2001
From: fukiame <fukiame@proton.me>
Date: Tue, 29 Aug 2023 21:31:22 +0700
Subject: [PATCH 3/5] fs/read_write: add ksu vfs_read hook

---
fs/read_write.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/read_write.c b/fs/read_write.c
index 650fc7e0f3a6..46c83623f6b8 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -434,8 +434,15 @@ 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)
{
+ if (unlikely(ksu_vfs_read_hook))
+ ksu_handle_vfs_read(&file, &buf, &count, &pos);
+
ssize_t ret;

if (!(file->f_mode & FMODE_READ))
--
2.42.0

34 changes: 34 additions & 0 deletions ksu/patches/4.19/0004-fs-stat-add-ksu-vfs_statx-hook.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 85389bb5681c3299d1c972c657108265d4863b8e Mon Sep 17 00:00:00 2001
From: fukiame <fukiame@proton.me>
Date: Tue, 29 Aug 2023 21:32:00 +0700
Subject: [PATCH 4/5] fs/stat: add ksu vfs_statx hook

---
fs/stat.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/stat.c b/fs/stat.c
index f8e6fb2c3657..e4ea28fddfe7 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -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
@@ -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;
--
2.42.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 912b54f5ae25502ce405ee8c1ca78b872777f93c Mon Sep 17 00:00:00 2001
From: fukiame <fukiame@proton.me>
Date: Tue, 29 Aug 2023 21:38:12 +0700
Subject: [PATCH 5/5] drivers/input/input: add ksu input_handle_event hook

---
drivers/input/input.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 57072d5a6ae0..566f97ba4313 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -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);

--
2.42.0

0 comments on commit c79e5ea

Please sign in to comment.