Skip to content

Commit b982df7

Browse files
committed
Merge tag 'edac_urgent_for_5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/ras/ras
Pull EDAC fixes from Borislav Petkov: "Two fixes for use-after-free and memory leaking in the EDAC core, by Robert Richter. Debug options like DEBUG_TEST_DRIVER_REMOVE, KASAN and DEBUG_KMEMLEAK unearthed issues with the lifespan of memory allocated by the EDAC memory controller descriptor due to misdesigned memory freeing, done partially by the EDAC core *and* the driver core, which is problematic to say the least. These two are minimal fixes to take care of stable - a proper rework is following which cleans up that mess properly" * tag 'edac_urgent_for_5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/ras/ras: EDAC/sysfs: Remove csrow objects on errors EDAC/mc: Fix use-after-free and memleaks during device removal
2 parents e29c6a1 + 4d59588 commit b982df7

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

drivers/edac/edac_mc.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -505,16 +505,10 @@ void edac_mc_free(struct mem_ctl_info *mci)
505505
{
506506
edac_dbg(1, "\n");
507507

508-
/* If we're not yet registered with sysfs free only what was allocated
509-
* in edac_mc_alloc().
510-
*/
511-
if (!device_is_registered(&mci->dev)) {
512-
_edac_mc_free(mci);
513-
return;
514-
}
508+
if (device_is_registered(&mci->dev))
509+
edac_unregister_sysfs(mci);
515510

516-
/* the mci instance is freed here, when the sysfs object is dropped */
517-
edac_unregister_sysfs(mci);
511+
_edac_mc_free(mci);
518512
}
519513
EXPORT_SYMBOL_GPL(edac_mc_free);
520514

drivers/edac/edac_mc_sysfs.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,7 @@ static const struct attribute_group *csrow_attr_groups[] = {
276276

277277
static void csrow_attr_release(struct device *dev)
278278
{
279-
struct csrow_info *csrow = container_of(dev, struct csrow_info, dev);
280-
281-
edac_dbg(1, "device %s released\n", dev_name(dev));
282-
kfree(csrow);
279+
/* release device with _edac_mc_free() */
283280
}
284281

285282
static const struct device_type csrow_attr_type = {
@@ -447,8 +444,7 @@ static int edac_create_csrow_objects(struct mem_ctl_info *mci)
447444
csrow = mci->csrows[i];
448445
if (!nr_pages_per_csrow(csrow))
449446
continue;
450-
451-
device_del(&mci->csrows[i]->dev);
447+
device_unregister(&mci->csrows[i]->dev);
452448
}
453449

454450
return err;
@@ -608,10 +604,7 @@ static const struct attribute_group *dimm_attr_groups[] = {
608604

609605
static void dimm_attr_release(struct device *dev)
610606
{
611-
struct dimm_info *dimm = container_of(dev, struct dimm_info, dev);
612-
613-
edac_dbg(1, "device %s released\n", dev_name(dev));
614-
kfree(dimm);
607+
/* release device with _edac_mc_free() */
615608
}
616609

617610
static const struct device_type dimm_attr_type = {
@@ -893,10 +886,7 @@ static const struct attribute_group *mci_attr_groups[] = {
893886

894887
static void mci_attr_release(struct device *dev)
895888
{
896-
struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev);
897-
898-
edac_dbg(1, "device %s released\n", dev_name(dev));
899-
kfree(mci);
889+
/* release device with _edac_mc_free() */
900890
}
901891

902892
static const struct device_type mci_attr_type = {

0 commit comments

Comments
 (0)