Skip to contentSkip to conversation

iommu: fix KASAN use-after-free in iommu_insert_resv_region

PATCH Superseded Eric Auger 1 participant 1 message Nov 25, 2019 IOMMU

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

PATCH 1/1 iommu: fix KASAN use-after-free in iommu_insert_resv_region

Store the new region type in a variable. In case the new region gets merged into another one, the new node is freed and nr shall not be used anymore.

Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()

implementation")

---
 drivers/iommu/iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/iommu.c +3 -1
index d658c7c6a2ab..338769f96d17 100644
@@ -293,6 +293,8 @@ int iommu_insert_resv_region(struct iommu_resv_region *new,
 			     struct list_head *regions)
 {
 	struct iommu_resv_region *iter, *tmp, *nr, *top;
+	enum iommu_resv_type nr_type = new->type;
+
 	LIST_HEAD(stack);
 
 	nr = iommu_alloc_resv_region(new->start, new->length,
@@ -313,7 +315,7 @@ int iommu_insert_resv_region(struct iommu_resv_region *new,
 		phys_addr_t top_end, iter_end = iter->start + iter->length - 1;
 
 		/* no merge needed on elements of different types than @nr */
-		if (iter->type != nr->type) {
+		if (iter->type != nr_type) {
 			list_move_tail(&iter->list, &stack);
 			continue;
 		}
Signature · 1 line
2.20.1