简体   繁体   English

内核模块内存访问

[英]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) 我已经编写了这个简单的C代码来覆盖每个内存地址但它没有做任何事情(期望系统崩溃,不确定这是否触及物理内存或它仍然是虚拟内存)

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. 我用sudo insmod ./test.ko运行它,代码只挂在那里(因为当然是无限循环)但是当我手动退出时系统工作正常。

#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)
{
    //
}

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. 您的代码不起作用的原因是,您没有指定initexit模块。 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. 在这里,您将找到有关所需宏的一些解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM