Skip to contentSkip to conversation

dmaengine: virt-dma: Fix access after free in vcna_complete()

PATCH Applied Peter Ujfalusi 3 participants 6 messages Dec 20, 2019 – Dec 23, 2019 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: virt-dma: Fix access after free in vcna_complete()

vchan_vdesc_fini() is freeing up 'vd' so the access to vd->tx_result is via already freed up memory.

Move the vchan_vdesc_fini() after invoking the callback to avoid this.

Fixes 09d5b702b0f97 ("dmaengine: virt-dma: store result on dma descriptor")
---
 drivers/dma/virt-dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/virt-dma.c +1 -2
index ec4adf4260a0..256fc662c500 100644
@@ -104,9 +104,8 @@ static void vchan_complete(unsigned long arg)
 		dmaengine_desc_get_callback(&vd->tx, &cb);
 
 		list_del(&vd->node);
-		vchan_vdesc_fini(vd);
-
 		dmaengine_desc_callback_invoke(&cb, &vd->tx_result);
+		vchan_vdesc_fini(vd);
 	}
 }
 
Signature · 4 lines
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Peter Ujfalusi

[External]

vchan_vdesc_fini() is freeing up 'vd' so the access to vd->tx_result is via already freed up memory.

Move the vchan_vdesc_fini() after invoking the callback to avoid this.

Quoted 22 lines
Fixes 09d5b702b0f97 ("dmaengine: virt-dma: store result on dma

descriptor")

---
 drivers/dma/virt-dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/virt-dma.c +1 -2
index ec4adf4260a0..256fc662c500 100644
@@ -104,9 +104,8 @@ static void vchan_complete(unsigned long arg)
 		dmaengine_desc_get_callback(&vd->tx, &cb);
 
 		list_del(&vd->node);
-		vchan_vdesc_fini(vd);
-
 		dmaengine_desc_callback_invoke(&cb, &vd->tx_result);
+		vchan_vdesc_fini(vd);
 	}
 }
 
#2 lore raw
In reply to Peter Ujfalusi
Quoted 7 lines · Peter Ujfalusi

[External]

vchan_vdesc_fini() is freeing up 'vd' so the access to vd->tx_result is via already freed up memory.

Move the vchan_vdesc_fini() after invoking the callback to avoid this.

Apologies for seeing this too late: typo in title vcna_complete() -> vchan_complete()

Quoted 22 lines
Fixes 09d5b702b0f97 ("dmaengine: virt-dma: store result on dma

descriptor")

---
 drivers/dma/virt-dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/virt-dma.c +1 -2
index ec4adf4260a0..256fc662c500 100644
@@ -104,9 +104,8 @@ static void vchan_complete(unsigned long arg)
 		dmaengine_desc_get_callback(&vd->tx, &cb);
 
 		list_del(&vd->node);
-		vchan_vdesc_fini(vd);
-
 		dmaengine_desc_callback_invoke(&cb, &vd->tx_result);
+		vchan_vdesc_fini(vd);
 	}
 }
 
#3 lore raw
Quoted 11 lines · Alexandru
Quoted 7 lines · Peter Ujfalusi

[External]

vchan_vdesc_fini() is freeing up 'vd' so the access to vd->tx_result is via already freed up memory.

Move the vchan_vdesc_fini() after invoking the callback to avoid this.

Apologies for seeing this too late: typo in title vcna_complete() -> vchan_complete()

Yep, I also noticed after sending it, I hope Vinod is kind enough and fix it up when applying ;)

- Péter

Quoted 14 lines
Quoted 14 lines
Fixes 09d5b702b0f97 ("dmaengine: virt-dma: store result on dma

descriptor")

---
 drivers/dma/virt-dma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/virt-dma.c +0 -0
index ec4adf4260a0..256fc662c500 100644
@@ -104,9 +104,8 @@ static void vchan_complete(unsigned long arg)
 		dmaengine_desc_get_callback(&vd->tx, &cb);
 
Quoted 8 lines

drivers/dma/virt-dma.c static void vchan_complete(unsigned long arg) · line 111

Quoted 8 lines
drivers/dma/virt-dma.c +1 -2
 		list_del(&vd->node);
-		vchan_vdesc_fini(vd);
-
 		dmaengine_desc_callback_invoke(&cb, &vd->tx_result);
+		vchan_vdesc_fini(vd);
 	}
 }
 

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki

maintainer
#4 lore raw
Quoted 9 lines · Peter Ujfalusi
Quoted 6 lines · Alexandru
Quoted 5 lines · Peter Ujfalusi

[External]

vchan_vdesc_fini() is freeing up 'vd' so the access to vd->tx_result is via already freed up memory.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Move the vchan_vdesc_fini() after invoking the callback to avoid this.

Apologies for seeing this too late: typo in title vcna_complete() -> vchan_complete()

Yep, I also noticed after sending it, I hope Vinod is kind enough and fix it up when applying ;)

In case it wasnt clear, yeah trivial changes while applying are no hassle :)

Signature · 1 line
~Vinod
maintainer Applied
#5 lore raw
In reply to Peter Ujfalusi
Quoted 4 lines · Peter Ujfalusi

vchan_vdesc_fini() is freeing up 'vd' so the access to vd->tx_result is via already freed up memory.

Move the vchan_vdesc_fini() after invoking the callback to avoid this.

Applied, thanks

Signature · 1 line
~Vinod