简体   繁体   English

Linux内核中的内存保护

[英]Memory protection in Linux kernel

When the shared library is mapped into the memory, Linux kernel will assign virtual memory areas to this memory region and mark their permissions respectively. 当共享库映射到内存时,Linux内核将为此内存区域分配虚拟内存区域并分别标记其权限。 But we know that there is no executable bit in the page table entry in x86 arch. 但我们知道x86 arch中的页表条目中没有可执行位。 If there is a call instruction like "call *edx" in the program to invoke function in the shared library, how can the Linux kernel know whether the target address is executable or not? 如果在程序中有一个类似“call * edx”的调用指令来调用共享库中的函数,那么Linux内核如何知道目标地址是否可执行? Will it cause general protection fault if the permission is not compatible in the vma list? 如果权限在vma列表中不兼容,是否会导致一般性保护错误?

It can't. 它不能。

On an architecture (/operating mode) where there is no execute page permission distinct from the read permission, the kernel would not be able to discover a supposedly illegal address execution as a result of a fault detected by the MMU. 在没有与读取权限不同的执行页面权限的体系结构(/操作模式)上,由于MMU检测到故障,内核将无法发现所谓的非法地址执行。

You're right that in theory the kernel could decide based on the finer-grained permissions on the memory region object, but such a decision making procedure would have to be in the page fault handler, which (I suppose) would make routine memory accesses very expensive. 你是对的,理论上内核可以根据内存区域对象的更细粒度的权限来决定,但是这样的决策制定过程必须在页面错误处理程序中,我认为这会使例程内存访问非常贵。

The kernel instead employs these simplification rules on x86: 内核在x86上使用了这些简化规则:

  • read access right always implies execute access right 读权限总是意味着执行权限
  • write access right always implies read access right 写访问权限始终意味着读访问权限

Source: Understanding Linux Kernel, 1st edition, page 205 来源:了解Linux内核,第1版,第205页

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

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