Skip to content

Commit 104eef9

Browse files
jbeulichgregkh
authored andcommitted
Xen/x86: don't bail early from clear_foreign_p2m_mapping()
commit a35f2ef upstream. Its sibling (set_foreign_p2m_mapping()) as well as the sibling of its only caller (gnttab_map_refs()) don't clean up after themselves in case of error. Higher level callers are expected to do so. However, in order for that to really clean up any partially set up state, the operation should not terminate upon encountering an entry in unexpected state. It is particularly relevant to notice here that set_foreign_p2m_mapping() would skip setting up a p2m entry if its grant mapping failed, but it would continue to set up further p2m entries as long as their mappings succeeded. Arguably down the road set_foreign_p2m_mapping() may want its page state related WARN_ON() also converted to an error return. This is part of XSA-361. Signed-off-by: Jan Beulich <jbeulich@suse.com> Cc: stable@vger.kernel.org Reviewed-by: Juergen Gross <jgross@suse.com> Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 49de0a1 commit 104eef9

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

arch/x86/xen/p2m.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,17 +754,15 @@ int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
754754
unsigned long mfn = __pfn_to_mfn(page_to_pfn(pages[i]));
755755
unsigned long pfn = page_to_pfn(pages[i]);
756756

757-
if (mfn == INVALID_P2M_ENTRY || !(mfn & FOREIGN_FRAME_BIT)) {
757+
if (mfn != INVALID_P2M_ENTRY && (mfn & FOREIGN_FRAME_BIT))
758+
set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
759+
else
758760
ret = -EINVAL;
759-
goto out;
760-
}
761-
762-
set_phys_to_machine(pfn, INVALID_P2M_ENTRY);
763761
}
764762
if (kunmap_ops)
765763
ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref,
766-
kunmap_ops, count);
767-
out:
764+
kunmap_ops, count) ?: ret;
765+
768766
return ret;
769767
}
770768
EXPORT_SYMBOL_GPL(clear_foreign_p2m_mapping);

0 commit comments

Comments
 (0)