josh
josh

Reputation: 11

Kernel Module memory access

I'm new to kernel modules and currently experimenting with it. I've read that they have the same level access as the kernel itself.

Does this mean they have access to physical memory and can see/overwrite values of other processes (including the kernel memory space)?

I have written this simple C code to overwrite every memory address but it's not doing anything (expecting the system to just crash, not sure if this is touching physical memory or it's still virtual memory)

I run it with sudo insmod ./test.ko, the code just hangs there (because of the infinite loop of course) but system works fine when I exit manually.

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

int init_module(void)
{
    unsigned char *p = 0x0;
    while (true){
      *p=0;
      p++;
    }

    return 0;
}

void cleanup_module(void)
{
    //
}

Upvotes: 1

Views: 1578

Answers (1)

Kampi
Kampi

Reputation: 1891

Kernel modules run with kernel privileges (including kernel memory and all peripherals). The reason why your code isn´t working is, that you don´t specify the init and exit module. So you can load the module, but the kernel doesn´t call your methods.

Please take a look at this example for a minimal kernel module. Here you will find some explanation about the needed macros.

Upvotes: 3

Related Questions