x86/mm: widen locked region in xenmem_add_to_physmap_one()
authorJan Beulich <jbeulich@suse.com>
Wed, 25 Aug 2021 12:17:56 +0000 (14:17 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 25 Aug 2021 12:17:56 +0000 (14:17 +0200)
commitf147422bf9476fb8161b43e35f5901571ed17c35
tree837c765e26ceefa895a95c2e07519a6bf7e7679a
parent753cb68e653002e89fdcd1c80e52905fdbfb78cb
x86/mm: widen locked region in xenmem_add_to_physmap_one()

For pages which can be made part of the P2M by the guest, but which can
also later be de-allocated (grant table v2 status pages being the
present example), it is imperative that they be mapped at no more than a
single GFN. We therefore need to make sure that of two parallel
XENMAPSPACE_grant_table requests for the same status page one completes
before the second checks at which other GFN the underlying MFN is
presently mapped.

Pull ahead the respective get_gfn() and push down the respective
put_gfn(). This leverages that gfn_lock() really aliases p2m_lock(), but
the function makes this assumption already anyway: In the
XENMAPSPACE_gmfn case lock nesting constraints for both involved GFNs
would otherwise need to be enforced to avoid ABBA deadlocks.

This is CVE-2021-28697 / XSA-379.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
xen/arch/x86/mm/p2m.c