EDAC: Fix kernel panic on module unloading
authorKonstantin Khlebnikov <[email protected]>
Fri, 14 Dec 2012 11:03:10 +0000 (15:03 +0400)
committerBorislav Petkov <[email protected]>
Mon, 7 Jan 2013 16:42:58 +0000 (17:42 +0100)
This patch fixes use-after-free and double-free bugs in
edac_mc_sysfs_exit(). mci_pdev has single reference and put_device()
calls mc_attr_release() which calls kfree(). The following
device_del() works with already released memory. An another kfree() in
edac_mc_sysfs_exit() releses the same memory again. Great.

Signed-off-by: Konstantin Khlebnikov <[email protected]>
Cc: [email protected] # 3.[67]
Cc: Denis Kirjanov <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Link: http://lkml.kernel.org/r/20121214110310.11019.21098.stgit@zurg
Signed-off-by: Borislav Petkov <[email protected]>
drivers/edac/edac_mc_sysfs.c

index de2df92f9c77126709d2c8388b2d88ba7f6ed55c..a3b0119ecb00255626c07f193d2cfb205e2dba26 100644 (file)
@@ -1159,8 +1159,7 @@ int __init edac_mc_sysfs_init(void)
 
 void __exit edac_mc_sysfs_exit(void)
 {
-       put_device(mci_pdev);
        device_del(mci_pdev);
+       put_device(mci_pdev);
        edac_put_sysfs_subsys();
-       kfree(mci_pdev);
 }