在Linux哈希表中插入PID
目前我正在开发一个Linux内核模块,它可以隐藏任何正常进程。 隐藏效果很好,但我还没有找到一种方法来取消隐藏过程。 首先,我从内核中任务结构的大列表中删除结构任务结构:在Linux哈希表中插入PID,linux,hash,process,kernel,pid,Linux,Hash,Process,Kernel,Pid,目前我正在开发一个Linux内核模块,它可以隐藏任何正常进程。 隐藏效果很好,但我还没有找到一种方法来取消隐藏过程。 首先,我从内核中任务结构的大列表中删除结构任务结构: struct task_struct *p; //Finding the correct task_struct for_each_process(p) if(p->pid == pid){ // Removing the task_struct struct list_hea
struct task_struct *p;
//Finding the correct task_struct
for_each_process(p)
if(p->pid == pid){
// Removing the task_struct
struct list_head *next = task->tasks.next;
struct list_head *prev = task->tasks.prev;
next->prev=prev;
prev->next=next;
}
但是task_结构仍然是可跟踪的,因为它位于包含每个进程的task_结构的哈希表中。事实上,大多数PID查找都是通过该哈希表执行的。从中删除任务结构有点棘手:
struct pid *pid; //struct pid of the task_struct
//Deleting for every pid_namespace the pid_chain from the hash_list
for (i = 0; i <= pid->level; i++) {
struct upid *upid = pid->numbers + i;
hlist_del_rcu(&upid->pid_chain);
}
pid\u hash fn和pid\u hash定义如下:
#define pid_hashfn(nr, ns) hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
static struct hlist_head *pid_hash;
我需要插入的结构是pid_链:
struct hlist_node pid_chain;
所以我的问题是,如何在正确的哈希列表中插入pid\u链?
是否有一种方法可以获取对哈希列表数组的引用,即使它被声明为静态的
或者,可能是一个不常见的想法:哈希列表是通过
pid_hash = alloc_large_system_hash("PID", sizeof(*pid_hash), 0, 18,HASH_EARLY | HASH_SMALL, &pidhash_shift, NULL,0, 4096);
因此,如果我可以得到散列列表内存的起始位置,我可以扫描相应的内存空间以查找我的结构的指针,然后将周围的内存区域强制转换为类型为struct hlist的结构吗
谢谢你的帮助。每个解决方案或想法都值得赞赏:)在sysmap文件中有一个可用的哈希列表。您可以检查一次。pid\u散列可以位于/proc/kallsyms中,也可以通过kallsyms\u lookup\u名称以编程方式访问
pid_hash = alloc_large_system_hash("PID", sizeof(*pid_hash), 0, 18,HASH_EARLY | HASH_SMALL, &pidhash_shift, NULL,0, 4096);