代码之家  ›  专栏  ›  技术社区  ›  achinda99

Linux内核编程:无法在虚拟地址[地址]处处理内核空指针解引用

  •  1
  • achinda99  · 技术社区  · 14 年前

    示例:在下面的代码中,current\ u process是指向task\ u struct的有效指针,k\ u buf是有效的

    printk("Setting parent process\n");
    parent_process = current_process->real_parent;
    printk("Parent process set\n");
    if (parent_process != NULL) {
    printk("Parent process is not null and getting pid\n");
        k_buf[i].parent_pid = parent_process->pid;
    } else {
        k_buf[i].parent_pid = 0;
    }
    printk("Done with parent process\n");
    

    运行时,程序将打印:

    Setting parent process
    Parent process set
    Parent process is not null and getting pid
    Done with parent process
    

    几次,然后

    Setting parent process
    Parent process set
    Parent process is not null and getting pid
    

    在抛出错误并进入内核恐慌之前。

    目前,我注释掉了上面的代码,以便继续处理系统调用的其余部分。当我尝试访问子进程的pid时(在两次成功尝试之后),它会给出一个“无法在虚拟地址处理内核分页请求”错误。据我所知,我有读取这些数据的正确锁。但是,在我访问内存之前,是否还需要做些什么来检查内存?

    3 回复  |  直到 14 年前
        1
  •  1
  •   user191776 user191776    14 年前

    我在这里猜测,但我可以 parent_process->pid 存在 NULL

    要么是这样,要么是访问 i 的th元素 k_buf 阵列ie。 *(k_buf+i)

        2
  •  1
  •   Thomas M. DuBuisson    14 年前

    你好像不是在测试 kbuf 属于 kbuf[i] printk 通过这些指针,您可以捕获非空但显然无效的地址(例如 0xbfff0c3a )

        3
  •  0
  •   Qazi Arsalan Shah    4 年前

    我写了一封信 系统 呼叫 列出所有进程 得到这个了吗

    [260.613416]第0页第0页 [260.613422]对不起:0000[#1]SMP PTI [260.613427]CPU:3 PID:1793通信:a.输出受污染:P OE 4.19.5#2

    我在检查, 然后打印PID,

    现在我想我应该试试if(process->parent!=空)

    问题答案: 亲爱的兄弟,