Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Linux kernel symbols that are not exported via EXPORT_SYMBOL*

We have a need to access kernel global vars in net/ipv4/af_inet.c that are not exported explicitly from a loadable kernel module. We are using 2.6.18 kernel currently.

kallsyms_lookup_name doesn't appear to be available anymore (not exported)

__symbol_get returns NULL (upon further reading, symbol_get/__symbol_get looks through the kernel and existing modules' symbol tables that contains only exported symbol, and it is there to make sure the module from which a symbol is exported is actually loaded)

Is there anyway to access symbols that are not exported from a kernel module?

After doing a lot of reading and looking at answers people provided, it appears that it would be very hard to find one method across many kernel versions since the kAPI changes significantly over time.

like image 764
software engineer Avatar asked Mar 30 '12 23:03

software engineer


2 Answers

You can use the method you mentioned before by getting it from /proc/kallsyms or just use the address given in the System.map (which is the same thing), it may seem hackish but this is how I've seen it done before (never really had to do it myself). Either this or you can build your own custom kernel where you actually do EXPORT_SYMBOL on whatever it is you want exported but this is not as portable.

like image 144
Jesus Ramos Avatar answered Sep 28 '22 01:09

Jesus Ramos


If performance is not a big concern, you can traverse the whole list of symbols with kallsyms_on_each_symbol() (exported by the kernel for GPL'd modules) and check the names to get the ones you need. I would not recommend doing so unless there is no other choice though.

If you would like to go this way, here is an example from one of our projects. See the usage of kallsyms_on_each_symbol() as well as the code of symbol_walk_callback(), the other parts are irrelevant to this question.

like image 23
Eugene Avatar answered Sep 28 '22 00:09

Eugene