[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging-4.22] xen/mm: reorder page vs gfn release order in guest_remove_page()



commit 0b46235b8e109b24f64e63502ceeb63c248cf51c
Author:     Roger Pau Monné <roger@xxxxxxxxxxxxxx>
AuthorDate: Thu Nov 26 17:46:42 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Nov 26 17:46:42 2026 +0100

    xen/mm: reorder page vs gfn release order in guest_remove_page()
    
    The current order of put_page() and put_gfn() calls can lead to the removed
    page being freed before performing a p2m TLB flush, if the caller of
    guest_remove_page() doesn't hold a reference to the page being unhooked
    from the p2m.
    
    Invert the call order, so that the p2m is unlocked first, possibly carrying
    any deferred flushes, and the page is released afterwards.  This fixes the
    usage of guest_remove_page() in decrease_reservation(), that would
    otherwise free the pages before the p2m flush.
    
    Note there are calls to guest_remove_page() with the p2m lock already held;
    those are dealt with in separate changes.
    
    This is XSA-535 / CVE-2026-119781
    
    Fixes: 09fc40ed3054 ("x86/ept: defer the invalidation until the p2m lock is 
released")
    Fixes: e1604ea82700 ("x86/hap: Defer NPT P2M TLB flushes")
    Signed-off-by: Roger Pau Monné <roger@xxxxxxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    master commit: 6019959aecb1a78227c8773d7b0dccdc74a9f28b
    master date: 2026-11-26 17:26:00 +0100
---
 xen/common/memory.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/xen/common/memory.c b/xen/common/memory.c
index ff2ed61fe2..4cbbe723ee 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -407,7 +407,7 @@ out:
 
 int guest_remove_page(struct domain *d, unsigned long gmfn)
 {
-    struct page_info *page;
+    struct page_info *page = NULL;
 #ifdef CONFIG_X86
     p2m_type_t p2mt;
 #endif
@@ -528,13 +528,19 @@ int guest_remove_page(struct domain *d, unsigned long 
gmfn)
     if ( !rc && !is_domain_direct_mapped(d) )
         put_page_alloc_ref(page);
 
-    put_page(page);
-
 #ifdef CONFIG_X86
  out_put_gfn:
     put_gfn(d, gmfn);
 #endif
 
+    /*
+     * Do the final put page after the p2m flush possibly done when putting the
+     * gfn.  Otherwise we risk freeing the page while there are stale p2m TLB
+     * entries.
+     */
+    if ( page )
+        put_page(page);
+
     /*
      * Filter out -ENOENT return values that aren't a result of an empty p2m
      * entry.
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.22



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.