Linux内核代码空间写保护
我有几个关于 Linux 内核内存页面写保护的问题。
我怎样才能知道内核是否 代码(文本段)被写入 受保护与否。我可以看看
/proc/
查看 各种进程的内存映射。 但不知道去哪里寻找 内核代码内存映射。/map 如果内核代码段被写入 受保护,那么有可能 代码段页是 被任何其他内核覆盖 级别代码。换句话说,是否 文本段页写保护 仅针对用户空间提供保护 向其写入代码或将其 甚至可以防止从内部写入 内核空间代码。
谢谢
I had couple of questions on linux kernel memory page write protection.
How can i figure out if the kernel
code (text segment) is write
protected or not. I can look at/proc/<process-id>/map
to see the
memory map for various processes.
But not sure where to look for the
kernel code memory map.If the kernel code segment is write
protected, then is it possible for
the code segment pages to be
overwritten by any other kernel
level code. In other words, does the
write protect on a text segment page
protects against only the user space
code writing to it or will it
prevent writes even from within the
kernel space code.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在内核中运行的代码可以直接访问当前地址空间的页表,因此它可以通过检查这些页表来检查写入访问。可能有一些函数可以帮助您进行该检查,但我对 mm 代码不够熟悉,无法指出它们。有更简单的方法吗?我不确定。
内核文本永远不能从用户空间写入。另外,还可以保护文本免于从内核代码写入(我认为这就是您所说的)。这只是针对错误的基本保护。如果内核代码确实愿意,可以通过直接修改页表来禁用该保护。
Code running in the kernel has direct access to the page tables for the current address space, so it can check for write access by examining those. There are probably functions to help you with that check, but I'm not familiar enough with the mm code to point them out. Is there an easier way? I'm not sure.
The kernel text should never be writable from user-space. The text can additionally be protected against writing from kernel code too (I think this is what you're talking about). This is only a basic protection against bugs. Kernel code, if it really wants to, can disable that protection by modifying the page tables directly.
有一篇论文谈到了这一点。基本上,它使用一个小型虚拟机管理程序来保护操作系统内核。
SecVisor:一个微型虚拟机管理程序,可为商品操作系统提供终身内核代码完整性。
http://www.sosp2007.org/papers/sosp079-seshadri.pdf
There is one paper talking about that. Basically, it uses a small hypervisor to protect the OS kernel.
SecVisor: A Tiny Hypervisor to Provide Lifetime Kernel Code Integrity for Commodity OSes.
http://www.sosp2007.org/papers/sosp079-seshadri.pdf