When working with Linux kernel modules, parameters control their behavior at runtime. While /sys/module/<module_name>/parameters/
is the standard interface, some modules don't expose their parameters through sysfs. As a developer, you need reliable methods to inspect these values.
The modinfo
command shows parameter information, including default values:
modinfo -p <module_name>
# Example:
modinfo -p e1000
For currently loaded modules, examine /proc/modules
:
cat /proc/modules | grep <module_name>
Many modules log their parameters during initialization. Check kernel messages:
dmesg | grep <module_name>
For programmatic access in C:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/moduleparam.h>
static int get_module_params(const char *modname)
{
struct module *mod;
unsigned int i;
list_for_each_entry(mod, &THIS_MODULE->list, list) {
if (strcmp(mod->name, modname) == 0) {
printk(KERN_INFO "Module %s parameters:\n", modname);
for (i = 0; i < mod->num_kp; i++) {
struct kernel_param *kp = &mod->kp[i];
printk(KERN_INFO "%s: %p\n", kp->name, kp->arg);
}
return 0;
}
}
return -ENOENT;
}
For advanced debugging with SystemTap:
probe module("<module_name>").function("*") {
printf("Parameter values at %s:%d\n", probefunc(), probeline())
/* Add parameter inspection logic here */
}
When parameters aren't exposed through standard interfaces, consider:
- Recompiling the module with debug options
- Using kernel debugging tools like kgdb
- Checking the module's source code for parameter declarations
Remember that accessing module parameters might require root privileges. Always:
- Validate inputs when writing scripts
- Handle cases where modules aren't loaded
- Consider security implications of exposing parameter values
When working with Linux kernel modules, parameters allow runtime configuration without recompiling. While /sys/module/<module_name>/parameters/
is the standard interface, some modules might not expose parameters through this mechanism. Here are alternative approaches to inspect module parameters.
The /proc/modules
file contains information about all loaded modules, including their memory addresses:
cat /proc/modules
# Example output:
# nf_conntrack 126976 2 nf_nat,xt_conntrack, Live 0xffffffffc05b8000
The modinfo
command shows declared parameters, but not their current values:
modinfo nf_conntrack
# Output includes:
# parm: hashsize:uint
# parm: expect_hashsize:uint
For modules without sysfs interface, you might need to examine kernel memory:
# First find module text address
grep nf_conntrack /proc/modules
# Then use gdb to examine symbols (requires kernel debug symbols)
gdb /usr/lib/debug/boot/vmlinux-$(uname -r)
(gdb) p &nf_conntrack_hashsize
SystemTap can probe module parameters at runtime:
probe module("nf_conntrack").function("*") {
printf("Parameter values might be accessible via: %s\n", pp())
}
Some modules provide custom debugfs entries:
ls /sys/kernel/debug/
Here's how to check TCP keepalive parameters:
cat /proc/sys/net/ipv4/tcp_keepalive_time
cat /proc/sys/net/ipv4/tcp_keepalive_intvl
cat /proc/sys/net/ipv4/tcp_keepalive_probes
Remember that parameter access methods vary by module implementation. When standard interfaces aren't available, you might need to consult the module's source code or documentation for specific inspection methods.