From c108a8ed326077b45ff18492bd15e2d3e38c4aec Mon Sep 17 00:00:00 2001 From: backslashxx <118538522+backslashxx@users.noreply.github.com> Date: Wed, 11 Jun 2025 11:47:30 +0800 Subject: [PATCH] kernel: throne_tracker: harden track_throne_function file read this probably wont happen, but just to make sure, we dont block the rename now so there is really a chance that this does not exist yet when the kthread runs. Signed-off-by: backslashxx <118538522+backslashxx@users.noreply.github.com> --- kernel/throne_tracker.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/kernel/throne_tracker.c b/kernel/throne_tracker.c index d83f2d88..547b6a20 100644 --- a/kernel/throne_tracker.c +++ b/kernel/throne_tracker.c @@ -305,13 +305,24 @@ static bool is_uid_exist(uid_t uid, char *package, void *data) void track_throne() { - struct file *fp = - ksu_filp_open_compat(SYSTEM_PACKAGES_LIST_PATH, O_RDONLY, 0); + struct file *fp; + int tries = 0; + + while (tries++ < 10) { + fp = ksu_filp_open_compat(SYSTEM_PACKAGES_LIST_PATH, O_RDONLY, 0); + if (!IS_ERR(fp)) // success, file exists + break; + + pr_info("%s: waiting for %s\n", __func__, SYSTEM_PACKAGES_LIST_PATH); + schedule(); // maybe enough, otherwise, add delay? + msleep(100); // migth as well add a delay + }; + if (IS_ERR(fp)) { - pr_err("%s: open " SYSTEM_PACKAGES_LIST_PATH " failed: %ld\n", - __func__, PTR_ERR(fp)); + pr_err("%s: open " SYSTEM_PACKAGES_LIST_PATH " failed: %ld\n", __func__, PTR_ERR(fp)); return; - } + } else + pr_info("%s: %s found!\n", __func__, SYSTEM_PACKAGES_LIST_PATH); struct list_head uid_list; INIT_LIST_HEAD(&uid_list);