Revert "Implement workqueue for unmounting"

This commit is contained in:
ShirkNeko
2025-11-04 21:55:00 +08:00
parent 54b5fb5fdb
commit 801bcb0e1f
2 changed files with 9 additions and 62 deletions

View File

@@ -1,5 +0,0 @@
{
"files.associations": {
"selinux.h": "c"
}
}

View File

@@ -24,7 +24,6 @@
#include <linux/uaccess.h>
#include <linux/uidgid.h>
#include <linux/version.h>
#include <linux/workqueue.h>
#include <linux/binfmts.h>
#include <linux/tty.h>
@@ -63,13 +62,6 @@ static void ksu_try_escalate_for_uid(uid_t uid)
remove_pending_root(uid);
}
static struct workqueue_struct *ksu_workqueue;
struct ksu_umount_work {
struct work_struct work;
struct mnt_namespace *mnt_ns;
};
static bool ksu_kernel_umount_enabled = true;
static int kernel_umount_feature_get(u64 *value)
@@ -516,29 +508,6 @@ static void try_umount(const char *mnt, bool check_mnt, int flags)
ksu_umount_mnt(&path, flags);
}
static void do_umount_work(struct work_struct *work)
{
struct ksu_umount_work *umount_work = container_of(work, struct ksu_umount_work, work);
struct mnt_namespace *old_mnt_ns = current->nsproxy->mnt_ns;
current->nsproxy->mnt_ns = umount_work->mnt_ns;
try_umount("/odm", true, 0);
try_umount("/system", true, 0);
try_umount("/vendor", true, 0);
try_umount("/product", true, 0);
try_umount("/system_ext", true, 0);
try_umount("/data/adb/modules", false, MNT_DETACH);
// try umount ksu temp path
try_umount("/debug_ramdisk", false, MNT_DETACH);
// fixme: dec refcount
current->nsproxy->mnt_ns = old_mnt_ns;
kfree(umount_work);
}
int ksu_handle_setuid(struct cred *new, const struct cred *old)
{
if (!new || !old) {
@@ -620,22 +589,17 @@ int ksu_handle_setuid(struct cred *new, const struct cred *old)
// fixme: use `collect_mounts` and `iterate_mount` to iterate all mountpoint and
// filter the mountpoint whose target is `/data/adb`
struct ksu_umount_work *umount_work = kmalloc(sizeof(struct ksu_umount_work), GFP_ATOMIC);
if (!umount_work) {
pr_err("Failed to allocate umount_work\n");
return 0;
}
try_umount("/odm", true, 0);
try_umount("/system", true, 0);
try_umount("/vendor", true, 0);
try_umount("/product", true, 0);
try_umount("/system_ext", true, 0);
// fixme: inc refcount
umount_work->mnt_ns = current->nsproxy->mnt_ns;
try_umount("/data/adb/modules", false, MNT_DETACH);
try_umount("/data/adb/kpm", false, MNT_DETACH);
INIT_WORK(&umount_work->work, do_umount_work);
queue_work(ksu_workqueue, &umount_work->work);
get_task_struct(current); // delay fix
ksu_set_current_proc_umounted();
put_task_struct(current);
// try umount ksu temp path
try_umount("/debug_ramdisk", false, MNT_DETACH);
return 0;
}
@@ -858,14 +822,6 @@ __maybe_unused int ksu_kprobe_exit(void)
void __init ksu_core_init(void)
{
if (ksu_register_feature_handler(&kernel_umount_handler)) {
pr_err("Failed to register kernel_umount feature handler\n");
}
ksu_workqueue = alloc_workqueue("ksu_umount", WQ_UNBOUND, 0);
if (!ksu_workqueue) {
pr_err("Failed to create ksu workqueue\n");
}
#ifdef CONFIG_KPROBES
int rc = ksu_kprobe_init();
if (rc) {
@@ -885,8 +841,4 @@ void ksu_core_exit(void)
pr_info("ksu_core_exit\n");
ksu_kprobe_exit();
#endif
if (ksu_workqueue) {
flush_workqueue(ksu_workqueue);
destroy_workqueue(ksu_workqueue);
}
}