Skip to contentSkip to conversation

mm: dmapool: fix possible use after free in dmam_pool_destroy()

PATCH Maxin B John 3 participants 6 messages Jun 2, 2011 – Jun 9, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · Rolf Eike Beer
Quoted 3 lines · Maxin B John

"dma_pool_destroy(pool)" calls "kfree(pool)". The freed pointer "pool" is again passed as an argument to the function "devres_destroy()". This patch fixes the possible use after free.

The pool itself is not used there, only the address where the pool has been.This will only lead to any trouble if something else is allocated to the same place and inserted into the devres list of the same device between the dma_pool_destroy() and devres_destroy().

Thank you very much for explaining it in detail.

Quoted 3 lines

But I agree that this is bad style. But if you are going to change this please also have a look at devm_iounmap() in lib/devres.c. Maybe also the devm_*irq* functions need the same changes.

As per your suggestion, I have made similar modifications for lib/devres.c and kernel/irq/devres.c

CCed the maintainers of the respective files.

---

kernel/irq/devres.c +1 -1
index 1ef4ffc..bd8e788 100644
@@ -87,8 +87,8 @@ void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id)
 {
 	struct irq_devres match_data = { irq, dev_id };
 
-	free_irq(irq, dev_id);
 	WARN_ON(devres_destroy(dev, devm_irq_release, devm_irq_match,
 			       &match_data));
+	free_irq(irq, dev_id);
 }
 EXPORT_SYMBOL(devm_free_irq);
lib/devres.c +1 -1
index 6efddf5..7c0e953 100644
@@ -79,9 +79,9 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
  */
 void devm_iounmap(struct device *dev, void __iomem *addr)
 {
-	iounmap(addr);
 	WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
 			       (void *)addr));
+	iounmap(addr);
 }
 EXPORT_SYMBOL(devm_iounmap);
 
#1 lore raw

Hi,

Quoted 43 lines · Maxin B John
Quoted 9 lines · Rolf Eike Beer
Quoted 3 lines · Maxin B John

"dma_pool_destroy(pool)" calls "kfree(pool)". The freed pointer "pool" is again passed as an argument to the function "devres_destroy()". This patch fixes the possible use after free.

The pool itself is not used there, only the address where the pool has been.This will only lead to any trouble if something else is allocated to the same place and inserted into the devres list of the same device between the dma_pool_destroy() and devres_destroy().

Thank you very much for explaining it in detail.

Quoted 3 lines

But I agree that this is bad style. But if you are going to change this please also have a look at devm_iounmap() in lib/devres.c. Maybe also the devm_*irq* functions need the same changes.

As per your suggestion, I have made similar modifications for lib/devres.c and kernel/irq/devres.c

CCed the maintainers of the respective files.

---

kernel/irq/devres.c +1 -1
index 1ef4ffc..bd8e788 100644
@@ -87,8 +87,8 @@ void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id)
  {
        struct irq_devres match_data = { irq, dev_id };
 
-       free_irq(irq, dev_id);
        WARN_ON(devres_destroy(dev, devm_irq_release, devm_irq_match,
                               &match_data));
+       free_irq(irq, dev_id);
  }
  EXPORT_SYMBOL(devm_free_irq);
lib/devres.c +0 -0
index 6efddf5..7c0e953 100644

lib/devres.c EXPORT_SYMBOL(devm_ioremap_nocache); · line 87

Quoted 10 lines
lib/devres.c +1 -1
@@ -79,9 +79,9 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
  */
  void devm_iounmap(struct device *dev, void __iomem *addr)
  {
-       iounmap(addr);
        WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
                               (void *)addr));
+       iounmap(addr);
  }
  EXPORT_SYMBOL(devm_iounmap);
 

Could you please let me know your thoughts on this patch ?

Best Regards,
Maxin

#3 lore raw

Hi,

Quoted 7 lines · Rolf Eike Beer
Quoted 1 line · Maxin B John

Could you please let me know your thoughts on this patch ?

Makes absolute sense to me.

Thanks a lot for reviewing the patch. Should I merge these two patches and re-send it as a single one ?

Please let me know your opinion.

Warm Regards,
Maxin

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 6 lines

Hi,

Quoted 2 lines · Rolf Eike Beer

Maxin B John wrote:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Could you please let me know your thoughts on this patch ?

Makes absolute sense to me.

Thanks a lot for reviewing the patch. Should I merge these two patches and re-send it as a single one ?

I would do so.

Eike

Acked-by
#5 lore raw
In reply to Maxin B John

Hello,

Quoted 4 lines · Maxin B John
Quoted 4 lines

The pool itself is not used there, only the address where the pool has been.This will only lead to any trouble if something else is allocated to the same place and inserted into the devres list of the same device between the dma_pool_destroy() and devres_destroy().

Which can't happen. devres release is bound to device driver model and a device can't be re-attached before release is complete. ie. those operations are serialized, so the failure mode is only theoretical.

Quoted 6 lines

Thank you very much for explaining it in detail.

Quoted 3 lines

But I agree that this is bad style. But if you are going to change this please also have a look at devm_iounmap() in lib/devres.c. Maybe also the devm_*irq* functions need the same changes.

Quoted 6 lines

As per your suggestion, I have made similar modifications for lib/devres.c and kernel/irq/devres.c

CCed the maintainers of the respective files.

But it shouldn't hurt and if it helps memleak.

Thanks.

Signature · 1 line
tejun