Skip to content
27 changes: 10 additions & 17 deletions kernel/core_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,18 @@ int ksu_handle_rename(struct dentry *old_dentry, struct dentry *new_dentry)
return 0;
}

// /data/system/packages.list.tmp -> /data/system/packages.list
if (strcmp(new_dentry->d_iname, "packages.list")) {
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")) {
// It still monitors changes to certain system files to trigger scans, but does not rely on packages.list.
if (strstr(new_dentry->d_iname, "packages") &&
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;
}
pr_info("renameat: %s -> %s, new path: %s\n", old_dentry->d_iname,
new_dentry->d_iname, buf);

track_throne();

return 0;
}
Expand Down
30 changes: 30 additions & 0 deletions kernel/kernel_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@
#include <linux/version.h>
#include "ss/policydb.h"
#include "linux/key.h"
#include <linux/list.h>

/**
* list_count_nodes - count the number of nodes in a list
* @head: the head of the list
*
* This function iterates over the list starting from @head and counts
* the number of nodes in the list. It does not modify the list.
*
* Context: Any context. The function is safe to call in any context,
* including interrupt context, as it does not sleep or allocate
* memory.
*
* Return: the number of nodes in the list (excluding the head)
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 6, 0)
static inline __maybe_unused size_t list_count_nodes(const struct list_head *head)
{
const struct list_head *pos;
size_t count = 0;

if (!head)
return 0;

list_for_each(pos, head)
count++;

return count;
}
#endif

/*
* Adapt to Huawei HISI kernel without affecting other kernels ,
Expand Down
Loading
Loading