Skip to contentSkip to conversation

x86/p2m: fix p2m_add_foreign error path

PATCH In review Roger Pau Monne 2 participants 2 messages Jan 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/p2m: fix p2m_add_foreign error path

One of the error paths in p2m_add_foreign could call put_page with a NULL page, thus triggering a fault.

Split the checks into two different if statements, so the appropriate error path can be taken.

Fixes 173ae325026bd ('x86/p2m: tidy p2m_add_foreign() a little')
---
 xen/arch/x86/mm/p2m.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
xen/arch/x86/mm/p2m.c +7 -2
index 487959b121..a4ebfc9b21 100644
@@ -2601,8 +2601,13 @@ static int p2m_add_foreign(struct domain *tdom, unsigned long fgfn,
      *     ram_rw | ram_logdirty | ram_ro | paging_out.
      */
     page = get_page_from_gfn(fdom, fgfn, &p2mt, P2M_ALLOC);
-    if ( !page ||
-         !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) )
+    if ( !page )
+    {
+        rc = -EINVAL;
+        goto out;
+    }
+
+    if ( !p2m_is_ram(p2mt) || p2m_is_shared(p2mt) || p2m_is_hole(p2mt) )
     {
         rc = -EINVAL;
         goto put_one;
Signature · 1 line
2.29.2
#1 lore raw
Quoted 8 lines · Roger Pau Monne

One of the error paths in p2m_add_foreign could call put_page with a NULL page, thus triggering a fault.

Split the checks into two different if statements, so the appropriate error path can be taken.

Fixes 173ae325026bd ('x86/p2m: tidy p2m_add_foreign() a little')

Acked and committed.

~Andrew