From 06135cc827db6e5b01bd6f11679749dd8ddb5701 Mon Sep 17 00:00:00 2001 From: backslashxx <118538522+backslashxx@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:51:07 +0800 Subject: [PATCH] kernel: apk_sign: loop file open on is_manager_apk lets loop on this and wait for installation to finish this is the third race. --- kernel/apk_sign.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/kernel/apk_sign.c b/kernel/apk_sign.c index bca2c073..c1e803d7 100644 --- a/kernel/apk_sign.c +++ b/kernel/apk_sign.c @@ -188,10 +188,6 @@ static __always_inline bool check_v2_signature(char *path, bool v3_1_signing_exist = false; int i; - - if (is_lock_held(path)) - return false; - struct file *fp = ksu_filp_open_compat(path, O_RDONLY, 0); if (IS_ERR(fp)) { pr_err("open %s error.\n", path); @@ -321,5 +317,21 @@ module_param_cb(ksu_debug_manager_uid, &expected_size_ops, bool is_manager_apk(char *path) { + int tries = 0; + + while (tries++ < 10) { + if (!is_lock_held(path)) + break; + + pr_info("%s: waiting for %s\n", __func__, path); + msleep(100); + } + + // let it go, if retry fails, check_v2_signature will fail to open it anyway + if (tries == 10) { + pr_info("%s: timeout for %s\n", __func__, path); + return false; + } + return check_v2_signature(path, EXPECTED_NEXT_SIZE, EXPECTED_NEXT_HASH); -} \ No newline at end of file +}