0
votes

Need memory address where the kernel module (*.ko) will be loaded, so I can break-into the system when the address is accessed.

Seems plenty of posts suggesting how to get it after the fact, from /proc/modules for example. This is great, but this is after the fact.

Even loading, unloading the module during runtime does not guarantee it will be loaded always at the same address. If there way to fix it ? I hoped insmod has an address parameter, but seems I was wrong.

1
So far only way I have it, is always insert the module of interest first, or , always in the same order. Re-start system each time when repeating the process - to get same addresses.v01d
There is no load address in the .ko file, so you cannot get that address without loading the module.Tsyvarev
@Tsyvarev the .ko doens't, but may be there is other way to get where it will be loaded? Like internal runtime table of module handles, or 'next free' handle .. ( I guess I need to read on how the addresses created at run time by the module loader..)v01d
The memory for module and its parts is allocated via module_alloc, so an attempt to guess its result is like guessing result of the malloc. BTW, if you just want to call some kernel function when the load address of the module becomes known but before the module is loaded, register_module_notifier is your friend.Tsyvarev
@Tsyvarev yea, thank you this sure is helpful will look it up.v01d

1 Answers

1
votes

I'm closing my own question with answer.

Best comment or answer is by @Tsyvarev above in the comments. The comment - see register_module_notifier - tell you how one would get the address at runtime with-in your own code say. ( I haven't used it as I don't need it).

For my case I needed it for debugging with external hardware monitor, and I can equally set the debugger to interrupt the system on the module_alloc when I need. (And I control when the specific module is loaded anyway.)

Thus, all-in-all - 2 ways above - here it is explained how you may get the address before module is "loaded".