简体   繁体   English

如何在Linux x86_64和x86中设置内存段权限

[英]How are memory segment permissions set in Linux x86_64 and x86

I've been trying to figure this out for awhile now. 我已经尝试了一段时间了。 I've read that Linux uses paging and DEP is enforced by marking a page as non executable. 我读过Linux使用分页,并且DEP是通过将页面标记为不可执行来强制执行的。 But what about the permissions read/write? 但是读/写权限呢? How does the global descriptor table and segment registers come into play? 全局描述符表和段寄存器如何发挥作用? I read that the global and local descriptor tables contain the permissions for each segment. 我读到全局和本地描述符表包含每个段的权限。 So is it the tables that control permissions or the VM area structs maintained by the kernel? 那么是控制权限的表还是内核维护的VM区域结构?

x86 segment registers don't come into play here (except FS or GS for thread-local storage). x86段寄存器在这里不起作用 (用于线程本地存储的FS或GS除外)。 Segmentation isn't used to control read/write, that's done on a per-page basis with page-table entries. 分段不用于控制读/写,而是使用页表条目在每页的基础上完成的。

Linux keeps track of mappings in its own data structures separate from the hardware page tables, to figure out what to put in the HW page tables. Linux跟踪与硬件页表分开的其自己的数据结构中的映射,以找出要放入硬件页表中的内容。

A hardware page table entry (one per page) has a bit for read-only vs. read-write. 硬件页表项(每页一个)有一点是只读还是读写。 This existed even in the legacy page-table format, before the new (PAE and x86-64 long mode) page table format introduced a No-eXecute bit for DEP. 在新的(PAE和x86-64长模式)页表格式为DEP引入No-eXecute位之前,甚至存在于旧页表格式中。

See Why in 64bit the virtual address are 4 bits short (48bit long) compared with the physical address (52 bit long)? 请参阅为什么在64位中,虚拟地址比物理地址(52位长)短4位(长48位)? for a diagram of the x86-64 page table format, and links to more docs. 用于x86-64页表格式的图表,以及指向更多文档的链接。

The 32-bit mode PAE page tables are basically the same. 32位模式的PAE页表基本相同。 See https://wiki.osdev.org/Paging#MMU for a breakdown of the bits, specifically the R bit in each hardware PTE controls what the hardware does. 有关这些位的详细信息,请参阅https://wiki.osdev.org/Paging#MMU ,特别是每个硬件PTE中的R位控制着硬件的工作。

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

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