Skip to content

Commit 989185b

Browse files
committed
s390/ism: add release function for struct device
jira LE-3571 Rebuild_History Non-Buildable kernel-4.18.0-553.60.1.el8_10 commit-author Julian Ruess <[email protected]> commit 915e34d According to device_release() in /drivers/base/core.c, a device without a release function is a broken device and must be fixed. The current code directly frees the device after calling device_add() without waiting for other kernel parts to release their references. Thus, a reference could still be held to a struct device, e.g., by sysfs, leading to potential use-after-free issues if a proper release function is not set. Fixes: 8c81ba2 ("net/smc: De-tangle ism and smc device initialization") Reviewed-by: Alexandra Winter <[email protected]> Reviewed-by: Wenjia Zhang <[email protected]> Signed-off-by: Julian Ruess <[email protected]> Signed-off-by: Alexandra Winter <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> (cherry picked from commit 915e34d) Signed-off-by: Jonathan Maple <[email protected]>
1 parent a8c9748 commit 989185b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

drivers/s390/net/ism_drv.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,15 @@ static int ism_dev_init(struct ism_dev *ism)
640640
return ret;
641641
}
642642

643+
static void ism_dev_release(struct device *dev)
644+
{
645+
struct ism_dev *ism;
646+
647+
ism = container_of(dev, struct ism_dev, dev);
648+
649+
kfree(ism);
650+
}
651+
643652
static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
644653
{
645654
struct ism_dev *ism;
@@ -653,6 +662,7 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
653662
dev_set_drvdata(&pdev->dev, ism);
654663
ism->pdev = pdev;
655664
ism->dev.parent = &pdev->dev;
665+
ism->dev.release = ism_dev_release;
656666
device_initialize(&ism->dev);
657667
dev_set_name(&ism->dev, dev_name(&pdev->dev));
658668
ret = device_add(&ism->dev);
@@ -689,7 +699,7 @@ static int ism_probe(struct pci_dev *pdev, const struct pci_device_id *id)
689699
device_del(&ism->dev);
690700
err_dev:
691701
dev_set_drvdata(&pdev->dev, NULL);
692-
kfree(ism);
702+
put_device(&ism->dev);
693703

694704
return ret;
695705
}
@@ -735,7 +745,7 @@ static void ism_remove(struct pci_dev *pdev)
735745
pci_disable_device(pdev);
736746
device_del(&ism->dev);
737747
dev_set_drvdata(&pdev->dev, NULL);
738-
kfree(ism);
748+
put_device(&ism->dev);
739749
}
740750

741751
static int ism_suspend(struct device *dev)

0 commit comments

Comments
 (0)