两个 Linux 内核模块损坏共享指针 - 如何调试?

Two Linux kernel modules corrupting a shared pointer - How to debug?

假设有两个Linux kernel modules。 这两个模块共享一个 global pointerModule 1 正在尝试访问此 pointer,损坏此指针值并退出。 现在 Module 2 正在尝试访问此 pointer,它不再有效并崩溃。

模块 1:

module_function()
{
     //corrupt global_ptr
}

module2_function()
{

    local_ptr = global_ptr;
    //local_ptr corrupted
    //Now if local_ptr is accessed, it will crash
}

如果这种情况有效且可能,有人可以解释一下吗? 那么

i) 如何调试这个问题。也就是说,如何找出哪个模块正在破坏指针?

ii) 如何解决这个问题,使 module2 永远不会崩溃?

  1. 这是 use-after-freeuse-after-modifybug 的典型案例,通常会导致 oops,因此 tainting linux kernel设置了 G flag,结果是 system hang and reboot。如果由于 system hang.
  2. 而无法获得 dmesg logs,您可以在 /var/log/kern.log 中观察这些 logs
  3. 为了调试此类 kernel memory pointer corruption 问题,您需要在 kernel menuconfigEnable Slab Corruption debug,因此 .config。为了更快地参考,执行此操作的步骤是:- make menuconfig ---> Kernel hacking ---> Memory debugging ---> Debug slab memory locations
  4. 此问题的设计解决方案是不在模块之间使用 global pointers,因为您永远不知道哪个模块可能首先获得 freed,从而导致指针损坏。