UEFI: CR0.WP must be set before entering the kernel.

If WP is not enabled then the kernel can freely write to read-only user
pages, which breaks copy-on-write.

Signed-off-by: Jessica Hamilton <jessica.l.hamilton@gmail.com>
This commit is contained in:
Henry Harrington 2016-12-13 13:44:08 +00:00 committed by Jessica Hamilton
parent b521a45ec2
commit e2b610b4b3

View File

@ -200,6 +200,9 @@ mmu_post_efi_setup(UINTN memory_map_size, EFI_MEMORY_DESCRIPTOR *memory_map, UIN
// Something involving ConvertPointer might need to be done after this?
// http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#SetVirtualAddressMap.28.29
kRuntimeServices->SetVirtualAddressMap(memory_map_size, descriptor_size, descriptor_version, memory_map);
// Important. Make sure supervisor threads can fault on read only pages...
asm("mov %%rax, %%cr0" : : "a" ((1 << 31) | (1 << 16) | (1 << 5) | 1));
}