From: Roger Pau Monne Date: Thu, 3 Dec 2026 17:53:44 +0100 Subject: [PATCH] x86/hvm: check the type of grant mappings on unmap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a grant is unmapped from an HVM/PVH guest, Xen removes the p2m entry at the address supplied by the guest and releases the pin held by the mapping handle. replace_grant_p2m_mapping() only checks that the entry at that address is a grant mapping of the expected frame, not whether it's a read-only or a read-write one. A guest having the same frame mapped both read-write and read-only can hence unmap the read-write handle while passing the address of the read-only mapping. The write pin is then dropped, together with the writable type reference if one was taken, while the read-write p2m entry stays in place backed only by the read pin of the other handle. Refuse the unmap unless the type of the p2m entry matches the flags the handle was mapped with. The flags passed to the function are already those of the existing mapping, so no new parameter is needed. This is the HVM counterpart of XSA-234, which added the equivalent check for PV guests in 16b1414de91b ("gnttab: also validate PTE permissions upon destroy/replace"). This is XSA-543 / CVE-2026-142564 Fixes: b37d30c8fc52 ("Mapping grant references into HVM guests, take 2") Signed-off-by: Roger Pau Monné Reviewed-by: Andrew Cooper --- xen/arch/x86/hvm/grant_table.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/hvm/grant_table.c b/xen/arch/x86/hvm/grant_table.c index afe449d8882c..fa8c17199da4 100644 --- a/xen/arch/x86/hvm/grant_table.c +++ b/xen/arch/x86/hvm/grant_table.c @@ -38,7 +38,8 @@ int replace_grant_p2m_mapping(uint64_t addr, mfn_t frame, uint64_t new_addr, unsigned int flags) { unsigned long gfn = (unsigned long)(addr >> PAGE_SHIFT); - p2m_type_t type; + p2m_type_t type, exp_type = (flags & GNTMAP_readonly) ? p2m_grant_map_ro + : p2m_grant_map_rw; mfn_t old_mfn; struct domain *d = current->domain; @@ -46,7 +47,7 @@ int replace_grant_p2m_mapping(uint64_t addr, mfn_t frame, return GNTST_general_error; old_mfn = get_gfn_query(d, gfn, &type); - if ( !p2m_is_grant(type) || !mfn_eq(old_mfn, frame) ) + if ( type != exp_type || !mfn_eq(old_mfn, frame) ) { put_gfn(d, gfn); gdprintk(XENLOG_WARNING, -- 2.55.0