Skip to content

Commit

Permalink
support umount modules for 4.4 or higher Non-GKI kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
CZB666-wdnmd committed Mar 10, 2024
1 parent 22a1276 commit d79982a
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion kernel/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "linux/fs.h"
#include "linux/namei.h"
#include "linux/rcupdate.h"
#include "../../fs/mount.h"

#include "allowlist.h"
#include "arch.h"
Expand All @@ -32,6 +33,48 @@

static bool ksu_module_mounted = false;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)

#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
extern inline bool may_mount(void);
extern inline int check_mnt(struct mount *mnt);
extern void mntput_no_expire(struct mount *mnt);
extern int do_umount(struct mount *mnt, int flags);
static inline bool ksu_path_mounted(const struct path *path){
return path->mnt->mnt_root == path->dentry;
}
static int ksu_can_umount(const struct path *path, int flags){
struct mount *mnt = real_mount(path->mnt);

if (!may_mount())
return -EPERM;
if (!ksu_path_mounted(path))
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;
}
static int ksu_path_umount(struct path *path, int flags){
struct mount *mnt = real_mount(path->mnt);
int ret;

ret = ksu_can_umount(path, flags);
if (!ret)
ret = do_umount(mnt, flags);

/* we mustn't call path_put() as that would clear mnt_expiry_mark */
dput(path->dentry);
mntput_no_expire(mnt);
return ret;
}
#else
//not tested
#endif

extern int handle_sepolicy(unsigned long arg3, void __user *arg4);

static inline bool is_allow_su()
Expand Down Expand Up @@ -509,8 +552,13 @@ static void ksu_umount_mnt(struct path *path, int flags)
if (err) {
pr_info("umount %s failed: %d\n", path->dentry->d_iname, err);
}
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)
int err = ksu_path_umount(path, flags);
if (err) {
pr_info("umount %s failed: %d\n", path->dentry->d_iname, err);
}
#else
// TODO: umount for non GKI kernel
//not tested
#endif
}

Expand Down

1 comment on commit d79982a

@bemerguy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this fix the kernel being recognized as rootable? lol
my kernel isn't gki

Please sign in to comment.