VT-d: correct ordering of operations in cleanup_domid_map()
authorJan Beulich <jbeulich@suse.com>
Tue, 5 Apr 2022 12:12:27 +0000 (14:12 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 5 Apr 2022 12:12:27 +0000 (14:12 +0200)
commitd9eca7bb6c6636eb87bb17b08ba7de270f47ecd0
tree3dbff083c48fe75d8f3df8774289d1af5bcb9f46
parent4f4db53784d912c4f409a451c36ebfd4754e0a42
VT-d: correct ordering of operations in cleanup_domid_map()

The function may be called without any locks held (leaving aside the
domctl one, which we surely don't want to depend on here), so needs to
play safe wrt other accesses to domid_map[] and domid_bitmap[]. This is
to avoid context_set_domain_id()'s writing of domid_map[] to be reset to
zero right away in the case of it racing the freeing of a DID.

For the interaction with context_set_domain_id() and did_to_domain_id()
see the code comment.

{check_,}cleanup_domid_map() are called with pcidevs_lock held or during
domain cleanup only (and pcidevs_lock is also held around
context_set_domain_id()), i.e. racing calls with the same (dom, iommu)
tuple cannot occur.

domain_iommu_domid(), besides its use by cleanup_domid_map(), has its
result used only to control flushing, and hence a stale result would
only lead to a stray extra flush.

This is CVE-2022-26357 / XSA-399.

Fixes: b9c20c78789f ("VT-d: per-iommu domain-id")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
xen/drivers/passthrough/vtd/iommu.c