Commit 4c80ba39 authored by Eric Auger's avatar Eric Auger Committed by Linus Torvalds

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: 4dbd258f ("iommu: Revisit iommu_insert_resv_region() implementation")
Signed-off-by: default avatarEric Auger <eric.auger@redhat.com>
Reported-by: default avatarQian Cai <cai@lca.pw>
Reviewed-by: default avatarJerry Snitselaar <jsnitsel@redhat.com>
Cc: Stable <stable@vger.kernel.org> #v5.3+
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7de7de7c
...@@ -312,8 +312,8 @@ int iommu_insert_resv_region(struct iommu_resv_region *new, ...@@ -312,8 +312,8 @@ int iommu_insert_resv_region(struct iommu_resv_region *new,
list_for_each_entry_safe(iter, tmp, regions, list) { list_for_each_entry_safe(iter, tmp, regions, list) {
phys_addr_t top_end, iter_end = iter->start + iter->length - 1; phys_addr_t top_end, iter_end = iter->start + iter->length - 1;
/* no merge needed on elements of different types than @nr */ /* no merge needed on elements of different types than @new */
if (iter->type != nr->type) { if (iter->type != new->type) {
list_move_tail(&iter->list, &stack); list_move_tail(&iter->list, &stack);
continue; continue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment