Skip to contentSkip to conversation

x86/p2m-pt: fix (latent) page table mapping leak on do_recalc() error paths

PATCH In review Jan Beulich 3 participants 3 messages Nov 25, 2019 – Nov 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/p2m-pt: fix (latent) page table mapping leak on do_recalc() error paths

There are two mappings active in the middle of do_recalc(), and hence commit 0d0f4d78e5d1 ("p2m: change write_p2m_entry to return an error code") should have added (or otherwise invoked) unmapping code just like it did in p2m_next_level(), despite us not expecting any errors here. Arrange for the existing unmap invocation to take effect in all cases.

xen/arch/x86/mm/p2m-pt.c +7 -6
@@ -391,21 +391,22 @@ static int do_recalc(struct p2m_domain *
                     if ( err )
                     {
                         ASSERT_UNREACHABLE();
-                        goto out;
+                        break;
                     }
                 }
                 remainder -= 1UL << ((level - 1) * PAGETABLE_ORDER);
             }
             smp_wmb();
-            clear_recalc(l1, e);
-            err = p2m->write_p2m_entry(p2m, gfn, pent, e, level + 1);
-            if ( err )
+            if ( !err )
             {
-                ASSERT_UNREACHABLE();
-                goto out;
+                clear_recalc(l1, e);
+                err = p2m->write_p2m_entry(p2m, gfn, pent, e, level + 1);
+                ASSERT(!err);
             }
         }
         unmap_domain_page((void *)((unsigned long)pent & PAGE_MASK));
+        if ( unlikely(err) )
+            goto out;
     }
 
     pent = p2m_find_entry(table, &gfn_remainder, gfn,

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jan Beulich

There are two mappings active in the middle of do_recalc(), and hence commit 0d0f4d78e5d1 ("p2m: change write_p2m_entry to return an error code") should have added (or otherwise invoked) unmapping code just like it did in p2m_next_level(), despite us not expecting any errors here. Arrange for the existing unmap invocation to take effect in all cases.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 8 lines · George Dunlap
Quoted 7 lines · Jan Beulich

There are two mappings active in the middle of do_recalc(), and hence commit 0d0f4d78e5d1 ("p2m: change write_p2m_entry to return an error code") should have added (or otherwise invoked) unmapping code just like it did in p2m_next_level(), despite us not expecting any errors here. Arrange for the existing unmap invocation to take effect in all cases.

Quoted 4 lines
Quoted 1 line

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel