iommu/virtio: Fix freeing of incomplete domains
authorJean-Philippe Brucker <jean-philippe@linaro.org>
Thu, 26 Mar 2020 09:35:57 +0000 (10:35 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Apr 2020 08:36:39 +0000 (10:36 +0200)
commit9c01a49a7117fa824ee0703c9f46b2fa54dfd94d
treed16782638007f4341855da1aa5dd246839c07f9c
parent475bec7063bcc941c3bbb4acc9c9f402259afadc
iommu/virtio: Fix freeing of incomplete domains

[ Upstream commit 7062af3ed2ba451029e3733d9f677c68f5ea9e77 ]

Calling viommu_domain_free() on a domain that hasn't been finalised (not
attached to any device, for example) can currently cause an Oops,
because we attempt to call ida_free() on ID 0, which may either be
unallocated or used by another domain.

Only initialise the vdomain->viommu pointer, which denotes a finalised
domain, at the end of a successful viommu_domain_finalise().

Fixes: edcd69ab9a32 ("iommu: Add virtio-iommu driver")
Reported-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/20200326093558.2641019-3-jean-philippe@linaro.org
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/virtio-iommu.c