p2m: Check return value of p2m_set_entry() when decreasing reservation
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 10 Nov 2017 16:53:55 +0000 (16:53 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Nov 2017 11:26:37 +0000 (11:26 +0000)
commit324f9a4776f49ae75d2943ac1c64dc2db5fb5761
tree912652d378246a51cfccecef4364f4352c36d21d
parent0533bae0a857a6c27daf20ca803a327977fe3432
p2m: Check return value of p2m_set_entry() when decreasing reservation

If the entire range specified to p2m_pod_decrease_reservation() is marked
populate-on-demand, then it will make a single p2m_set_entry() call,
reducing its PoD entry count.

Unfortunately, in the right circumstances, this p2m_set_entry() call
may fail.  It that case, repeated calls to decrease_reservation() may
cause p2m->pod.entry_count to fall below zero, potentially tripping
over BUG_ON()s to the contrary.

Instead, check to see if the entry succeeded, and return false if not.
The caller will then call guest_remove_page() on the gfns, which will
return -EINVAL upon finding no valid memory there to return.

Unfortunately if the order > 0, the entry may have partially changed.
A domain_crash() is probably the safest thing in that case.

Other p2m_set_entry() calls in the same function should be fine,
because they are writing the entry at its current order.  Nonetheless,
check the return value and crash if our assumption turns otu to be
wrong.

This is part of XSA-247.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Gbp-Pq: Name p2m-check-return-value-of-p2m_set_entry-.patch
xen/arch/x86/mm/p2m-pod.c