For testing the behavior of the kernel when it leaks memory, I am writing a kernel module that continuously allocates memory e.g. the code looks like
int bytesLeaked = 128000;
char *var = kmalloc(bytesLeaked, GFP_KERNEL);
if (var != NULL)
printk("leaked %d bytes at address %x\n", bytesLeaked, (unsigned int)var);
This code is in the init_module. I have the following questions
- How do I determine whether the code has leaked memory? lsmod does not reveal much.
- The tutorials on the internet only show the code in init_module and exit_module. What if I wish to do the memory allocation over a period of time after the module has been inserted but before exiting.
- Is it possible for me to write code that leaks memory only when the user gives an instruction for it to do so e.g. can a user space program do a system call which will cause the module to leak memory?