Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I am studying module programming. I can find out function addresses using 'kallsyms_lookup_name'. But, I am unable to access global variables this way. In particular, I am trying to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2006
    Posts
    3

    Accessing kernel global variables


    Hi,
    I am studying module programming. I can find out function addresses using 'kallsyms_lookup_name'. But, I am unable to access global variables this way. In particular, I am trying to access 'modules_op' declared in "kernel/module.c" from my test module. I am getting the following error during build
    WARNING: "modules_op" [/tmp/kernel-module.ko] undefined!
    'insmod' is also failing. Can somebody tell me how to find address of global variables ?

    Thanks,

    -Rahul S.

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Although kernel modules are linked only against the kernel, that doesn't mean that all the kernel variables are available. For example, it's common to use the static keyword to limit the visibility of a variable.

    In addition, some functions need to be exported with EXPORT_SYMBOL and EXPORT_GPL macros.

    Sometimes this is done to avoid other people to do bad things with kernel facilities (That's one of the reasons because the kernel doesn't export the syscall table anymore)

    Are you sure that you can access that symbol?

    Best Regards

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    3
    The following is what I am doing

    #include <linux/module.h>
    #include <linux/seq_file.h>

    extern struct seq_operations modules_op;
    void * (*m_start)(struct seq_file *, loff_t *);

    some_func () {
    ...
    m_start = modules_op.start;
    ...
    }

    'modules_op' is defined in "kernel/module.c" (not as static) as follows

    struct seq_operations modules_op = {
    .start = m_start,
    .next = m_next,
    .stop = m_stop,
    .show = m_show
    };

    It is not exported using EXPORT_SYMBOL. It is not in /proc/kallsyms.

    It is also referred to in "fs/proc/proc_misc.c" by declaring it as "extern".

    Do you think I will not be able to access it from my module ?

    Regards,

    -Rahul S.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    Location
    Holland
    Posts
    301
    Probably you can't for the same reason as you can't get the syscall table. It is not exported.

    In module.c it works because that file is compiled and linked "inside" the kernel, this is, in linking stage, the linker resolves that symbol so there is no reason to warn. However, in your module, after the linking stage, you don't know the address of that symbol.

    Best Regards

  6. #5
    Just Joined!
    Join Date
    Feb 2007
    Posts
    31
    so did you find any way to access that global variable from your kernel module.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •