iommu: fix KASAN use-after-free in iommu_insert_resv_region
PATCH v3 1/1 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.
implementation")
---
v2 -> v3:
- directly use new->type
v1 -> v2:
- remove spurious new line
--- drivers/iommu/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/iommu.c +1 -1
@@ -313,7 +313,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 != new->type) {list_move_tail (&iter->list, &stack);continue ; }
Signature · 1 line
2.20.1
Quoted 11 lines · Eric Auger
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->typeinstead.Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()implementation")
Signed-off-by Eric Auger <[email protected]>Reported-by Qian Cai <[email protected]>Cc Stable <[email protected]> #v5.3+
Minor nit, but should the comment above list_for_each_entry_safe get updated as well? Other than that, lgtm.
Quoted 32 lines
---
v2 -> v3:
- directly usenew->typev1 -> v2:
- remove spurious new line
---drivers/iommu/iommu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/iommu.c +1
-1@@ -313,7 +313,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 != new->type) {list_move_tail (&iter->list, &stack);continue ; }Signature · 6 lines
2.20.1 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 9 lines · Eric Auger
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->typeinstead.
Quoted 5 lines
Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()implementation")
Signed-off-by Eric Auger <[email protected]>Reported-by Qian Cai <[email protected]>Cc Stable <[email protected]> #v5.3+
Looks like Joerg is away for a few weeks. Could Andrew or Linus pick up this use-after-free?
Quoted 28 lines
---
v2 -> v3:
- directly usenew->typev1 -> v2:
- remove spurious new line
---drivers/iommu/iommu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/iommu.c +1
-1@@ -313,7 +313,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 != new->type) {list_move_tail (&iter->list, &stack);continue ; }Signature · 1 line
2.20.1
Hi,
Quoted 16 lines · Qian Cai
Quoted 9 lines · Eric Auger
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->typeinstead.Quoted 5 lines
Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()implementation")
Signed-off-by Eric Auger <[email protected]>Reported-by Qian Cai <[email protected]>Cc Stable <[email protected]> #v5.3+
Quoted 2 lines
Looks like Joerg is away for a few weeks. Could Andrew or Linus pick up this use-after-free?
Thanks for the heads up. Indeed I was wondering why it hasn't been taken yet.
Note the right version to pick up is the v4, reviewed by Jerry:
https://www.mail-archive.com/[email protected]/msg36226.html
Thanks
Eric
Quoted 30 lines
Quoted 29 lines
---
v2 -> v3:
- directly usenew->typev1 -> v2:
- remove spurious new line
---drivers/iommu/iommu.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/iommu.c +1
-1@@ -313,7 +313,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 != new->type) {list_move_tail (&iter->list, &stack);continue ; }Signature · 1 line
2.20.1
Quoted 4 lines · Auger Eric
Quoted 3 lines · Qian Cai
Looks like Joerg is away for a few weeks. Could Andrew or Linus pick up this use-after-free?
I've taken it.
Quoted 2 lines
Note the right version to pick up is the v4, reviewed by Jerry:
https://www.mail-archive.com/[email protected]/msg36226.html
Btw, please use lore.kernel.org, it's much more convenient for me (faster, and a single interface for me so that I don't have to always figure out "what's the incantation to get the original raw email" that so many archives make it hard to get).
Linus
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu