Skip to content

Commit

Permalink
throne_tracker: remove racy workqueue and call do_update_uid() synchr…
Browse files Browse the repository at this point in the history
…onously

If rename system-call is preempted after ksu_update_uid_work is queued,
packages.list.tmp may still exist and do_update_uid() may read outdated
packages.list.

Avoid this and simply call do_update_uid() synchronously.

With APK caching, overhead is considerably lower. Plus, performing user
I/O from a separate asynchronous workqueue is discouraged.

Signed-off-by: Juhyung Park <[email protected]>
  • Loading branch information
arter97 committed May 22, 2024
1 parent 9945dcc commit 3129698
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions kernel/throne_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <linux/string.h>
#include <linux/types.h>
#include <linux/version.h>
#include <linux/workqueue.h>

#include "allowlist.h"
#include "klog.h" // IWYU pragma: keep
Expand All @@ -16,8 +15,7 @@

uid_t ksu_manager_uid = KSU_INVALID_UID;

#define SYSTEM_PACKAGES_LIST_PATH "/data/system/packages.list"
static struct work_struct ksu_update_uid_work;
#define SYSTEM_PACKAGES_LIST_PATH "/data/system/packages.list.tmp"

struct uid_data {
struct list_head list;
Expand Down Expand Up @@ -277,14 +275,13 @@ static bool is_uid_exist(uid_t uid, char *package, void *data)
return exist;
}

static void do_update_uid(struct work_struct *work)
void track_throne()
{
struct file *fp =
ksu_filp_open_compat(SYSTEM_PACKAGES_LIST_PATH, O_RDONLY, 0);
if (IS_ERR(fp)) {
pr_err("do_update_uid, open " SYSTEM_PACKAGES_LIST_PATH
" failed: %ld\n",
PTR_ERR(fp));
pr_err("%s: open " SYSTEM_PACKAGES_LIST_PATH " failed: %ld\n",
__func__, PTR_ERR(fp));
return;
}

Expand Down Expand Up @@ -371,14 +368,9 @@ static void do_update_uid(struct work_struct *work)
}
}

void track_throne()
{
ksu_queue_work(&ksu_update_uid_work);
}

void ksu_throne_tracker_init()
{
INIT_WORK(&ksu_update_uid_work, do_update_uid);
// nothing to do
}

void ksu_throne_tracker_exit()
Expand Down

0 comments on commit 3129698

Please sign in to comment.