iommu/vt-d: Detach domain before using a private one
PATCH 1/2 iommu/vt-d: Detach domain before using a private one
When the default domain of a group doesn't work for a device, the iommu driver will try to use a private domain. The domain which was previously attached to the device must be detached.
--- drivers/iommu/intel-iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +5 -1
@@ -3449,6 +3449,7 @@ static bool iommu_need_mapping(struct device *dev) dmar_domain =to_dmar_domain (domain); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ; } +dmar_remove_one_dev_info (dev);get_private_domain_for_dev (dev); }
@@ -4803,7 +4804,8 @@ static void dmar_remove_one_dev_info(struct device *dev)spin_lock_irqsave (&device_domain_lock, flags); info = dev->archdata.iommu; -__dmar_remove_one_dev_info (info); +if (info) +__dmar_remove_one_dev_info (info);spin_unlock_irqrestore (&device_domain_lock, flags); }
@@ -5281,6 +5283,7 @@ static int intel_iommu_add_device(struct device *dev)if (device_def_domain_type (dev) ==IOMMU_DOMAIN_IDENTITY ) { ret =iommu_request_dm_for_dev (dev);if (ret) { +dmar_remove_one_dev_info (dev); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ;domain_add_dev_info (si_domain, dev); dev_info(dev,
@@ -5291,6 +5294,7 @@ static int intel_iommu_add_device(struct device *dev)if (device_def_domain_type (dev) ==IOMMU_DOMAIN_DMA ) { ret =iommu_request_dma_domain_for_dev (dev);if (ret) { +dmar_remove_one_dev_info (dev); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ;if (!get_private_domain_for_dev (dev)) { dev_warn(dev,
Signature · 1 line
2.17.1
PATCH 2/2 iommu/vt-d: Fix possible use-after-free of private domain
Multiple devices might share a private domain. One real example is a pci bridge and all devices behind it. When remove a private domain, make sure that it has been detached from all devices to avoid use-after-free case.
--- drivers/iommu/intel-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/intel-iommu.c +2 -1
@@ -4791,7 +4791,8 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info)/* free the private domain */ if (domain->flags &DOMAIN_FLAG_LOSE_CHILDREN && - !(domain->flags &DOMAIN_FLAG_STATIC_IDENTITY )) + !(domain->flags &DOMAIN_FLAG_STATIC_IDENTITY ) && +list_empty (&domain->devices))domain_exit (info->domain);free_devinfo_mem (info);
Signature · 6 lines
2.17.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 12 lines · On Tue, 6 Aug 2019 08:14:08 +0800 Lu Baolu <[email protected]> wrote:
When the default domain of a group doesn't work for a device, the iommu driver will try to use a private domain. The domain which was previously attached to the device must be detached.
Cc Ashok Raj <[email protected]>Cc Jacob Pan <[email protected]>Cc Kevin Tian <[email protected]>Cc Alex Williamson <[email protected]>Fixes 942067f1b6b97 ("iommu/vt-d: Identify default domains replaced with private")Reported-by Alex Williamson <[email protected]>Signed-off-by Lu Baolu <[email protected]>
Quoted 1 line
---
This series resolves the issue I reported against:
iommu/vt-d: Cleanup get_valid_domain_for_dev()
Thanks,
Alex
Quoted 34 lines
drivers/iommu/intel-iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/iommu/intel-iommu.c +4
-1@@ -3449,6 +3449,7 @@ static bool iommu_need_mapping(struct device *dev) dmar_domain =to_dmar_domain (domain); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ; } +dmar_remove_one_dev_info (dev);get_private_domain_for_dev (dev); }@@ -4803,7 +4804,8 @@ static void dmar_remove_one_dev_info(struct device *dev)spin_lock_irqsave (&device_domain_lock, flags); info = dev->archdata.iommu; -__dmar_remove_one_dev_info (info); +if (info) +__dmar_remove_one_dev_info (info);spin_unlock_irqrestore (&device_domain_lock, flags); }@@ -5281,6 +5283,7 @@ static int intel_iommu_add_device(struct device *dev)if (device_def_domain_type (dev) ==IOMMU_DOMAIN_IDENTITY ) { ret =iommu_request_dm_for_dev (dev);if (ret) { +dmar_remove_one_dev_info (dev); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ;domain_add_dev_info (si_domain, dev); dev_info(dev,
drivers/iommu/intel-iommu.c static int intel_iommu_add_device(struct device *dev) · line 5300
Quoted 7 lines
drivers/iommu/intel-iommu.c +1
-0@@ -5291,6 +5294,7 @@ static int intel_iommu_add_device(struct device *dev)if (device_def_domain_type (dev) ==IOMMU_DOMAIN_DMA ) { ret =iommu_request_dma_domain_for_dev (dev);if (ret) { +dmar_remove_one_dev_info (dev); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ;if (!get_private_domain_for_dev (dev)) { dev_warn(dev,
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 2/2] iommu/vt-d: Fix possible use-after-free of private domain
In reply to Lu BaoluQuoted 5 lines · On Tue, 6 Aug 2019 08:14:09 +0800 Lu Baolu <[email protected]> wrote:
Multiple devices might share a private domain. One real example is a pci bridge and all devices behind it. When remove a private domain, make sure that it has been detached from all devices to avoid use-after-free case.
Quoted 7 lines
Cc Ashok Raj <[email protected]>Cc Jacob Pan <[email protected]>Cc Kevin Tian <[email protected]>Cc Alex Williamson <[email protected]>Fixes 942067f1b6b97 ("iommu/vt-d: Identify default domains replaced with private")Signed-off-by Lu Baolu <[email protected]>---
Quoted 8 lines
drivers/iommu/intel-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iommu/intel-iommu.c +0
-0
drivers/iommu/intel-iommu.c static void __dmar_remove_one_dev_info(struct device_domain_info *info) · line 4798
Quoted 9 lines
drivers/iommu/intel-iommu.c +2
-1@@ -4791,7 +4791,8 @@ static void __dmar_remove_one_dev_info(struct device_domain_info *info)/* free the private domain */ if (domain->flags &DOMAIN_FLAG_LOSE_CHILDREN && - !(domain->flags &DOMAIN_FLAG_STATIC_IDENTITY )) + !(domain->flags &DOMAIN_FLAG_STATIC_IDENTITY ) && +list_empty (&domain->devices))domain_exit (info->domain);free_devinfo_mem (info);
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi Alex,
Quoted 17 lines · Alex Williamson
Quoted 12 lines · On Tue, 6 Aug 2019 08:14:08 +0800 Lu Baolu <[email protected]> wrote:
When the default domain of a group doesn't work for a device, the iommu driver will try to use a private domain. The domain which was previously attached to the device must be detached.
Cc Ashok Raj <[email protected]>Cc Jacob Pan <[email protected]>Cc Kevin Tian <[email protected]>Cc Alex Williamson <[email protected]>Fixes 942067f1b6b97 ("iommu/vt-d: Identify default domains replaced with private")Reported-by Alex Williamson <[email protected]>Signed-off-by Lu Baolu <[email protected]>Quoted 1 line
---
Quoted 4 lines
Tested-by Alex Williamson <[email protected]>This series resolves the issue I reported against:
iommu/vt-d: Cleanupget_valid_domain_for_dev()
Thank you for testing it.
Best regards,
Baolu
Quoted 47 lines
Thanks,
AlexQuoted 41 lines
drivers/iommu/intel-iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/iommu/intel-iommu.c +5
-1@@ -3449,6 +3449,7 @@ static bool iommu_need_mapping(struct device *dev) dmar_domain =to_dmar_domain (domain); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ; } +dmar_remove_one_dev_info (dev);get_private_domain_for_dev (dev); }@@ -4803,7 +4804,8 @@ static void dmar_remove_one_dev_info(struct device *dev)spin_lock_irqsave (&device_domain_lock, flags); info = dev->archdata.iommu; -__dmar_remove_one_dev_info (info); +if (info) +__dmar_remove_one_dev_info (info);spin_unlock_irqrestore (&device_domain_lock, flags); }@@ -5281,6 +5283,7 @@ static int intel_iommu_add_device(struct device *dev)if (device_def_domain_type (dev) ==IOMMU_DOMAIN_IDENTITY ) { ret =iommu_request_dm_for_dev (dev);if (ret) { +dmar_remove_one_dev_info (dev); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ;domain_add_dev_info (si_domain, dev); dev_info(dev,@@ -5291,6 +5294,7 @@ static int intel_iommu_add_device(struct device *dev)if (device_def_domain_type (dev) ==IOMMU_DOMAIN_DMA ) { ret =iommu_request_dma_domain_for_dev (dev);if (ret) { +dmar_remove_one_dev_info (dev); dmar_domain->flags |=DOMAIN_FLAG_LOSE_CHILDREN ;if (!get_private_domain_for_dev (dev)) { dev_warn(dev,
Joerg Roedel
maintainerQuoted 2 lines · Lu Baolu
drivers/iommu/intel-iommu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Applied to iommu/fixes, thanks.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu