]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
x86: don't allow page_unlock() to drop the last type reference
authorJan Beulich <jbeulich@suse.com>
Wed, 27 Sep 2017 10:00:56 +0000 (11:00 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 12 Oct 2017 12:49:46 +0000 (14:49 +0200)
Only _put_page_type() does the necessary cleanup, and hence not all
domain pages can be released during guest cleanup (leaving around
zombie domains) if we get this wrong.

This is XSA-242.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/mm.c

index 1247e1397d42b5d23532cb922e88c7f8a1d892e6..5628bc73895641f5a0cb141051061669ea7c4e57 100644 (file)
@@ -1705,7 +1705,11 @@ void page_unlock(struct page_info *page)
 
     do {
         x = y;
+        ASSERT((x & PGT_count_mask) && (x & PGT_locked));
+
         nx = x - (1 | PGT_locked);
+        /* We must not drop the last reference here. */
+        ASSERT(nx & PGT_count_mask);
     } while ( (y = cmpxchg(&page->u.inuse.type_info, x, nx)) != x );
 }
 
@@ -2308,6 +2312,17 @@ static int _put_page_type(struct page_info *page, bool preemptible,
 
             set_tlbflush_timestamp(page);
         }
+        else if ( unlikely((nx & (PGT_locked | PGT_count_mask)) ==
+                           (PGT_locked | 1)) )
+        {
+            /*
+             * We must not drop the second to last reference when the page is
+             * locked, as page_unlock() doesn't do any cleanup of the type.
+             */
+            cpu_relax();
+            y = page->u.inuse.type_info;
+            continue;
+        }
 
         if ( likely((y = cmpxchg(&page->u.inuse.type_info, x, nx)) == x) )
             break;