Thank you very much for your ideas! (and
@arpruss thanks for coming back to share your ideas) I implemented
@arpruss's suggestion to the best of my knowledge (if I can't get this working I will search with code signatures. It's harder but looks completely foolproof. Nice idea BTW!) and am getting some strange outputs. Because I don't know how to look up task_struct fields by name I just iterated through all task_struct values that could be kernel pointers because task_struct isn't very large, setting them as the kernel base. Also please forgive me if I'm missing something very obvious or have broken something, I'm still not familiar a lot with how this exploit works and I only know a little of C.
The changes I made (roughly):
1) Make search_base a global variable
2) Defining KERNEL_BASE as search_base
3) kptrLeak function iterates over the task_struct addresses and if an address has a value above 0xffffff0000000000, take that as the search_base and call loadKallsyms()
4) Terminate loadKallsyms() if kallsyms entry counts mismatch (else leads to a segmentation fault, or rarely a device crash or bus error)
5) Some other minor changes which I can't quite remember
The code gives this output:
The code I used is uploaded too. Also the entry counts 131463 and 76323 are persistent after reboots, but 54847 is not (it gave 58215 IIRC on a previous boot) There are 160849 lines in /proc/kallsyms.
Anyone have an idea about what is happening here?
(Sorry if this makes no sense but could the kallsyms table be split in two somehow? Or maybe the code doesn't find the kallsyms table at all?)
Thank you very much!