iommu/vt-d: Fix possible invalid memory access caused by free_dmar_iommu()
Static identity and virtual machine domains may be cached in iommu->domain_ids array after corresponding IOMMUs have been removed from domain->iommu_bmp. So we should check domain->iommu_bmp before decreasing domain->iommu_count in function free_dmar_iommu(), otherwise it may cause free of inuse domain data structure. Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
This commit is contained in:
parent
44bde61428
commit
2a46ddf77c
1 changed files with 4 additions and 7 deletions
|
@ -425,6 +425,8 @@ static void domain_remove_one_dev_info(struct dmar_domain *domain,
|
||||||
struct device *dev);
|
struct device *dev);
|
||||||
static void iommu_detach_dependent_devices(struct intel_iommu *iommu,
|
static void iommu_detach_dependent_devices(struct intel_iommu *iommu,
|
||||||
struct device *dev);
|
struct device *dev);
|
||||||
|
static int domain_detach_iommu(struct dmar_domain *domain,
|
||||||
|
struct intel_iommu *iommu);
|
||||||
|
|
||||||
#ifdef CONFIG_INTEL_IOMMU_DEFAULT_ON
|
#ifdef CONFIG_INTEL_IOMMU_DEFAULT_ON
|
||||||
int dmar_disabled = 0;
|
int dmar_disabled = 0;
|
||||||
|
@ -1465,8 +1467,7 @@ static int iommu_init_domains(struct intel_iommu *iommu)
|
||||||
static void free_dmar_iommu(struct intel_iommu *iommu)
|
static void free_dmar_iommu(struct intel_iommu *iommu)
|
||||||
{
|
{
|
||||||
struct dmar_domain *domain;
|
struct dmar_domain *domain;
|
||||||
int i, count;
|
int i;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
if ((iommu->domains) && (iommu->domain_ids)) {
|
if ((iommu->domains) && (iommu->domain_ids)) {
|
||||||
for_each_set_bit(i, iommu->domain_ids, cap_ndoms(iommu->cap)) {
|
for_each_set_bit(i, iommu->domain_ids, cap_ndoms(iommu->cap)) {
|
||||||
|
@ -1479,11 +1480,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)
|
||||||
|
|
||||||
domain = iommu->domains[i];
|
domain = iommu->domains[i];
|
||||||
clear_bit(i, iommu->domain_ids);
|
clear_bit(i, iommu->domain_ids);
|
||||||
|
if (domain_detach_iommu(domain, iommu) == 0)
|
||||||
spin_lock_irqsave(&domain->iommu_lock, flags);
|
|
||||||
count = --domain->iommu_count;
|
|
||||||
spin_unlock_irqrestore(&domain->iommu_lock, flags);
|
|
||||||
if (count == 0)
|
|
||||||
domain_exit(domain);
|
domain_exit(domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue