2

How can I get the base address and size of a loaded kernel module?

user
  • 163

2 Answers2

4

I think you can use /proc/modules. It contains information about all currently loaded modules in the kernel. For example:

cat /proc/modules | grep i8k

Result could be:

i8k 14696 0 - Live 0xffffffffa03b8000

Where:

  1. The first column contains the name of the module.
  2. The second column refers to the memory size of the module, in bytes.
  3. The third column lists how many instances of the module are currently loaded. A value of zero represents an unloaded module.
  4. The fourth column states if the module depends upon another module to be present in order to function, and lists those other modules.
  5. The fifth column lists what load state the module is in: Live, Loading, or Unloading.
  6. Base memory address for a module in the kernel's virtual address space.

If you run:

awk '$1 ~ /i8k/ { print $1, $2, $6 }' /proc/modules

The result could be, values you need:

i8k 14696 0xffffffffa03b8000
taliezin
  • 9,275
  • 1
    I had to run sudo cat /proc/modules in order to see the base addresses (6) – philn Jun 09 '20 at 17:58
  • The 3rd column is actually a reference count, it has nothing to do with how many instances are loaded (I doubt a module can have multiple instances anyway, even when handling multiple devices). A value of 0 means the module can be unloaded and a non-zero value means it cannot (references to it must be released first, most likely by other modules). – Tey' Apr 15 '21 at 19:18
2

Size on /sys

I like this alternative as it gives just a single value:

cat /sys/module/<module-name>/coresize

Load address on pr_debug

If you enable pr_debug, that information is present, and this can be useful if the module panics at init_module.

Details at: How to get the address of a kernel module that was inserted using insmod? | Stack Overflow

Ciro Santilli OurBigBook.com
  • 18,092
  • 4
  • 117
  • 102