kernel: add package whitelist check for manager APKs

Co-authored-by: lamadaemon <i@lama.icu>
Co-authored-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
Signed-off-by: ShirkNeko <109797057+ShirkNeko@users.noreply.github.com>
This commit is contained in:
ShirkNeko
2025-06-07 00:14:33 +08:00
parent 3b8445cdaa
commit aec76a388f
4 changed files with 47 additions and 13 deletions

View File

@@ -63,14 +63,8 @@ static int get_pkg_from_apk_path(char *pkg, const char *path)
return 0;
}
static void crown_manager(const char *apk, struct list_head *uid_data)
static void crown_manager(const char *apk, char *pkg, struct list_head *uid_data)
{
char pkg[KSU_MAX_PACKAGE_NAME];
if (get_pkg_from_apk_path(pkg, apk) < 0) {
pr_err("Failed to get package name from apk path: %s\n", apk);
return;
}
pr_info("manager pkg: %s\n", pkg);
#ifdef KSU_MANAGER_PACKAGE
@@ -192,6 +186,7 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
} else {
if ((namelen == 8) && (strncmp(name, "base.apk", namelen) == 0)) {
struct apk_path_hash *pos;
char pkg[KSU_MAX_PACKAGE_NAME];
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 8, 0)
unsigned int hash = full_name_hash(dirpath, strlen(dirpath));
#else
@@ -204,11 +199,16 @@ FILLDIR_RETURN_TYPE my_actor(struct dir_context *ctx, const char *name,
}
}
bool is_manager = is_manager_apk(dirpath);
if (get_pkg_from_apk_path(pkg, dirpath) < 0) {
pr_err("Failed to get package name from apk path: %s\n", dirpath);
return FILLDIR_ACTOR_CONTINUE;
}
bool is_manager = is_manager_apk(dirpath, pkg);
pr_info("Found new base.apk at path: %s, is_manager: %d\n",
dirpath, is_manager);
if (is_manager) {
crown_manager(dirpath, my_ctx->private_data);
crown_manager(dirpath, pkg, my_ctx->private_data);
*my_ctx->stop = 1;
}
}