]> xenbits.xensource.com Git - xen.git/commit
x86/mm: relinquish_memory: Grab an extra type ref when setting PGT_partial
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 11 Dec 2019 14:13:34 +0000 (15:13 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 11 Dec 2019 14:13:34 +0000 (15:13 +0100)
commit1363b37da29d4123d6f8680c569fd31f2899de25
tree105fbd56b610491ffbb78cf0368c6d3448cf56c5
parent570190751a012c74f27003d498386b609e965e15
x86/mm: relinquish_memory: Grab an extra type ref when setting PGT_partial

The PGT_partial bit in page->type_info holds both a type count and a
general ref count.  During domain tear-down, when free_page_type()
returns -ERESTART, relinquish_memory() correctly handles the general
ref count, but fails to grab an extra type count when setting
PGT_partial.  When this bit is eventually cleared, type_count underflows
and triggers the following BUG in page_alloc.c:free_domheap_pages():

    BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);

As far as we can tell, this page underflow cannot be exploited any any
other way: The page can't be used as a pagetable by the dying domain
because it's dying; it can't be used as a pagetable by any other
domain since it belongs to the dying domain; and ownership can't
transfer to any other domain without hitting the BUG_ON() in
free_domheap_pages().

(steal_page() won't work on a page in this state, since it requires
PGC_allocated to be set, and PGC_allocated will already have been
cleared.)

Fix this by grabbing an extra type ref if setting PGT_partial in
relinquish_memory.

This is part of XSA-310.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
master commit: 66bdc16aeed8ddb2ae724adc5ea6bde0dea78c3d
master date: 2019-12-11 14:55:08 +0100
xen/arch/x86/domain.c