Fixed some minor issues that may have existed
This commit is contained in:
@@ -298,19 +298,26 @@ int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// It still monitors changes to certain system files to trigger scans, but does not rely on packages.list.
|
// /data/system/packages.list.tmp -> /data/system/packages.list
|
||||||
if (strstr(new_dentry->d_iname, "packages") &&
|
if (strcmp(new_dentry->d_iname, "packages.list")) {
|
||||||
strstr(new_dentry->d_iname, "list")) {
|
|
||||||
char path[128];
|
|
||||||
char *buf = dentry_path_raw(new_dentry, path, sizeof(path));
|
|
||||||
if (!IS_ERR(buf) && strstr(buf, "/system/")) {
|
|
||||||
pr_info("System package change detected: %s -> %s, triggering user scan\n",
|
|
||||||
old_dentry->d_iname, new_dentry->d_iname);
|
|
||||||
track_throne();
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char path[128];
|
||||||
|
char *buf = dentry_path_raw(new_dentry, path, sizeof(path));
|
||||||
|
if (IS_ERR(buf)) {
|
||||||
|
pr_err("dentry_path_raw failed.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strstr(buf, "/system/packages.list")) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
pr_info("renameat: %s -> %s, new path: %s\n", old_dentry->d_iname,
|
||||||
|
new_dentry->d_iname, buf);
|
||||||
|
|
||||||
|
track_throne();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
uid_t ksu_manager_uid = KSU_INVALID_UID;
|
uid_t ksu_manager_uid = KSU_INVALID_UID;
|
||||||
|
|
||||||
#define USER_DATA_BASE_PATH "/data/user_de"
|
#define USER_DATA_BASE_PATH "/data/user_de"
|
||||||
#define USER_DATA_LEGACY_BASE_PATH "/data/user"
|
#define MAX_SUPPORTED_USERS 32 // Supports up to 32 users
|
||||||
#define USER_DATA_PATH_LEN 256 // 256 is enough for /data/user_de/{userid}/<package>
|
#define USER_DATA_PATH_LEN 384 // 384 is enough for /data/user_de/{userid}/<package>
|
||||||
#define MAX_ANDROID_USER_ID 999
|
#define MAX_ANDROID_USER_ID 999
|
||||||
#define MIN_ANDROID_USER_ID 0
|
#define MIN_ANDROID_USER_ID 0
|
||||||
|
|
||||||
@@ -166,30 +166,29 @@ struct user_data_context {
|
|||||||
static int get_active_user_ids(uid_t *user_ids, size_t max_users, size_t *found_users)
|
static int get_active_user_ids(uid_t *user_ids, size_t max_users, size_t *found_users)
|
||||||
{
|
{
|
||||||
struct file *dir_file;
|
struct file *dir_file;
|
||||||
struct dir_context ctx __maybe_unused = {0};
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
|
|
||||||
|
const char *opened_base = NULL;
|
||||||
|
|
||||||
*found_users = 0;
|
*found_users = 0;
|
||||||
|
|
||||||
dir_file = ksu_filp_open_compat(USER_DATA_BASE_PATH, O_RDONLY, 0);
|
dir_file = ksu_filp_open_compat(USER_DATA_BASE_PATH, O_RDONLY, 0);
|
||||||
if (IS_ERR(dir_file)) {
|
if (IS_ERR(dir_file)) {
|
||||||
pr_warn("Failed to open %s: %ld, trying legacy path\n",
|
pr_err("Failed to open user data path %s: %ld\n",
|
||||||
USER_DATA_BASE_PATH, PTR_ERR(dir_file));
|
USER_DATA_BASE_PATH, PTR_ERR(dir_file));
|
||||||
|
|
||||||
// Try the legacy path
|
|
||||||
dir_file = ksu_filp_open_compat(USER_DATA_LEGACY_BASE_PATH, O_RDONLY, 0);
|
|
||||||
if (IS_ERR(dir_file)) {
|
|
||||||
pr_err("Failed to open both user data paths: %ld\n", PTR_ERR(dir_file));
|
|
||||||
return PTR_ERR(dir_file);
|
return PTR_ERR(dir_file);
|
||||||
}
|
}
|
||||||
}
|
opened_base = USER_DATA_BASE_PATH;
|
||||||
|
|
||||||
|
for (uid_t user_id = MIN_ANDROID_USER_ID;
|
||||||
|
user_id <= MAX_ANDROID_USER_ID && count < max_users;
|
||||||
|
user_id++) {
|
||||||
|
|
||||||
struct path path;
|
|
||||||
for (uid_t user_id = MIN_ANDROID_USER_ID; user_id <= MAX_ANDROID_USER_ID && count < max_users; user_id++) {
|
|
||||||
char user_path[USER_DATA_PATH_LEN];
|
char user_path[USER_DATA_PATH_LEN];
|
||||||
|
struct path path;
|
||||||
|
|
||||||
snprintf(user_path, sizeof(user_path), "%s/%u", USER_DATA_BASE_PATH, user_id);
|
snprintf(user_path, sizeof(user_path), "%s/%u", opened_base, user_id);
|
||||||
|
|
||||||
if (!kern_path(user_path, 0, &path)) {
|
if (!kern_path(user_path, 0, &path)) {
|
||||||
user_ids[count++] = user_id;
|
user_ids[count++] = user_id;
|
||||||
@@ -199,9 +198,8 @@ static int get_active_user_ids(uid_t *user_ids, size_t max_users, size_t *found_
|
|||||||
|
|
||||||
filp_close(dir_file, NULL);
|
filp_close(dir_file, NULL);
|
||||||
*found_users = count;
|
*found_users = count;
|
||||||
if (count > 0) {
|
if (count > 0)
|
||||||
pr_info("UserDE UID: Found %zu active users\n", count);
|
pr_info("UserDE UID: Found %zu active users\n", count);
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -264,7 +262,7 @@ FILLDIR_RETURN_TYPE user_data_actor(struct dir_context *ctx, const char *name,
|
|||||||
return FILLDIR_ACTOR_CONTINUE;
|
return FILLDIR_ACTOR_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct uid_data *data = kzalloc(sizeof(struct uid_data), GFP_ATOMIC);
|
struct uid_data *data = kzalloc(sizeof(struct uid_data), GFP_KERNEL);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
pr_err("Failed to allocate memory for package: %.*s (user %u)\n", namelen, name, scan_ctx->user_id);
|
pr_err("Failed to allocate memory for package: %.*s (user %u)\n", namelen, name, scan_ctx->user_id);
|
||||||
scan_ctx->errors_count++;
|
scan_ctx->errors_count++;
|
||||||
@@ -272,7 +270,7 @@ FILLDIR_RETURN_TYPE user_data_actor(struct dir_context *ctx, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
data->uid = uid;
|
data->uid = uid;
|
||||||
size_t copy_len = min(namelen, KSU_MAX_PACKAGE_NAME - 1);
|
size_t copy_len = min_t(size_t, namelen, KSU_MAX_PACKAGE_NAME - 1);
|
||||||
strncpy(data->package, name, copy_len);
|
strncpy(data->package, name, copy_len);
|
||||||
data->package[copy_len] = '\0';
|
data->package[copy_len] = '\0';
|
||||||
|
|
||||||
@@ -331,7 +329,7 @@ static int scan_user_data_for_user(uid_t user_id, struct list_head *uid_list,
|
|||||||
|
|
||||||
int scan_user_data_for_uids(struct list_head *uid_list)
|
int scan_user_data_for_uids(struct list_head *uid_list)
|
||||||
{
|
{
|
||||||
uid_t user_ids[32]; // Supports up to 32 users
|
uid_t user_ids[MAX_SUPPORTED_USERS];
|
||||||
size_t active_users = 0;
|
size_t active_users = 0;
|
||||||
size_t total_packages = 0;
|
size_t total_packages = 0;
|
||||||
size_t total_errors = 0;
|
size_t total_errors = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user