Skip to content

Commit

Permalink
patches: Support path_umount
Browse files Browse the repository at this point in the history
  • Loading branch information
bxySo committed Jun 2, 2024
1 parent 779b268 commit d89e00b
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions patches/patches.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash
#!/usr/bin/env bash
# Patches author: weishu <[email protected]>
# Shell authon: xiaoleGun <[email protected]>
# bdqllW <[email protected]>
# Tested kernel versions: 5.4, 4.19, 4.14, 4.9
# 20240123
# 20240601

patch_files=(
fs/exec.c
fs/open.c
fs/read_write.c
fs/stat.c
fs/namespace.c
drivers/input/input.c
)

Expand All @@ -23,7 +24,6 @@ for i in "${patch_files[@]}"; do
case $i in

# fs/ changes
## exec.c
fs/exec.c)
sed -i '/static int do_execveat_common/i\#ifdef CONFIG_KSU\nextern bool ksu_execveat_hook __read_mostly;\nextern int ksu_handle_execveat(int *fd, struct filename **filename_ptr, void *argv,\n void *envp, int *flags);\nextern int ksu_handle_execveat_sucompat(int *fd, struct filename **filename_ptr,\n void *argv, void *envp, int *flags);\n#endif' fs/exec.c
if grep -q "return __do_execve_file(fd, filename, argv, envp, flags, NULL);" fs/exec.c; then
Expand All @@ -33,7 +33,6 @@ for i in "${patch_files[@]}"; do
fi
;;

## open.c
fs/open.c)
if grep -q "long do_faccessat(int dfd, const char __user \*filename, int mode)" fs/open.c; then
sed -i '/long do_faccessat(int dfd, const char __user \*filename, int mode)/i\#ifdef CONFIG_KSU\nextern int ksu_handle_faccessat(int *dfd, const char __user **filename_user, int *mode,\n int *flags);\n#endif' fs/open.c
Expand All @@ -43,18 +42,16 @@ for i in "${patch_files[@]}"; do
sed -i '/if (mode & ~S_IRWXO)/i\ #ifdef CONFIG_KSU\n ksu_handle_faccessat(&dfd, &filename, &mode, NULL);\n #endif\n' fs/open.c
;;

## read_write.c
fs/read_write.c)
sed -i '/ssize_t vfs_read(struct file/i\#ifdef CONFIG_KSU\nextern bool ksu_vfs_read_hook __read_mostly;\nextern int ksu_handle_vfs_read(struct file **file_ptr, char __user **buf_ptr,\n size_t *count_ptr, loff_t **pos);\n#endif' fs/read_write.c
sed -i '/ssize_t vfs_read(struct file/,/ssize_t ret;/{/ssize_t ret;/a\
#ifdef CONFIG_KSU\
if (unlikely(ksu_vfs_read_hook))\
ksu_handle_vfs_read(&file, &buf, &count, &pos);\
#endif
#ifdef CONFIG_KSU\
if (unlikely(ksu_vfs_read_hook))\
ksu_handle_vfs_read(&file, &buf, &count, &pos);\
#endif
}' fs/read_write.c
;;

## stat.c
fs/stat.c)
if grep -q "int vfs_statx(int dfd, const char __user \*filename, int flags," fs/stat.c; then
sed -i '/int vfs_statx(int dfd, const char __user \*filename, int flags,/i\#ifdef CONFIG_KSU\nextern int ksu_handle_stat(int *dfd, const char __user **filename_user, int *flags);\n#endif' fs/stat.c
Expand All @@ -65,8 +62,47 @@ for i in "${patch_files[@]}"; do
fi
;;

fs/namespace.c)
sed -i '/int ksys_umount(char __user \*name, int flags)/i \
#ifdef CONFIG_KSU\
static int can_umount(const struct path *path, int flags)\
{\
struct mount *mnt = real_mount(path->mnt);\
\
if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))\
return -EINVAL;\
if (!may_mount())\
return -EPERM;\
if (path->dentry != path->mnt->mnt_root)\
return -EINVAL;\
if (!check_mnt(mnt))\
return -EINVAL;\
if (mnt->mnt.mnt_flags & MNT_LOCKED) /* Check optimistically */\
return -EINVAL;\
if (flags & MNT_FORCE && !capable(CAP_SYS_ADMIN))\
return -EPERM;\
return 0;\
}\
\
int path_umount(struct path *path, int flags)\
{\
struct mount *mnt = real_mount(path->mnt);\
int ret;\
\
ret = can_umount(path, flags);\
if (!ret)\
ret = do_umount(mnt, flags);\
\
/* we must not call path_put() as that would clear mnt_expiry_mark */\
dput(path->dentry);\
mntput_no_expire(mnt);\
return ret;\
}\
#endif\
' fs/namespace.c
;;

# drivers/input changes
## input.c
drivers/input/input.c)
sed -i '/static void input_handle_event/i\#ifdef CONFIG_KSU\nextern bool ksu_input_hook __read_mostly;\nextern int ksu_handle_input_handle_event(unsigned int *type, unsigned int *code, int *value);\n#endif\n' drivers/input/input.c
sed -i '/int disposition = input_get_disposition(dev, type, code, &value);/a\ #ifdef CONFIG_KSU\n if (unlikely(ksu_input_hook))\n ksu_handle_input_handle_event(&type, &code, &value);\n #endif' drivers/input/input.c
Expand Down

0 comments on commit d89e00b

Please sign in to comment.