Modifying kernel to give each process an identifier/hash (proc address to kernel address translation)

Hello,

My goal is to give each process an identifier/hash value when the process is created. I ammended the "struct proc" from (sys/sys/proc.h) with a hash field, which I am planning to set at the end of the "do_fork" function (from sys/kern/kern_fork.c).
My plan is to create a hash based on the content of the ".text" segment of the binary file of the process (not the whole content, just few selected values from it).

The problem is that I don't know how to read a process memory from the kernel. Is there some kind of function that would translate the process address to the kernel address?

It seems that using the thread pointer from the "do_fork" I could access the "proc" structure, along with "vmspace", "vm_map" and "vm_map_entry" (all from sys/vm/vm_map.h file). It seems the vmspace has "vm_taddr" and "vm_tsize" which I think could be helpful.

I tried using chatgpt and github-copilot but both are useless in this case, any help would be appreciated.
 
I tried using chatgpt and github-copilot but both are useless in this case,
if they weren't, your case would be boring 🤷😏

Sorry, can't help here either, but I'd still appreciate some context: What do you plan to do with this hash? Some sort of "security feature"?
 
I'm working on a hardware-based monitoring system that works for baremetal programs only, I am trying to adapt it to work with an OS (to monitor a single userspace program/process). The purpose of this hash would be to recognize which program/process is currently running (the plan is to modify "sched_switch" to set a temp variable to the hash, this would allow the monitoring system to recognize the currently running process by checking program counter, instruction and the general purpose register file write port).
By using values from ".text" segment, it could be computed before running the program and would have consistent value whenever the program is ran (unlike pid).
 
You may consider using the vnode number that is backing the text segment. That is always the same for the same binary, and it does not require you to hash anything.
 
Back
Top