kernel: Prune allowlist only after boot completed

For unknown reason, packages.list is not reliable during boot for oplus
devices, so we have to disable pruning and re-run pruning after boot.
This commit is contained in:
Wang Han
2025-11-12 21:43:02 +08:00
committed by ShirkNeko
parent 4c04508267
commit 0c9ebb9bad
5 changed files with 15 additions and 3 deletions

View File

@@ -18,6 +18,7 @@
#endif
#include "klog.h" // IWYU pragma: keep
#include "ksud.h"
#include "selinux/selinux.h"
#include "allowlist.h"
#include "manager.h"
@@ -500,6 +501,11 @@ void ksu_prune_allowlist(bool (*is_uid_valid)(uid_t, char *, void *),
struct perm_data *np = NULL;
struct perm_data *n = NULL;
if (!ksu_boot_completed) {
pr_info("boot not completed, skip prune\n");
return;
}
bool modified = false;
// TODO: use RCU!
mutex_lock(&allowlist_mutex);

View File

@@ -36,6 +36,7 @@
#ifndef CONFIG_KSU_SUSFS
#include "syscall_hook_manager.h"
#endif // #ifndef CONFIG_KSU_SUSFS
#include "throne_tracker.h"
bool ksu_module_mounted __read_mostly = false;
bool ksu_boot_completed __read_mostly = false;
@@ -140,6 +141,7 @@ void on_module_mounted(void){
void on_boot_completed(void){
ksu_boot_completed = true;
pr_info("on_boot_completed!\n");
track_throne(true);
#ifndef CONFIG_KSU_SUSFS
// remark process, we don't want to mark other init
// forked process excepte zygote and adbd

View File

@@ -36,7 +36,7 @@ static KSU_DECL_FSNOTIFY_OPS(ksu_handle_generic_event)
if (ksu_uid_scanner_enabled) {
ksu_request_userspace_scan();
}
track_throne();
track_throne(false);
}
return 0;
}

View File

@@ -428,7 +428,7 @@ static bool is_uid_exist(uid_t uid, char *package, void *data)
return exist;
}
void track_throne(void)
void track_throne(bool prune_only)
{
struct list_head uid_list;
struct uid_data *np, *n;
@@ -505,6 +505,9 @@ void track_throne(void)
}
uid_ready:
if (prune_only)
goto prune;
// first, check if manager_uid exist!
list_for_each_entry(np, &uid_list, list) {
if (np->uid == current_manager_uid) {
@@ -548,6 +551,7 @@ uid_ready:
pr_info("Manager search finished\n");
}
prune:
// then prune the allowlist
ksu_prune_allowlist(is_uid_exist, &uid_list);
out:

View File

@@ -5,6 +5,6 @@ void ksu_throne_tracker_init(void);
void ksu_throne_tracker_exit(void);
void track_throne(void);
void track_throne(bool prune_only);
#endif