Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kernel paging request fails in try_module_get()

Tags:

linux-kernel

The following code fails in one of my linux-kernel modules

printk("This module: %p\n",THIS_MODULE);
DEBUG_USE_COUNT(p);
printk("This module refcount: %d\n", module_refcount(THIS_MODULE));
DEBUG_USE_COUNT(p);
if (!try_module_get(THIS_MODULE)) {
    printk_stderr("can't get module\n");
    return -EFAULT;
}

The code itself works in usual environment, but when I try to execute it in the function called from within another module, it fails with paging error. (another module is passed the pointer to the function in question during initialization) Any ideas why module can't increment its reference count being called from another module? Are there any special limitations that apply to try_get_module call?

[ 7888.065029] BUG: unable to handle kernel paging request at fa69206
8
[ 7888.067470] IP: [<f926a2b6>] _ZL18open_station_sharePKcP23__camac_
kernel_open_argP4file+0x84/0x8ec [camac_k0607_lsi6] //function in question, calling try_module_get()
[ 7888.069014] Call Trace:
[ 7888.069014]  [<c10ac2b7>] ? __kmalloc+0x104/0x110
[ 7888.069014]  [<c12518f5>] ? printk+0xe/0x11
[ 7888.069014]  [<f90fae79>] ? T.633+0x46/0x4b [camac_mx]
[ 7888.069014]  [<f90fb07e>] ? camac_mx_ioctl+0x200/0x228 [camac_mx] //function of another module that calls the one in question
[ 7888.069014]  [<c10ba415>] ? vfs_ioctl+0x58/0x72
[ 7888.069014]  [<c10ba966>] ? do_vfs_ioctl+0x492/0x4d6
[ 7888.069014]  [<c109007b>] ? shmem_parse_options+0x167/0x281
[ 7888.069014]  [<c10ae69e>] ? fd_install+0x1b/0x38
[ 7888.069014]  [<c10ae88b>] ? do_sys_open+0xc8/0xdd
[ 7888.069014]  [<c10ba9ee>] ? sys_ioctl+0x44/0x64
[ 7888.069014]  [<c100305b>] ? sysenter_do_call+0x12/0x28

I would also be great if someone explains the garbage on the top of the printed stack. There should not be any functions in cross-module call. Top three functions on the stack are meaningless for me.

like image 977
Basilevs Avatar asked May 01 '26 10:05

Basilevs


1 Answers

THIS_MODULE may evaluate to NULL if the particular source file is compiled into the kernel rather than as part of a module, and module_refcount does not like getting NULL.

Also, the use of C++ in kernel modules is not recommended for it may interfere with about everything (think of exceptions and all that).

like image 75
user502515 Avatar answered May 04 '26 02:05

user502515



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!