Skip to contentSkip to conversation

Xen Security Advisory 535 v1 (CVE-2026-119781,CVE-2026-119782,CVE-2026-119783) - x86: Incorrect ordering of page-freeing and p2m flush

PATCH Xen.org security team 1 participant 1 message Nov 26

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Xen Security Advisory CVE-2026-119781,CVE-2026-119782,CVE-2026-119783 / XSA-535

x86: Incorrect ordering of page-freeing and p2m flush

ISSUE DESCRIPTION
=================

For HVM and PVH guests using HAP, Xen defers the TLB flush that follows a p2m change until the p2m lock is released, so that several changes done under the same locked region issue a single flush.

Some paths that remove a page from the p2m however drop the last reference to the page before that flush is done. The page is then freed, and can be reused, while stale TLB entries still allow the guest to access it.

IMPACT
======

A guest can retain access to memory it no longer owns. This can lead to privilege escalation, Denial of Service (DoS) affecting the entire host, and information leaks.

VULNERABLE SYSTEMS
==================

Xen versions 4.7 and onwards are vulnerable. Xen versions 4.6 and older are not vulnerable.

Only x86 systems are vulnerable. Arm systems are not vulnerable.

On Intel hardware all vulnerable versions are affected. On AMD hardware only Xen versions 4.22 and onwards are affected.

Only HVM and PVH guests using HAP can leverage the vulnerability.

MITIGATION
==========

There is no known mitigation.

CREDITS
=======

This issue was discovered by Roger Pau Monné of AMD.

RESOLUTION
==========

Applying the appropriate set of attached patches resolves this issue.

Note that patches for released versions are generally prepared to apply to the stable branches, and may not apply cleanly to the most recent release tarball. Downstreams are encouraged to update to the tip of the stable branch before applying these patches.

xsa535/xsa535-?.patch xen-unstable - Xen 4.19.x
xsa535/xsa535-4.18-?.patch Xen 4.18.x - Xen 4.17.x

$ sha256sum xsa535*/*
42083890ae0518a4aa8b786d291791bb449405044f47afdbd55a5fd2f1933dd4  xsa535/xsa535-1.patch
cc0adac0222471f599c88f79109fd84d75849daf69b9f106102e28d2eb38ad14  xsa535/xsa535-2.patch
9c1e52c6f4f3f97c081793bbf6d722ac94276195067265a3c415a7396a9b2714  xsa535/xsa535-3.patch
a9a2a89bd14a33fc5096cff3edd1a89817c68d42f4d715823c9ca700b86c80f5  xsa535/xsa535-4.18-1.patch
848a13e675915978b482f6023b7e063319f8ade582e3af7ae7f6eecca2794b44  xsa535/xsa535-4.18-2.patch
0677d16bccb92336792bea455a793063bc3753391e00b59897e444a9c2126770  xsa535/xsa535-4.18-3.patch
$

NOTE REGARDING LACK OF EMBARGO
==============================

While the Xen Security Team was working on a fix, a 3rd party posted an incorrect fix for the same issue publicly. That fix only changes the removal of foreign mappings, and does not resolve this issue. -----BEGIN PGP SIGNATURE-----

iQFABAEBCAAqFiEEI+MiLBRfRHX6gGCng/4UyVfoK9kFAmsIWKMMHHBncEB4ZW4u b3JnAAoJEIP+FMlX6CvZglgH/3WrMR6rc+g1x5LGBiGB5xnLZqoezvtkqtASQsSE 7Lf3wfkcCoJRHu+4b63cnqe6M5EbniC2xuUPFRle/lz7j7zw0iS7yC+BxKpG+V7O o76Alivp4JJB4gFSOvwTyU3ayrnPnsgP9K0jMm3dqHwUCDNSPZBZiY9tCNTvU39k TeUB5mvrPdy8HLgX31ej12gX17ORITPU3UK6l9xL2fB54/0nR5jqNPG4h8o5QQzJ do6HYM2LjS0YnHcoP5/dUhIzVs0hRaCjcnq4Xgbz5trHHB6FJhkeWk01Ny8whKBK z+ubbHK8+mnQtklpOmC0ukB7zCz3vRNywrmST9jqysSctH8=
=FsFr
-----END PGP SIGNATURE-----

From: Roger Pau Monne <[email protected]>
Date: Mon, 26 Oct 2026 18:11:43 +0100
Subject: [PATCH 1/3] xen/mm: reorder page vs gfn release order in
guest_remove_page()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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")
---
 xen/common/memory.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
xen/common/memory.c +9 -3
index 4afa2271b7fe..3abdf27d2d3b 100644
@@ -408,7 +408,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
@@ -529,13 +529,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.
Signature · 1 line
2.55.0

From: Roger Pau Monne <[email protected]>
Date: Tue, 27 Oct 2026 09:02:05 +0100
Subject: [PATCH 2/3] x86/mm: take an extra page reference in
xenmem_add_to_physmap_one()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

xenmem_add_to_physmap_one() holds the domain's p2m lock when calling guest_remove_page(), which inhibits the p2m TLB flush when guest_remove_page() releases the gfn. However xenmem_add_to_physmap_one() does not hold a reference to the removed page, and so the page is freed when guest_remove_page() calls put_page() on it. This is problematic, as the page is freed before the p2m TLB is flushed.

Modify xenmem_add_to_physmap_one() so it takes a reference to the page to be removed, and make sure that reference is only dropped after the p2m lock has been released. Note the GFN to be removed needs to be unshared before the reference is taken, as otherwise the call to get_page() would fail if the entry is shared.

Also add an ASSERT() to ensure the function is called without the p2m being already locked, so that we ensure the last put_gfn() in the function performs a p2m flush if needed.

This is XSA-535 / CVE-2026-119782

---
 xen/arch/x86/mm/p2m.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +23 -2
index bb0356396ce1..588aedbb28bc 100644
@@ -2001,13 +2001,15 @@ int xenmem_add_to_physmap_one(
     unsigned long idx,
     gfn_t gfn)
 {
-    struct page_info *page = NULL;
+    struct page_info *page = NULL, *prev_page = NULL;
     unsigned long gmfn = 0 /* gcc ... */, old_gfn;
     mfn_t prev_mfn;
     int rc = 0;
     mfn_t mfn = INVALID_MFN;
     p2m_type_t p2mt;
 
+    ASSERT(!p2m_locked_by_me(p2m_get_hostp2m(d)));
+
     switch ( space )
     {
     case XENMAPSPACE_shared_info:
@@ -2063,8 +2065,15 @@ int xenmem_add_to_physmap_one(
      * general, for pages which can subsequently be freed this imperative:
      * Upon freeing we wouldn't be able to find other mappings in the P2M
      * (unless we did a brute force search).
+     *
+     * FIXME: remove a shared p2m entry directly, without unsharing first.
      */
-    prev_mfn = get_gfn(d, gfn_x(gfn), &p2mt);
+    prev_mfn = get_gfn_unshare(d, gfn_x(gfn), &p2mt);
+    if ( p2m_is_shared(p2mt) )
+    {
+        rc = -ENOMEM;
+        goto put_all;
+    }
 
     /* XENMAPSPACE_gmfn: Check if the MFN is associated with another GFN. */
     old_gfn = get_gpfn_from_mfn(mfn_x(mfn));
@@ -2084,8 +2093,17 @@ int xenmem_add_to_physmap_one(
             /* Special pages are simply unhooked from this phys slot. */
             rc = p2m_remove_page(d, gfn, prev_mfn, PAGE_ORDER_4K);
         else if ( !mfn_eq(mfn, prev_mfn) )
+        {
+            prev_page = mfn_to_page(prev_mfn);
+            if ( !get_page(prev_page, d) )
+            {
+                prev_page = NULL;
+                rc = -ENXIO;
+                goto put_all;
+            }
             /* Normal domain memory is freed, to avoid leaking memory. */
             rc = guest_remove_page(d, gfn_x(gfn));
+        }
     }
 
     /* Unmap from old location, if any. */
@@ -2127,6 +2145,9 @@ int xenmem_add_to_physmap_one(
     if ( page )
         put_page(page);
 
+    if ( prev_page )
+        put_page(prev_page);
+
     return rc;
 }
 
Signature · 1 line
2.55.0

From: Roger Pau Monne <[email protected]>
Date: Tue, 27 Oct 2026 09:02:32 +0100
Subject: [PATCH 3/3] x86/mm: take an extra page reference in p2m_add_foreign()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

p2m_add_foreign() holds the domain's p2m lock when calling guest_remove_page(), which inhibits the p2m TLB flush when guest_remove_page() releases the gfn. However p2m_add_foreign() does not hold a reference to the removed page, and so the page is freed when guest_remove_page() calls put_page() on it. This is problematic, as the page is freed before the p2m TLB is flushed.

Modify p2m_add_foreign() so it takes a reference to the page to be removed, and make sure that reference is only dropped after the p2m lock has been released. Note the GFN to be removed needs to be unshared before the reference is taken, as otherwise the call to get_page() would fail if the entry is shared.

Also add an ASSERT() to ensure the function is called without the p2m being already locked, so that we ensure the last put_gfn() in the function performs a p2m flush if needed.

This is XSA-535 / CVE-2026-119783

---
 xen/arch/x86/mm/p2m.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +22 -2
index 588aedbb28bc..578d00ee3093 100644
@@ -1910,10 +1910,12 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
 {
     p2m_type_t p2mt, p2mt_prev;
     mfn_t prev_mfn, mfn;
-    struct page_info *page;
+    struct page_info *page, *prev_page = NULL;
     int rc;
     struct domain *fdom;
 
+    ASSERT(!p2m_locked_by_me(p2m_get_hostp2m(tdom)));
+
     if ( !arch_acquire_resource_check(tdom) )
         return -EPERM;
 
@@ -1953,15 +1955,30 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
     mfn = page_to_mfn(page);
 
     /* Remove previously mapped page if it is present. */
-    prev_mfn = get_gfn(tdom, gpfn, &p2mt_prev);
+    prev_mfn = get_gfn_unshare(tdom, gpfn, &p2mt_prev);
+    if ( p2m_is_shared(p2mt_prev) )
+    {
+        rc = -ENOMEM;
+        goto put_both;
+    }
+
     if ( mfn_valid(prev_mfn) )
     {
         if ( is_special_page(mfn_to_page(prev_mfn)) )
             /* Special pages are simply unhooked from this phys slot */
             rc = p2m_remove_page(tdom, _gfn(gpfn), prev_mfn, 0);
         else
+        {
+            prev_page = mfn_to_page(prev_mfn);
+            if ( !get_page(prev_page, tdom) )
+            {
+                prev_page = NULL;
+                rc = -ENXIO;
+                goto put_both;
+            }
             /* Normal domain memory is freed, to avoid leaking memory. */
             rc = guest_remove_page(tdom, gpfn);
+        }
         if ( rc )
             goto put_both;
     }
@@ -1984,6 +2001,9 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
      */
     put_gfn(tdom, gpfn);
 
+    if ( prev_page )
+        put_page(prev_page);
+
  put_one:
     put_page(page);
 
Signature · 1 line
2.55.0

From: Roger Pau Monne <[email protected]>
Date: Mon, 26 Oct 2026 18:11:43 +0100
Subject: [PATCH 1/3] xen/mm: reorder page vs gfn release order in
guest_remove_page()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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")
---
 xen/common/memory.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
xen/common/memory.c +9 -3
index 640f3a70ab54..d9efa9562dfe 100644
@@ -293,7 +293,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
@@ -414,13 +414,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.
Signature · 1 line
2.55.0

From: Roger Pau Monne <[email protected]>
Date: Tue, 27 Oct 2026 09:02:05 +0100
Subject: [PATCH 2/3] x86/mm: take an extra page reference in
xenmem_add_to_physmap_one()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

xenmem_add_to_physmap_one() holds the domain's p2m lock when calling guest_remove_page(), which inhibits the p2m TLB flush when guest_remove_page() releases the gfn. However xenmem_add_to_physmap_one() does not hold a reference to the removed page, and so the page is freed when guest_remove_page() calls put_page() on it. This is problematic, as the page is freed before the p2m TLB is flushed.

Modify xenmem_add_to_physmap_one() so it takes a reference to the page to be removed, and make sure that reference is only dropped after the p2m lock has been released. Note the GFN to be removed needs to be unshared before the reference is taken, as otherwise the call to get_page() would fail if the entry is shared.

Also add an ASSERT() to ensure the function is called without the p2m being already locked, so that we ensure the last put_gfn() in the function performs a p2m flush if needed.

This is XSA-535 / CVE-2026-119782

---
 xen/arch/x86/mm/p2m.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +23 -2
index 511b251bc339..e539020308cd 100644
@@ -2431,13 +2431,15 @@ int xenmem_add_to_physmap_one(
     unsigned long idx,
     gfn_t gpfn)
 {
-    struct page_info *page = NULL;
+    struct page_info *page = NULL, *prev_page = NULL;
     unsigned long gfn = 0 /* gcc ... */, old_gpfn;
     mfn_t prev_mfn;
     int rc = 0;
     mfn_t mfn = INVALID_MFN;
     p2m_type_t p2mt;
 
+    ASSERT(!p2m_locked_by_me(p2m_get_hostp2m(d)));
+
     switch ( space )
     {
     case XENMAPSPACE_shared_info:
@@ -2487,8 +2489,15 @@ int xenmem_add_to_physmap_one(
      * general, for pages which can subsequently be freed this imperative:
      * Upon freeing we wouldn't be able to find other mappings in the P2M
      * (unless we did a brute force search).
+     *
+     * FIXME: remove a shared p2m entry directly, without unsharing first.
      */
-    prev_mfn = get_gfn(d, gfn_x(gpfn), &p2mt);
+    prev_mfn = get_gfn_unshare(d, gfn_x(gpfn), &p2mt);
+    if ( p2m_is_shared(p2mt) )
+    {
+        rc = -ENOMEM;
+        goto put_all;
+    }
 
     /* XENMAPSPACE_gmfn: Check if the MFN is associated with another GFN. */
     old_gpfn = get_gpfn_from_mfn(mfn_x(mfn));
@@ -2508,8 +2517,17 @@ int xenmem_add_to_physmap_one(
             /* Special pages are simply unhooked from this phys slot. */
             rc = p2m_remove_page(d, gpfn, prev_mfn, PAGE_ORDER_4K);
         else if ( !mfn_eq(mfn, prev_mfn) )
+        {
+            prev_page = mfn_to_page(prev_mfn);
+            if ( !get_page(prev_page, d) )
+            {
+                prev_page = NULL;
+                rc = -ENXIO;
+                goto put_all;
+            }
             /* Normal domain memory is freed, to avoid leaking memory. */
             rc = guest_remove_page(d, gfn_x(gpfn));
+        }
     }
 
     /* Unmap from old location, if any. */
@@ -2551,6 +2569,9 @@ int xenmem_add_to_physmap_one(
     if ( page )
         put_page(page);
 
+    if ( prev_page )
+        put_page(prev_page);
+
     return rc;
 }
 
Signature · 1 line
2.55.0

From: Roger Pau Monne <[email protected]>
Date: Tue, 27 Oct 2026 09:02:32 +0100
Subject: [PATCH 3/3] x86/mm: take an extra page reference in p2m_add_foreign()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

p2m_add_foreign() holds the domain's p2m lock when calling guest_remove_page(), which inhibits the p2m TLB flush when guest_remove_page() releases the gfn. However p2m_add_foreign() does not hold a reference to the removed page, and so the page is freed when guest_remove_page() calls put_page() on it. This is problematic, as the page is freed before the p2m TLB is flushed.

Modify p2m_add_foreign() so it takes a reference to the page to be removed, and make sure that reference is only dropped after the p2m lock has been released. Note the GFN to be removed needs to be unshared before the reference is taken, as otherwise the call to get_page() would fail if the entry is shared.

Also add an ASSERT() to ensure the function is called without the p2m being already locked, so that we ensure the last put_gfn() in the function performs a p2m flush if needed.

This is XSA-535 / CVE-2026-119783

---
 xen/arch/x86/mm/p2m.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +22 -2
index e539020308cd..d99e8d510a39 100644
@@ -2336,10 +2336,12 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
 {
     p2m_type_t p2mt, p2mt_prev;
     mfn_t prev_mfn, mfn;
-    struct page_info *page;
+    struct page_info *page, *prev_page = NULL;
     int rc;
     struct domain *fdom;
 
+    ASSERT(!p2m_locked_by_me(p2m_get_hostp2m(tdom)));
+
     /*
      * hvm fixme: until support is added to p2m teardown code to cleanup any
      * foreign entries, limit this to hardware domain only.
@@ -2383,15 +2385,30 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
     mfn = page_to_mfn(page);
 
     /* Remove previously mapped page if it is present. */
-    prev_mfn = get_gfn(tdom, gpfn, &p2mt_prev);
+    prev_mfn = get_gfn_unshare(tdom, gpfn, &p2mt_prev);
+    if ( p2m_is_shared(p2mt_prev) )
+    {
+        rc = -ENOMEM;
+        goto put_both;
+    }
+
     if ( mfn_valid(prev_mfn) )
     {
         if ( is_special_page(mfn_to_page(prev_mfn)) )
             /* Special pages are simply unhooked from this phys slot */
             rc = p2m_remove_page(tdom, _gfn(gpfn), prev_mfn, 0);
         else
+        {
+            prev_page = mfn_to_page(prev_mfn);
+            if ( !get_page(prev_page, tdom) )
+            {
+                prev_page = NULL;
+                rc = -ENXIO;
+                goto put_both;
+            }
             /* Normal domain memory is freed, to avoid leaking memory. */
             rc = guest_remove_page(tdom, gpfn);
+        }
         if ( rc )
             goto put_both;
     }
@@ -2414,6 +2431,9 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
      */
     put_gfn(tdom, gpfn);
 
+    if ( prev_page )
+        put_page(prev_page);
+
  put_one:
     put_page(page);
 
Signature · 1 line
2.55.0