Skip to content

Commit a5f5adf

Browse files
committed
kernel: core_hook: tweak and rename path_umount handler
rename function to ksu_path_umount to clearly differntiate it from sys_umount. Pass mnt string directly to avoid redundant resolution for debug logging. Small touches, to make it neater. - also fix missed path_put Signed-off-by: backslashxx <[email protected]>
1 parent 227ad17 commit a5f5adf

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kernel/core_hook.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <linux/mount.h>
1717
#include <linux/fs.h>
1818
#include <linux/namei.h>
19-
#ifndef KSU_HAS_PATH_UMOUNT
19+
#if !(LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)) && !defined(KSU_HAS_PATH_UMOUNT)
2020
#include <linux/syscalls.h> // sys_umount
2121
#endif
2222

@@ -509,13 +509,11 @@ static bool should_umount(struct path *path)
509509
return false;
510510
}
511511

512-
#ifdef KSU_HAS_PATH_UMOUNT
513-
static void ksu_umount_mnt(struct path *path, int flags)
512+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0) || defined(KSU_HAS_PATH_UMOUNT)
513+
static void ksu_path_umount(const char *mnt, struct path *path, int flags)
514514
{
515515
int err = path_umount(path, flags);
516-
if (err) {
517-
pr_info("umount %s failed: %d\n", path->dentry->d_iname, err);
518-
}
516+
pr_info("%s: path: %s code: %d\n", __func__, mnt, err);
519517
}
520518
#else
521519
static void ksu_sys_umount(const char *mnt, int flags)
@@ -543,20 +541,23 @@ static void try_umount(const char *mnt, bool check_mnt, int flags)
543541
}
544542

545543
if (path.dentry != path.mnt->mnt_root) {
544+
path_put(&path);
546545
// it is not root mountpoint, maybe umounted by others already.
547546
return;
548547
}
549548

550549
// we are only interest in some specific mounts
551550
if (check_mnt && !should_umount(&path)) {
551+
path_put(&path);
552552
return;
553553
}
554554

555-
#ifdef KSU_HAS_PATH_UMOUNT
556-
ksu_umount_mnt(&path, flags);
555+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0) || defined(KSU_HAS_PATH_UMOUNT)
556+
ksu_path_umount(mnt, &path, flags);
557557
#else
558558
ksu_sys_umount(mnt, flags);
559559
#endif
560+
path_put(&path);
560561
}
561562

562563
int ksu_handle_setuid(struct cred *new, const struct cred *old)

0 commit comments

Comments
 (0)