drivers/spi/mpc52xx_psc_spi.c, potential use after free
Hello Dragos,
Your mpc52xx_psc_spi_do_remove() from current git:
| static int __exit mpc52xx_psc_spi_do_remove(struct device *dev)
| {
| struct spi_master *master = dev_get_drvdata(dev);
| struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master);
|
| flush_workqueue(mps->workqueue);
| destroy_workqueue(mps->workqueue);
| spi_unregister_master(master);
| free_irq(mps->irq, mps);
| if (mps->psc)
| iounmap(mps->psc);
|
| return 0;
| }It looks to me that spi_unregister_master() frees your mps struct and the following free_irq() and iounmap() touches deallocated memory. Might this be correct?
Sebastian
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
Fix mpc52xx_psc_spi_do_remove() use of drvdata after spi master unregister.
---
mpc52xx_psc_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0
b/drivers/spi/mpc52xx_psc_spi.c
index 7051e6c..a4463ba 100644
drivers/spi/mpc52xx_psc_spi.c +0 -0
@@ -534,10 +534,10 @@ static int __exit mpc52xx_psc_spi_do_remove(struct
device *dev)
flush_workqueue(mps->workqueue);
destroy_workqueue(mps->workqueue);
- spi_unregister_master(master);
free_irq(mps->irq, mps);
if (mps->psc)
iounmap(mps->psc);+ spi_unregister_master(master);
return 0;
}
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
Quoted 4 lines · * Dragos Carp | 2008-01-10 15:19:06 [+0100]:
Fix
mpc52xx_psc_spi_do_remove()use of drvdata after spi master unregister.Signed-off-by Dragos Carp <[email protected]>
Acked-by Sebastian Siewior <[email protected]>
Quoted 22 lines
---
mpc52xx_psc_spi.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/spi/mpc52xx_psc_spi.c +1
-1@@ -534,10 +534,10 @@ static int __exit mpc52xx_psc_spi_do_remove(struct device *dev) flush_workqueue(mps->workqueue);destroy_workqueue (mps->workqueue); -spi_unregister_master (master);free_irq (mps->irq, mps);if (mps->psc)iounmap (mps->psc); +spi_unregister_master (master);return 0 ;
Quoted 1 line
}
This should work since you don't touch HW in cleanup. Another question: It seems you don't use any release_mem_region() / request_mem_region(). Are those hidden somewhere behind DT parsing or you don't do them at all?
Sebastian
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
drivers/spi/mpc52xx_psc_spi.c static int __exit mpc52xx_psc_spi_do_remove(struct · line 536
Quoted 6 lines · Dragos Carp
drivers/spi/mpc52xx_psc_spi.c +0
-0@@ -534,10 +534,10 @@ static int __exit mpc52xx_psc_spi_do_remove(struct device *dev) flush_workqueue(mps->workqueue);
Between here ...
drivers/spi/mpc52xx_psc_spi.c static int __exit mpc52xx_psc_spi_do_remove(struct · line 540
Quoted 5 lines
drivers/spi/mpc52xx_psc_spi.c +0
-1destroy_workqueue (mps->workqueue); -spi_unregister_master (master);free_irq (mps->irq, mps);if (mps->psc)iounmap (mps->psc);
... and here, drivers can submit I/O requests. Which will then be completely lost!!
Can you provide a proper shutdown sequence for this driver?
ISTR that some other adapters grab an extra reference to the adapter so that they can unregister first (getting rid of the spi_device children, unbinding their drivers, and ensuring no more incoming requests) and then clean up resources stored with the driver, and then finally spi_master_put().
- Dave
Quoted 7 lines
drivers/spi/mpc52xx_psc_spi.c +1
-0+spi_unregister_master (master);return 0 ;}
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace