kvm, ept: remove the default write bit
PATCH 2/2 kvm, ept: remove the default write bit
When ept enabled, current code set shadow_base_present_pte including the write bit, thus all pte entries have writabe bit, and it means guest os can always write to any mapped page (even VMM maps RO pages for the guest.)
We always use get_user_pages(write=1), so this bad code does not cause any bad result currently.
But it is really bad, so fix it, and we will use RO pages future.
We will set writabe bit when it is really writable (determined by the parameters of the set_spte())
---
arch/x86/kvm/vmx.c +1 -2
@@ -4365,8 +4365,7 @@ static int __init vmx_init(void)if (enable_ept) { bypass_guest_pf =0 ; -kvm_mmu_set_base_ptes (VMX_EPT_READABLE_MASK | -VMX_EPT_WRITABLE_MASK ); +kvm_mmu_set_base_ptes (VMX_EPT_READABLE_MASK );kvm_mmu_set_mask_ptes (0ull ,0ull ,0ull ,0ull ,VMX_EPT_EXECUTABLE_MASK );kvm_enable_tdp ();
Quoted 21 lines · Lai Jiangshan
When ept enabled, current code set
shadow_base_present_pteincluding the write bit, thus all pte entries have writabe bit, and it means guest os can always write to any mapped page (even VMM maps RO pages for the guest.)We always use
get_user_pages(write=1), so this bad code does not cause any bad result currently.But it is really bad, so fix it, and we will use RO pages future.
We will set writabe bit when it is really writable (determined by the parameters of the
set_spte())Signed-off-by Lai Jiangshan <[email protected]>---
arch/x86/kvm/vmx.c +0
-0
arch/x86/kvm/vmx.c static int __init vmx_init(void) · line 4371
Quoted 9 lines
arch/x86/kvm/vmx.c +1
-2@@ -4365,8 +4365,7 @@ static int __init vmx_init(void)if (enable_ept) { bypass_guest_pf =0 ; -kvm_mmu_set_base_ptes (VMX_EPT_READABLE_MASK | -VMX_EPT_WRITABLE_MASK ); +kvm_mmu_set_base_ptes (VMX_EPT_READABLE_MASK );kvm_mmu_set_mask_ptes (0ull ,0ull ,0ull ,0ull ,VMX_EPT_EXECUTABLE_MASK );kvm_enable_tdp ();
You can remove the call to kvm_mmu_set_base_ptes entirely, because VMX_EPT_READABLE_MASK == PT_PRESENT_MASK.
Quoted 24 lines · Marcelo Tosatti
Quoted 22 lines · Lai Jiangshan
When ept enabled, current code set
shadow_base_present_pteincluding the write bit, thus all pte entries have writabe bit, and it means guest os can always write to any mapped page (even VMM maps RO pages for the guest.)We always use
get_user_pages(write=1), so this bad code does not cause any bad result currently.But it is really bad, so fix it, and we will use RO pages future.
We will set writabe bit when it is really writable (determined by the parameters of the
set_spte())Signed-off-by Lai Jiangshan<[email protected]>---
arch/x86/kvm/vmx.c +0
-0@@ -4365,8 +4365,7 @@ static int __init vmx_init(void)
Quoted 12 lines
arch/x86/kvm/vmx.c static int __init vmx_init(void) · line 4371
Quoted 9 lines
arch/x86/kvm/vmx.c +1
-2if (enable_ept) { bypass_guest_pf =0 ; -kvm_mmu_set_base_ptes (VMX_EPT_READABLE_MASK | -VMX_EPT_WRITABLE_MASK ); +kvm_mmu_set_base_ptes (VMX_EPT_READABLE_MASK );kvm_mmu_set_mask_ptes (0ull ,0ull ,0ull ,0ull ,VMX_EPT_EXECUTABLE_MASK );kvm_enable_tdp ();You can remove the call to
kvm_mmu_set_base_ptesentirely, becauseVMX_EPT_READABLE_MASK==PT_PRESENT_MASK.
We can leave that to a later patch which removes kvm_mmu_set_base_ptes() entirely.
Signature · 1 line
error compiling committee.c: too many arguments to function