2021年1月18日星期一

Make already existing kernel symbol exported

There are two parts to this question:

  1. Defining a non-exported kernel function as being at a particular address and using the same name as the non-exported kernel function.
  2. Exporting a non-exported kernel function once its address is known.

This question will use kallsyms_lookup_name in its examples. This is no longer exported as of Linux 5.7, so this is fitting.

Defining the non-exported function

If a developer knows the address of a kernel function that has not been exported and wishes to use it, I've seen it typically done these ways:

// For `void __stack_chk_fail(void)`  void (*scf)(void) = (int (*)() ) ADDRESS;  // Called like below.  scf();    // For `struct filename *getname(const char __user *)`  static struct filename *(*getname_p)(const char __user *);  getname_p = (struct filename *(*)(const char __user *) ADDRESS;  // I actually don't know how this one is called.    // For `void machine_power_off(void)`  static void (*machine_power_off_p)(void);  machine_power_off_p = (void*) ADDRESS;  // Called like below.  (*machine_power_off_p)();  

Now suppose that I want to use kallsyms_lookup_name (which is no longer exported) and I want to call it as kallsyms_lookup_name instead of some alias such as kln/kallsyms_lookup_name_ptr/whatever. The declaration for the function can be included in the code using #include <linux/kallsyms.h>, but how can I get that included declaration to refer to the address of the non-dxported kallsyms_lookup_name?

Making the non-exported function available

As of Linux 5.7, there is no more EXPORT_SYMBOL_GPL(kallsyms_lookup_name). After determining the address of kallsyms_lookup_name and after doing the above, how can it then be exported or otherwise made available to other kernel modules as kallsyms_lookup_name?

https://stackoverflow.com/questions/65784965/make-already-existing-kernel-symbol-exported January 19, 2021 at 11:05AM

没有评论:

发表评论