Page Flag和mprotect,DEP和NX(EDB)

Page Flag Bit

#define _PAGE_BIT_PRESENT	0	/* is present */
#define _PAGE_BIT_RW		1	/* writeable */
#define _PAGE_BIT_USER		2	/* userspace addressable */
#define _PAGE_BIT_PWT		3	/* page write through */
#define _PAGE_BIT_PCD		4	/* page cache disabled */
#define _PAGE_BIT_ACCESSED	5	/* was accessed (raised by CPU) */
#define _PAGE_BIT_DIRTY		6	/* was written to (raised by CPU) */
#define _PAGE_BIT_PSE		7	/* 4 MB (or 2MB) page */
#define _PAGE_BIT_PAT		7	/* on 4KB pages */
#define _PAGE_BIT_GLOBAL	8	/* Global TLB entry PPro+ */
#define _PAGE_BIT_SOFTW1	9	/* available for programmer */
#define _PAGE_BIT_SOFTW2	10	/* " */
#define _PAGE_BIT_SOFTW3	11	/* " */
#define _PAGE_BIT_PAT_LARGE	12	/* On 2MB or 1GB pages */
#define _PAGE_BIT_SOFTW4	58	/* available for programmer */
#define _PAGE_BIT_PKEY_BIT0	59	/* Protection Keys, bit 1/4 */
#define _PAGE_BIT_PKEY_BIT1	60	/* Protection Keys, bit 2/4 */
#define _PAGE_BIT_PKEY_BIT2	61	/* Protection Keys, bit 3/4 */
#define _PAGE_BIT_PKEY_BIT3	62	/* Protection Keys, bit 4/4 */
#define _PAGE_BIT_NX		63	/* No execute: only valid after cpuid check */

直接修改Page Flag

需要Ring0权限才能直接修改各级Page Flag,并且一般都是逐个flag bit地就行修改。

mprotect

这是一个系统调用,能够方便地让用户态通过系统调用对各级Page Flag进行修改,而且可以是一下子操作一段内存。最终效果也是对各级Page Flag进行了修改。

DEP(Data Execution Prevention)

本身是一个数据执行保护概念,有通过软件和硬件的实现机制。

硬件实现机制。比如Intel的硬件NX Bit,BIOS中可以设置。有的BIOS中称为EDB(Execute Disable Bit)。也可以通过CPUID硬件指令查询到CPUID(EAX[80000001H]).EDX.Bit20.

软件实现机制。比如Kernel中的内存地址中的_PAGE_BIT_NX,就是用来指定Page的不可执行属性。

根据Kernel注释的意思,需要先验证硬件NX机制然后才验证软件NX。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值