Skip to contentSkip to conversation

iommu: fix KASAN use-after-free in iommu_insert_resv_region

PATCH Superseded Eric Auger 4 participants 5 messages Nov 26, 2019 – Dec 16, 2019 IOMMU

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

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.

Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()

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
index d658c7c6a2ab..285ad4a4c7f2 100644
@@ -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
Reviewed-by on v3 1/1
#1 lore raw
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->type instead.

Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()

implementation")

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 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
index d658c7c6a2ab..285ad4a4c7f2 100644
@@ -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
#2 lore raw
In reply to Eric Auger
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->type instead.

Quoted 5 lines
Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()

implementation")

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 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
index d658c7c6a2ab..285ad4a4c7f2 100644
@@ -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
author
#3 lore raw

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->type instead.

Quoted 5 lines
Fixes 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region()

implementation")

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 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
index d658c7c6a2ab..285ad4a4c7f2 100644
@@ -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
#4 lore raw
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