Implement workqueue for unmounting
umount schedules, so it cannot be used in kprobe context.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/uidgid.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/lsm_hooks.h>
|
||||
#include <linux/binfmts.h>
|
||||
#include <linux/tty.h>
|
||||
@@ -148,6 +149,8 @@ static inline bool is_zygote_normal_app_uid(uid_t uid)
|
||||
|
||||
bool ksu_module_mounted = false;
|
||||
|
||||
static struct workqueue_struct *ksu_workqueue;
|
||||
|
||||
#ifdef CONFIG_COMPAT
|
||||
bool ksu_is_compat __read_mostly = false;
|
||||
#endif
|
||||
@@ -973,6 +976,28 @@ void susfs_try_umount_all(uid_t uid) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void do_umount_work(struct work_struct *work)
|
||||
{
|
||||
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("/data/adb/kpm", false, MNT_DETACH, uid);
|
||||
|
||||
// try umount ksu temp path
|
||||
try_umount("/debug_ramdisk", false, MNT_DETACH);
|
||||
try_umount("/sbin", false, MNT_DETACH, uid);
|
||||
|
||||
try_umount("/system/etc/hosts", false, MNT_DETACH, uid);
|
||||
|
||||
// try umount lsposed dex2oat bins
|
||||
try_umount("/apex/com.android.art/bin/dex2oat64", false, MNT_DETACH, uid);
|
||||
try_umount("/apex/com.android.art/bin/dex2oat32", false, MNT_DETACH, uid);
|
||||
kfree(work);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_KSU_SUSFS
|
||||
int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
||||
{
|
||||
@@ -1053,24 +1078,14 @@ do_umount:
|
||||
#else
|
||||
// fixme: use `collect_mounts` and `iterate_mount` to iterate all mountpoint and
|
||||
// filter the mountpoint whose target is `/data/adb`
|
||||
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);
|
||||
struct work_struct *work = kmalloc(sizeof(struct work_struct), GFP_ATOMIC);
|
||||
if (!work) {
|
||||
pr_err("Failed to allocate work\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// try umount ksu temp path
|
||||
try_umount("/debug_ramdisk", false, MNT_DETACH);
|
||||
|
||||
try_umount("/sbin", false, MNT_DETACH, uid);
|
||||
|
||||
// try umount hosts file
|
||||
try_umount("/system/etc/hosts", false, MNT_DETACH, uid);
|
||||
|
||||
// try umount lsposed dex2oat bins
|
||||
try_umount("/apex/com.android.art/bin/dex2oat64", false, MNT_DETACH, uid);
|
||||
try_umount("/apex/com.android.art/bin/dex2oat32", false, MNT_DETACH, uid);
|
||||
INIT_WORK(work, do_umount_work);
|
||||
queue_work(ksu_workqueue, work);
|
||||
|
||||
#endif // #ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
|
||||
|
||||
@@ -1163,18 +1178,14 @@ 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`
|
||||
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);
|
||||
struct work_struct *work = kmalloc(sizeof(struct work_struct), GFP_ATOMIC);
|
||||
if (!work) {
|
||||
pr_err("Failed to allocate work\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// try umount ksu temp path
|
||||
try_umount("/debug_ramdisk", false, MNT_DETACH);
|
||||
|
||||
// try umount ksu su path
|
||||
try_umount("/sbin", false, MNT_DETACH);
|
||||
INIT_WORK(work, do_umount_work);
|
||||
queue_work(ksu_workqueue, work);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1499,6 +1510,10 @@ __maybe_unused int ksu_kprobe_exit(void)
|
||||
|
||||
void __init ksu_core_init(void)
|
||||
{
|
||||
ksu_workqueue = alloc_workqueue("ksu_umount", WQ_UNBOUND, 0);
|
||||
if (!ksu_workqueue) {
|
||||
pr_err("Failed to create ksu workqueue\n");
|
||||
}
|
||||
ksu_lsm_hook_init();
|
||||
#ifdef CONFIG_KPROBES
|
||||
int rc = ksu_kprobe_init();
|
||||
@@ -1520,4 +1535,8 @@ void ksu_core_exit(void)
|
||||
pr_info("ksu_core_kprobe_exit\n");
|
||||
ksu_kprobe_exit();
|
||||
#endif
|
||||
if (ksu_workqueue) {
|
||||
flush_workqueue(ksu_workqueue);
|
||||
destroy_workqueue(ksu_workqueue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user