Revert "x86/mm: drop guest_get_eff_l1e()"
PATCH 1/1 Revert "x86/mm: drop guest_get_eff_l1e()"
This reverts commit 9ff9705647646aa937b5f5c1426a64c69a62b3bd.
The change is only correct in the original context of XSA-286, where Xen's use of the linear pagetables were dropped. However, performance problems interfered with that plan, and XSA-286 was fixed differently.
This broke Xen's lazy faulting of the LDT for 64bit PV guests when an access was first encountered in user context. Xen would proceed to read the registered LDT virtual address out of the user pagetables, not the kernel pagetables.
Given the nature of the bug, it would have also interfered with the IO permisison bitmap functionality of userspace, which similarly needs to read data using the kernel pagetables.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>
CC: Manuel Bouyer <[email protected]>
There is also a bug with Xen's IRET handling, but that has been broken forever and is much more complicated to fix. I'll put it on my TODO list, but no idea when I'll get around to addressing it.
--- xen/arch/x86/pv/mm.c | 21 +++++++++++++++++++++ xen/arch/x86/pv/mm.h | 7 ++----- xen/arch/x86/pv/ro-page-fault.c | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-)
xen/arch/x86/pv/mm.c +21 -0
@@ -56,6 +56,27 @@ l1_pgentry_t *map_guest_l1e(unsigned long linear, mfn_t *gl1mfn) }/* +* Read the guest's l1e that maps this address, from the kernel-mode +* page tables. +*/ +static l1_pgentry_t guest_get_eff_kern_l1e (unsigned long linear) +{ +struct vcpu *curr = current; +const bool user_mode = !(curr->arch.flags & TF_kernel_mode); +l1_pgentry_t l1e; + +if ( user_mode ) +toggle_guest_pt (curr); + + l1e =guest_get_eff_l1e (linear); + +if ( user_mode ) +toggle_guest_pt (curr); + +return l1e; +} + +/* * Map a guest's LDT page (covering the byte at @offset from start of the LDT) * into Xen's virtual range. Returns true if the mapping changed, false * otherwise.
xen/arch/x86/pv/mm.h +2 -5
@@ -5,11 +5,8 @@ l1_pgentry_t *map_guest_l1e(unsigned long linear, mfn_t *gl1mfn);int new_guest_cr3 (mfn_t mfn); -/* -* Read the guest's l1e that maps this address, from the kernel-mode -* page tables. -*/ -static inline l1_pgentry_t guest_get_eff_kern_l1e (unsigned long linear) +/* Read a PV guest's l1e that maps this linear address. */ +static inline l1_pgentry_t guest_get_eff_l1e (unsigned long linear) {l1_pgentry_t l1e;
xen/arch/x86/pv/ro-page-fault.c +1 -1
@@ -342,7 +342,7 @@ int pv_ro_page_fault(unsigned long addr, struct cpu_user_regs *regs)bool mmio_ro;/* Attempt to read the PTE that maps the VA being accessed. */ - pte =guest_get_eff_kern_l1e (addr); + pte =guest_get_eff_l1e (addr);/* We are only looking for read-only mappings */ if ( ((l1e_get_flags (pte) & (_PAGE_PRESENT | _PAGE_RW)) != _PAGE_PRESENT) )
Signature · 1 line
2.11.0
Quoted 6 lines · Andrew Cooper
This reverts commit
9ff9705647646aa937b5f5c1426a64c69a62b3bd.The change is only correct in the original context of XSA-286, where Xen's use of the linear pagetables were dropped. However, performance problems interfered with that plan, and XSA-286 was fixed differently.
Quoted 8 lines
This broke Xen's lazy faulting of the LDT for 64bit PV guests when an access was first encountered in user context. Xen would proceed to read the registered LDT virtual address out of the user pagetables, not the kernel pagetables.
Given the nature of the bug, it would have also interfered with the IO permisison bitmap functionality of userspace, which similarly needs to read data using the kernel pagetables.
This paragraph wants dropping afaict - guest_io_okay() has explicit calls to toggle_guest_pt(), and hence is unaffected by the bug here (and there is in particular page tables reading involved there). Then ...
Quoted 3 lines
Reported-by Manuel Bouyer <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Tested-by Manuel Bouyer <[email protected]>
I was wondering however whether we really want a full revert. I've locally made the change below as an alternative.
Jan
x86/PV: guest_get_eff_kern_l1e() may still need to switch page tables
While indeed unnecessary for pv_ro_page_fault(), pv_map_ldt_shadow_page() may run when guest user mode is active, and hence may need to switch to the kernel page tables in order to retrieve an LDT page mapping.
---
This is the alternative to fully reverting the offending commit.
I've also been considering to drop the paging-mode-translate ASSERT(), now that we always have translate == external.
xen/arch/x86/pv/mm.h +9 -2
@@ -11,10 +11,14 @@ int new_guest_cr3(mfn_t mfn);*/ static inline l1_pgentry_t guest_get_eff_kern_l1e(unsigned long linear) { + struct vcpu *curr = current; l1_pgentry_t l1e; - ASSERT(!paging_mode_translate(current->domain)); - ASSERT(!paging_mode_external(current->domain)); + ASSERT(!paging_mode_translate(curr->domain)); + ASSERT(!paging_mode_external(curr->domain)); + + if ( !(curr->arch.flags & TF_kernel_mode) ) + toggle_guest_pt(curr); if ( unlikely(!__addr_ok(linear)) || __copy_from_user(&l1e,
@@ -22,6 +26,9 @@ static inline l1_pgentry_t guest_get_eff sizeof(l1_pgentry_t)) ) l1e =l1e_empty (); +if ( !(curr->arch.flags & TF_kernel_mode) ) +toggle_guest_pt (curr); +return l1e; }
Andrew Cooper
Reviewed-byQuoted 36 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
This reverts commit
9ff9705647646aa937b5f5c1426a64c69a62b3bd.The change is only correct in the original context of XSA-286, where Xen's use of the linear pagetables were dropped. However, performance problems interfered with that plan, and XSA-286 was fixed differently.
Quoted 8 lines
This broke Xen's lazy faulting of the LDT for 64bit PV guests when an access was first encountered in user context. Xen would proceed to read the registered LDT virtual address out of the user pagetables, not the kernel pagetables.
Given the nature of the bug, it would have also interfered with the IO permisison bitmap functionality of userspace, which similarly needs to read data using the kernel pagetables.
This paragraph wants dropping afaict -
guest_io_okay()has explicit calls totoggle_guest_pt(), and hence is unaffected by the bug here (and there is in particular page tables reading involved there). Then ...Quoted 3 lines
Reported-by Manuel Bouyer <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Tested-by Manuel Bouyer <[email protected]>Reviewed-by Jan Beulich <[email protected]>I was wondering however whether we really want a full revert. I've locally made the change below as an alternative.
Jan
x86/PV:
guest_get_eff_kern_l1e()may still need to switch page tablesWhile indeed unnecessary for
pv_ro_page_fault(),pv_map_ldt_shadow_page()may run when guest user mode is active, and hence may need to switch to the kernel page tables in order to retrieve an LDT page mapping.
Quoted 5 lines
Fixes 9ff970564764 ("x86/mm: drop guest_get_eff_l1e()")Reported-by Manuel Bouyer <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
This is the alternative to fully reverting the offending commit.
Hmm yes - I think I prefer this, because we don't really want to keep the non-kern alternative.
Quoted 2 lines
I've also been considering to drop the paging-mode-translate
ASSERT(), now that we always have translate == external.
I'd suggest not making that change here in this bugfix. I think we do want to alter how we do asserts like this, and there are other similarly impacted code blocks.
Quoted 6 lines
xen/arch/x86/pv/mm.h +0
-0@@ -11,10 +11,14 @@ int new_guest_cr3(mfn_t mfn);*/ static inline l1_pgentry_t guest_get_eff_kern_l1e (unsigned long linear)
xen/arch/x86/pv/mm.h int new_guest_cr3(mfn_t mfn); · line 20
Quoted 10 lines
xen/arch/x86/pv/mm.h +5
-2{ +struct vcpu *curr = current;l1_pgentry_t l1e; -ASSERT (!paging_mode_translate (current->domain)); -ASSERT (!paging_mode_external (current->domain)); +ASSERT (!paging_mode_translate (curr->domain)); +ASSERT (!paging_mode_external (curr->domain)); + +if ( !(curr->arch.flags & TF_kernel_mode) )
... pull this out into a variable, like the original code used to do.
bool user_mode = !(curr->arch.flags & TF_kernel_mode);
I've forgotten which static checker tripped up over this form, but one did IIRC.
~Andrew
Quoted 14 lines
xen/arch/x86/pv/mm.h +4
-0+toggle_guest_pt (curr);if (unlikely (!__addr_ok (linear)) || __copy_from_user(&l1e,@@ -22,6 +26,9 @@ static inline l1_pgentry_t guest_get_eff sizeof(l1_pgentry_t)) ) l1e =l1e_empty (); +if ( !(curr->arch.flags & TF_kernel_mode) ) +toggle_guest_pt (curr); +return l1e; }
Quoted 43 lines · Andrew Cooper
Quoted 36 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
This reverts commit
9ff9705647646aa937b5f5c1426a64c69a62b3bd.The change is only correct in the original context of XSA-286, where Xen's use of the linear pagetables were dropped. However, performance problems interfered with that plan, and XSA-286 was fixed differently.
Quoted 8 lines
This broke Xen's lazy faulting of the LDT for 64bit PV guests when an access was first encountered in user context. Xen would proceed to read the registered LDT virtual address out of the user pagetables, not the kernel pagetables.
Given the nature of the bug, it would have also interfered with the IO permisison bitmap functionality of userspace, which similarly needs to read data using the kernel pagetables.
This paragraph wants dropping afaict -
guest_io_okay()has explicit calls totoggle_guest_pt(), and hence is unaffected by the bug here (and there is in particular page tables reading involved there). Then ...Quoted 3 lines
Reported-by Manuel Bouyer <[email protected]>Signed-off-by Andrew Cooper <[email protected]>Tested-by Manuel Bouyer <[email protected]>Reviewed-by Jan Beulich <[email protected]>I was wondering however whether we really want a full revert. I've locally made the change below as an alternative.
Jan
x86/PV:
guest_get_eff_kern_l1e()may still need to switch page tablesWhile indeed unnecessary for
pv_ro_page_fault(),pv_map_ldt_shadow_page()may run when guest user mode is active, and hence may need to switch to the kernel page tables in order to retrieve an LDT page mapping.Quoted 5 lines
Fixes 9ff970564764 ("x86/mm: drop guest_get_eff_l1e()")Reported-by Manuel Bouyer <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
This is the alternative to fully reverting the offending commit.
Quoted 4 lines
Hmm yes - I think I prefer this, because we don't really want to keep the non-kern alternative.
Reviewed-by Andrew Cooper <[email protected]> however ...
Thanks.
Quoted 6 lines
Quoted 2 lines
I've also been considering to drop the paging-mode-translate
ASSERT(), now that we always have translate == external.I'd suggest not making that change here in this bugfix. I think we do want to alter how we do asserts like this, and there are other similarly impacted code blocks.
Okay, will look forward to learn what exactly you have in mind.
Quoted 18 lines
Quoted 5 lines
xen/arch/x86/pv/mm.h +0
-0@@ -11,10 +11,14 @@ int new_guest_cr3(mfn_t mfn);*/ static inline l1_pgentry_t guest_get_eff_kern_l1e (unsigned long linear)xen/arch/x86/pv/mm.h int new_guest_cr3(mfn_t mfn); · line 20
Quoted 10 lines
xen/arch/x86/pv/mm.h +5
-2{ +struct vcpu *curr = current;l1_pgentry_t l1e; -ASSERT (!paging_mode_translate (current->domain)); -ASSERT (!paging_mode_external (current->domain)); +ASSERT (!paging_mode_translate (curr->domain)); +ASSERT (!paging_mode_external (curr->domain)); + +if ( !(curr->arch.flags & TF_kernel_mode) )... pull this out into a variable, like the original code used to do.
Quoted 4 lines
bool
user_mode= !(curr->arch.flags &TF_kernel_mode);I've forgotten which static checker tripped up over this form, but one did IIRC.
I've made the change (will send the result in a minute), but I'm curious not so much which checker might have taken issue here but why.
Jan