]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
EDAC, i7core: Fix memleaks and use-after-free on probe and remove
authorJohan Hovold <johan@kernel.org>
Tue, 12 Jun 2018 12:43:35 +0000 (14:43 +0200)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:51:06 +0000 (19:51 -0600)
BugLink: https://bugs.launchpad.net/bugs/1836287
[ Upstream commit 6c974d4dfafe5e9ee754f2a6fba0eb1864f1649e ]

Make sure to free and deregister the addrmatch and chancounts devices
allocated during probe in all error paths. Also fix use-after-free in a
probe error path and in the remove success path where the devices were
being put before before deregistration.

Signed-off-by: Johan Hovold <johan@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-edac <linux-edac@vger.kernel.org>
Fixes: 356f0a30860d ("i7core_edac: change the mem allocation scheme to make Documentation/kobject.txt happy")
Link: http://lkml.kernel.org/r/20180612124335.6420-2-johan@kernel.org
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/edac/i7core_edac.c

index 8c5540160a23be06fbada0708cd216d62bd61b15..23e441dbaf49543e5583e43d36ef6843e22b9914 100644 (file)
@@ -1177,15 +1177,14 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
 
        rc = device_add(pvt->addrmatch_dev);
        if (rc < 0)
-               return rc;
+               goto err_put_addrmatch;
 
        if (!pvt->is_registered) {
                pvt->chancounts_dev = kzalloc(sizeof(*pvt->chancounts_dev),
                                              GFP_KERNEL);
                if (!pvt->chancounts_dev) {
-                       put_device(pvt->addrmatch_dev);
-                       device_del(pvt->addrmatch_dev);
-                       return -ENOMEM;
+                       rc = -ENOMEM;
+                       goto err_del_addrmatch;
                }
 
                pvt->chancounts_dev->type = &all_channel_counts_type;
@@ -1199,9 +1198,18 @@ static int i7core_create_sysfs_devices(struct mem_ctl_info *mci)
 
                rc = device_add(pvt->chancounts_dev);
                if (rc < 0)
-                       return rc;
+                       goto err_put_chancounts;
        }
        return 0;
+
+err_put_chancounts:
+       put_device(pvt->chancounts_dev);
+err_del_addrmatch:
+       device_del(pvt->addrmatch_dev);
+err_put_addrmatch:
+       put_device(pvt->addrmatch_dev);
+
+       return rc;
 }
 
 static void i7core_delete_sysfs_devices(struct mem_ctl_info *mci)
@@ -1211,11 +1219,11 @@ static void i7core_delete_sysfs_devices(struct mem_ctl_info *mci)
        edac_dbg(1, "\n");
 
        if (!pvt->is_registered) {
-               put_device(pvt->chancounts_dev);
                device_del(pvt->chancounts_dev);
+               put_device(pvt->chancounts_dev);
        }
-       put_device(pvt->addrmatch_dev);
        device_del(pvt->addrmatch_dev);
+       put_device(pvt->addrmatch_dev);
 }
 
 /****************************************************************************