From 6a6fc07cd437334a99bda15f562a20ee0654fed0 Mon Sep 17 00:00:00 2001 From: Yaroslav Zviezda Date: Wed, 14 May 2025 23:50:57 +0300 Subject: [PATCH] kernel: throne_tracker: move throne_tracker to kthread Runs throne_tracker() in kthread instead of blocking the caller. Prevents full lockup during installation and removing the manager. This also looks for manager UID in /data/system/packages.list, not /data/system/packages.list.tmp Nice additional side effect is a faster booting. Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com> Co-Authored-By: backslashxx <118538522+backslashxx@users.noreply.github.com> --- kernel/throne_tracker.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/kernel/throne_tracker.c b/kernel/throne_tracker.c index f76f01b8..9c8f9f9f 100644 --- a/kernel/throne_tracker.c +++ b/kernel/throne_tracker.c @@ -13,9 +13,13 @@ #include "throne_tracker.h" #include "kernel_compat.h" +#include +#include + uid_t ksu_manager_uid = KSU_INVALID_UID; -#define SYSTEM_PACKAGES_LIST_PATH "/data/system/packages.list.tmp" +static struct task_struct *throne_thread; +#define SYSTEM_PACKAGES_LIST_PATH "/data/system/packages.list" struct uid_data { struct list_head list; @@ -284,7 +288,7 @@ static bool is_uid_exist(uid_t uid, char *package, void *data) return exist; } -void track_throne() +static void track_throne_function() { struct file *fp = ksu_filp_open_compat(SYSTEM_PACKAGES_LIST_PATH, O_RDONLY, 0); @@ -379,6 +383,23 @@ out: } } +static int throne_tracker_thread(void *data) +{ + pr_info("%s: pid: %d started\n", __func__, current->pid); + track_throne_function(); + throne_thread = NULL; + pr_info("%s: pid: %d exit!\n", __func__, current->pid); + return 0; +} + +void track_throne() +{ + throne_thread = kthread_run(throne_tracker_thread, NULL, "throne_tracker"); + if (IS_ERR(throne_thread)) { + throne_thread = NULL; + } +} + void ksu_throne_tracker_init() { // nothing to do