Skip to content

Commit

Permalink
patches: susfs: Add 5.4k support (v1.3.8)
Browse files Browse the repository at this point in the history
KSU hook patch for 5.4 isn't tested, feel free to submit a PR if it doesn't work ( from https://github.com/dev-sm8350/kernel_oneplus_sm8350 )
  • Loading branch information
silvzr committed Aug 13, 2024
1 parent f3b2683 commit 3b35fd6
Show file tree
Hide file tree
Showing 5 changed files with 998 additions and 70 deletions.
42 changes: 26 additions & 16 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,25 @@ if [[ $KSU_ENABLED == "true" ]] && [[ ! -z "$KERNELSU_DIR" ]]; then

cp ./patches/KernelSU/Backport/safe_mode_ksu.patch $KERNEL_DIR/
cd $KERNEL_DIR && patch -p1 < safe_mode_ksu.patch
msg "Backporting KSU safe mode..." && cd $WORKDIR
msg "Backporting KSU safe mode..."

if [[ -d "$KERNEL_DIR/$KERNELSU_DIR/kernel" ]]; then
cp ./patches/KernelSU/SuSFS/enable_susfs_for_ksu_auto.patch $KERNEL_DIR/$KERNELSU_DIR/
cd $KERNEL_DIR/$KERNELSU_DIR && patch -p1 < enable_susfs_for_ksu_auto.patch
else
cp ./patches/KernelSU/SuSFS/enable_susfs_for_ksu_manual.patch $KERNEL_DIR/$KERNELSU_DIR/
cd $KERNEL_DIR/$KERNELSU_DIR && patch -p1 < enable_susfs_for_ksu_manual.patch
fi
if [[ ! -f "$KERNEL_DIR/fs/susfs.c" || ! -f "$KERNEL_DIR/include/linux/susfs.h" ]]; then
cd $WORKDIR
if [[ -d "$KERNEL_DIR/$KERNELSU_DIR/kernel" ]]; then
cp ./patches/KernelSU/SuSFS/enable_susfs_for_ksu_auto.patch $KERNEL_DIR/$KERNELSU_DIR/
cd $KERNEL_DIR/$KERNELSU_DIR && patch -p1 < enable_susfs_for_ksu_auto.patch
else
cp ./patches/KernelSU/SuSFS/enable_susfs_for_ksu_manual.patch $KERNEL_DIR/$KERNELSU_DIR/
cd $KERNEL_DIR/$KERNELSU_DIR && patch -p1 < enable_susfs_for_ksu_manual.patch
fi
msg "Importing SuSFS into KSU source..." && cd $WORKDIR

cp ./patches/KernelSU/SuSFS/add_susfs_in_kernel-$KERNEL_VER.patch $KERNEL_DIR/
cp ./patches/KernelSU/SuSFS/susfs.c $KERNEL_DIR/fs/
cp ./patches/KernelSU/SuSFS/susfs.h $KERNEL_DIR/include/linux/
cd $KERNEL_DIR && patch -p1 -F 3 < add_susfs_in_kernel-$KERNEL_VER.patch
msg "Importing SuSFS for $KERNEL_VER kernel..."
cp ./patches/KernelSU/SuSFS/add_susfs_in_kernel-$KERNEL_VER.patch $KERNEL_DIR/
cp ./patches/KernelSU/SuSFS/susfs.c $KERNEL_DIR/fs/
cp ./patches/KernelSU/SuSFS/susfs.h $KERNEL_DIR/include/linux/
cd $KERNEL_DIR && patch -p1 -F 3 < add_susfs_in_kernel-$KERNEL_VER.patch
msg "Importing SuSFS for $KERNEL_VER kernel..."
fi

echo "CONFIG_KSU=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KSU_SUSFS=y" >> $DEVICE_DEFCONFIG_FILE
Expand Down Expand Up @@ -225,9 +228,16 @@ elif
cd $KERNEL_DIR && patch -p1 < add_susfs_in_kernel-$KERNEL_VER.patch
msg "Importing SuSFS into $KERNEL_VER kernel..."

echo "CONFIG_KSU=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KSU_SUSFS=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KPROBES=n" >> $DEVICE_DEFCONFIG_FILE # it will conflict with KSU hooks if it's on
if [[ ! -f "$WORKDIR/patches/KernelSU/Backport/hook_patches_ksu-$KERNEL_VER.patch" ]]; then
echo "CONFIG_KPROBES=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_HAVE_KPROBES=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KPROBE_EVENTS=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KSU_SUSFS=y" >> $DEVICE_DEFCONFIG_FILE
else
echo "CONFIG_KSU=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KSU_SUSFS=y" >> $DEVICE_DEFCONFIG_FILE
echo "CONFIG_KPROBES=n" >> $DEVICE_DEFCONFIG_FILE # it will conflict with KSU hooks if it's on
fi

KSU_GIT_VERSION=$(cd KernelSU && git rev-list --count HEAD)
KERNELSU_VERSION=$(($KSU_GIT_VERSION + 10200))
Expand Down
103 changes: 103 additions & 0 deletions patches/KernelSU/Backport/hook_patches_ksu-5.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
5.4 KernelSU Hook Patch
* Make sure to disable CONFIG_KPROBE in your device's defconfig

--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1897,11 +1897,25 @@ static int __do_execve_file(int fd, struct filename *filename,
return retval;
}

+#ifdef CONFIG_KSU
+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);
+#endif
static int do_execveat_common(int fd, struct filename *filename,
struct user_arg_ptr argv,
struct user_arg_ptr envp,
int flags)
{
+#ifdef CONFIG_KSU
+ if (unlikely(ksu_execveat_hook))
+ ksu_handle_execveat(&fd, &filename, &argv, &envp, &flags);
+ else
+ ksu_handle_execveat_sucompat(&fd, &filename, &argv, &envp,
+ &flags);
+#endif
return __do_execve_file(fd, filename, argv, envp, flags, NULL);
}

--- a/fs/open.c
+++ b/fs/open.c
@@ -340,6 +340,10 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
return ksys_fallocate(fd, mode, offset, len);
}

+#ifdef CONFIG_KSU
+extern int ksu_handle_faccessat(int *dfd, const char __user **filename_user,
+ int *mode, int *flags);
+#endif
/*
* access() needs to use the real uid/gid, not the effective uid/gid.
* We do this by temporarily clearing all FS-related capabilities and
@@ -354,6 +358,10 @@ long do_faccessat(int dfd, const char __user *filename, int mode)
int res;
unsigned int lookup_flags = LOOKUP_FOLLOW;

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

--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -443,10 +443,20 @@ ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
}
EXPORT_SYMBOL_NS(kernel_read, ANDROID_GKI_VFS_EXPORT_ONLY);

+#ifdef CONFIG_KSU
+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);
+#endif
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
{
ssize_t ret;

+#ifdef CONFIG_KSU
+ if (unlikely(ksu_vfs_read_hook))
+ ksu_handle_vfs_read(&file, &buf, &count, &pos);
+#endif
+
if (!(file->f_mode & FMODE_READ))
return -EBADF;
if (!(file->f_mode & FMODE_CAN_READ))
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -150,6 +150,10 @@ int vfs_statx_fd(unsigned int fd, struct kstat *stat,
}
EXPORT_SYMBOL(vfs_statx_fd);

+#ifdef CONFIG_KSU
+extern int ksu_handle_stat(int *dfd, const char __user **filename_user,
+ int *flags);
+#endif
/**
* vfs_statx - Get basic and extra attributes by filename
* @dfd: A file descriptor representing the base dir for a relative filename
@@ -172,6 +176,10 @@ int vfs_statx(int dfd, const char __user *filename, int flags,
int error = -EINVAL;
unsigned int lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;

+#ifdef CONFIG_KSU
+ ksu_handle_stat(&dfd, &filename, &flags);
+#endif
+
if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT |
AT_EMPTY_PATH | KSTAT_QUERY_FLAGS)) != 0)
return -EINVAL;

Loading

0 comments on commit 3b35fd6

Please sign in to comment.