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/uaccess.h>
|
||||||
#include <linux/uidgid.h>
|
#include <linux/uidgid.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <linux/workqueue.h>
|
||||||
#include <linux/lsm_hooks.h>
|
#include <linux/lsm_hooks.h>
|
||||||
#include <linux/binfmts.h>
|
#include <linux/binfmts.h>
|
||||||
#include <linux/tty.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;
|
bool ksu_module_mounted = false;
|
||||||
|
|
||||||
|
static struct workqueue_struct *ksu_workqueue;
|
||||||
|
|
||||||
#ifdef CONFIG_COMPAT
|
#ifdef CONFIG_COMPAT
|
||||||
bool ksu_is_compat __read_mostly = false;
|
bool ksu_is_compat __read_mostly = false;
|
||||||
#endif
|
#endif
|
||||||
@@ -973,6 +976,28 @@ void susfs_try_umount_all(uid_t uid) {
|
|||||||
}
|
}
|
||||||
#endif
|
#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
|
#ifdef CONFIG_KSU_SUSFS
|
||||||
int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
int ksu_handle_setuid(struct cred *new, const struct cred *old)
|
||||||
{
|
{
|
||||||
@@ -1053,24 +1078,14 @@ do_umount:
|
|||||||
#else
|
#else
|
||||||
// fixme: use `collect_mounts` and `iterate_mount` to iterate all mountpoint and
|
// fixme: use `collect_mounts` and `iterate_mount` to iterate all mountpoint and
|
||||||
// filter the mountpoint whose target is `/data/adb`
|
// filter the mountpoint whose target is `/data/adb`
|
||||||
try_umount("/odm", true, 0);
|
struct work_struct *work = kmalloc(sizeof(struct work_struct), GFP_ATOMIC);
|
||||||
try_umount("/system", true, 0);
|
if (!work) {
|
||||||
try_umount("/vendor", true, 0);
|
pr_err("Failed to allocate work\n");
|
||||||
try_umount("/product", true, 0);
|
return 0;
|
||||||
try_umount("/system_ext", true, 0);
|
}
|
||||||
try_umount("/data/adb/modules", false, MNT_DETACH);
|
|
||||||
|
|
||||||
// try umount ksu temp path
|
INIT_WORK(work, do_umount_work);
|
||||||
try_umount("/debug_ramdisk", false, MNT_DETACH);
|
queue_work(ksu_workqueue, work);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
#endif // #ifdef CONFIG_KSU_SUSFS_TRY_UMOUNT
|
#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
|
// fixme: use `collect_mounts` and `iterate_mount` to iterate all mountpoint and
|
||||||
// filter the mountpoint whose target is `/data/adb`
|
// filter the mountpoint whose target is `/data/adb`
|
||||||
try_umount("/odm", true, 0);
|
struct work_struct *work = kmalloc(sizeof(struct work_struct), GFP_ATOMIC);
|
||||||
try_umount("/system", true, 0);
|
if (!work) {
|
||||||
try_umount("/vendor", true, 0);
|
pr_err("Failed to allocate work\n");
|
||||||
try_umount("/product", true, 0);
|
return 0;
|
||||||
try_umount("/system_ext", true, 0);
|
}
|
||||||
try_umount("/data/adb/modules", false, MNT_DETACH);
|
|
||||||
|
|
||||||
// try umount ksu temp path
|
INIT_WORK(work, do_umount_work);
|
||||||
try_umount("/debug_ramdisk", false, MNT_DETACH);
|
queue_work(ksu_workqueue, work);
|
||||||
|
|
||||||
// try umount ksu su path
|
|
||||||
try_umount("/sbin", false, MNT_DETACH);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1499,6 +1510,10 @@ __maybe_unused int ksu_kprobe_exit(void)
|
|||||||
|
|
||||||
void __init ksu_core_init(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();
|
ksu_lsm_hook_init();
|
||||||
#ifdef CONFIG_KPROBES
|
#ifdef CONFIG_KPROBES
|
||||||
int rc = ksu_kprobe_init();
|
int rc = ksu_kprobe_init();
|
||||||
@@ -1520,4 +1535,8 @@ void ksu_core_exit(void)
|
|||||||
pr_info("ksu_core_kprobe_exit\n");
|
pr_info("ksu_core_kprobe_exit\n");
|
||||||
ksu_kprobe_exit();
|
ksu_kprobe_exit();
|
||||||
#endif
|
#endif
|
||||||
|
if (ksu_workqueue) {
|
||||||
|
flush_workqueue(ksu_workqueue);
|
||||||
|
destroy_workqueue(ksu_workqueue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user