0

I want to get the base address of a .so file inside a usermode program. I want to be able to obtain that address by using my kernel module. In usermode I normally use grep [lib-name].so /proc/[pid]/maps | head -n 1 | cut -d "-" -f1.

I know that I can use kernel_read to directly read from files and I know that /proc is a pseudo filesystem that provides kernel data. So my question is, is there an easier way to get that address direclty from kernel or is there a better API that I can use to access /proc/[pid]/maps?

Parvo
  • 19
  • 4
  • I don't think you can currently use `kernel_read` to read `/proc/[pid]/maps` because `kernel_read` requires the `read_iter` file operation which is not provided for `/proc/[pid]/maps`. – Ian Abbott Nov 15 '22 at 18:17
  • Look at the `/proc` driver code for `maps`. It has to traverse the various kernel structs to produce the map. Just do what it does, minus the read/write functions to the `/proc/pid/maps` file. But, _why_ do you want this in your kernel module? What do you want to do with this data? The answer can dictate how you find/access/modify the data. As a kernel module, you already have access to the structs and various helper functions. If you've already loaded your module [via `insmod/modprobe`], how do you communicate the `pid` of interest to your module? – Craig Estey Nov 16 '22 at 17:31
  • I want to use this data so I can offset from the base address, to acces data in the usermode program I need. I get the pid of the usermode program by traversing the `task_struct` and then string comparing. – Parvo Nov 16 '22 at 17:44

0 Answers0