From: Eric Auger Date: Tue, 26 Nov 2019 17:54:13 +0000 (+0100) Subject: iommu: fix KASAN use-after-free in iommu_insert_resv_region X-Git-Tag: v5.15~4881 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c80ba392bf603d468ea827d902f8e7b2505fbf4;p=platform%2Fkernel%2Flinux-starfive.git iommu: fix KASAN use-after-free in iommu_insert_resv_region In case the new region gets merged into another one, the nr list node is freed. Checking its type while completing the merge algorithm leads to a use-after-free. Use new->type instead. Fixes: 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region() implementation") Signed-off-by: Eric Auger Reported-by: Qian Cai Reviewed-by: Jerry Snitselaar Cc: Stable #v5.3+ Signed-off-by: Linus Torvalds --- diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index db7bfd4..1c3f2a3 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -312,8 +312,8 @@ int iommu_insert_resv_region(struct iommu_resv_region *new, list_for_each_entry_safe(iter, tmp, regions, list) { 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) { + /* no merge needed on elements of different types than @new */ + if (iter->type != new->type) { list_move_tail(&iter->list, &stack); continue; }