kernel: Utilise the existing try_umount to avoid repackaging

This commit is contained in:
ShirkNeko
2025-11-15 19:29:12 +08:00
parent cd21af6728
commit 46846dce91
4 changed files with 8 additions and 56 deletions

View File

@@ -71,7 +71,7 @@ static void ksu_umount_mnt(struct path *path, int flags)
}
}
static void try_umount(const char *mnt, bool check_mnt, int flags)
void try_umount(const char *mnt, bool check_mnt, int flags)
{
struct path path;
int err = kern_path(mnt, 0, &path);

View File

@@ -6,6 +6,8 @@
void ksu_kernel_umount_init(void);
void ksu_kernel_umount_exit(void);
void try_umount(const char *mnt, bool check_mnt, int flags);
// Handler function to be called from setresuid hook
int ksu_handle_umount(uid_t old_uid, uid_t new_uid);

View File

@@ -1,4 +1,3 @@
#include "umount_manager.h"
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/uaccess.h>
@@ -6,29 +5,19 @@
#include <linux/path.h>
#include <linux/mount.h>
#include <linux/cred.h>
#include "klog.h"
#include "kernel_umount.h"
#include "umount_manager.h"
static struct umount_manager g_umount_mgr = {
.entry_count = 0,
.max_entries = 64,
};
extern int path_umount(struct path *path, int flags);
static bool check_path_busy(const char *path)
static void try_umount_path(struct umount_entry *entry)
{
struct path kpath;
int err;
err = kern_path(path, 0, &kpath);
if (err) {
return false;
}
bool busy = (kpath.mnt->mnt_root != kpath.dentry);
path_put(&kpath);
return busy;
try_umount(entry->path, entry->check_mnt, entry->flags);
}
static struct umount_entry *find_entry_locked(const char *path)
@@ -196,44 +185,6 @@ out:
return ret;
}
bool ksu_umount_path_is_busy(const char *path)
{
return check_path_busy(path);
}
static void try_umount_path(struct umount_entry *entry)
{
struct path kpath;
int err;
err = kern_path(entry->path, 0, &kpath);
if (err) {
return;
}
if (kpath.dentry != kpath.mnt->mnt_root) {
path_put(&kpath);
return;
}
if (entry->check_mnt) {
if (kpath.mnt && kpath.mnt->mnt_sb && kpath.mnt->mnt_sb->s_type) {
const char *fstype = kpath.mnt->mnt_sb->s_type->name;
if (strcmp(fstype, "overlay") != 0) {
path_put(&kpath);
return;
}
}
}
err = path_umount(&kpath, entry->flags);
if (err) {
pr_info("umount %s failed: %d\n", entry->path, err);
}
path_put(&kpath);
}
void ksu_umount_manager_execute_all(const struct cred *cred)
{
struct umount_entry *entry;

View File

@@ -59,7 +59,6 @@ int ksu_umount_manager_init(void);
void ksu_umount_manager_exit(void);
int ksu_umount_manager_add(const char *path, bool check_mnt, int flags, bool is_default);
int ksu_umount_manager_remove(const char *path);
bool ksu_umount_path_is_busy(const char *path);
void ksu_umount_manager_execute_all(const struct cred *cred);
int ksu_umount_manager_get_entries(struct ksu_umount_entry_info __user *entries, u32 *count);
int ksu_umount_manager_clear_custom(void);