From e2b610b4b3b9ae9108f23f61a1cfcb34d11fbb49 Mon Sep 17 00:00:00 2001 From: Henry Harrington Date: Tue, 13 Dec 2016 13:44:08 +0000 Subject: [PATCH] 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 --- src/system/boot/platform/efi/mmu.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/system/boot/platform/efi/mmu.cpp b/src/system/boot/platform/efi/mmu.cpp index fc40e2d2ea..3567a2e487 100644 --- a/src/system/boot/platform/efi/mmu.cpp +++ b/src/system/boot/platform/efi/mmu.cpp @@ -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)); }