mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-15 11:44:11 +00:00
virtio-mmio: don't break lifecycle of vm_dev
[ Upstream commit55c91fedd0
] vm_dev has a separate lifecycle because it has a 'struct device' embedded. Thus, having a release callback for it is correct. Allocating the vm_dev struct with devres totally breaks this protection, though. Instead of waiting for the vm_dev release callback, the memory is freed when the platform_device is removed. Resulting in a use-after-free when finally the callback is to be called. To easily see the problem, compile the kernel with CONFIG_DEBUG_KOBJECT_RELEASE and unbind with sysfs. The fix is easy, don't use devres in this case. Found during my research about object lifetime problems. Fixes:7eb781b1bb
("virtio_mmio: add cleanup for virtio_mmio_probe") Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Message-Id: <20230629120526.7184-1-wsa+renesas@sang-engineering.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
c702da670b
commit
1485c1753c
1 changed files with 2 additions and 3 deletions
|
@ -572,9 +572,8 @@ static void virtio_mmio_release_dev(struct device *_d)
|
|||
struct virtio_device *vdev =
|
||||
container_of(_d, struct virtio_device, dev);
|
||||
struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
|
||||
struct platform_device *pdev = vm_dev->pdev;
|
||||
|
||||
devm_kfree(&pdev->dev, vm_dev);
|
||||
kfree(vm_dev);
|
||||
}
|
||||
|
||||
/* Platform device */
|
||||
|
@ -585,7 +584,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
|
|||
unsigned long magic;
|
||||
int rc;
|
||||
|
||||
vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL);
|
||||
vm_dev = kzalloc(sizeof(*vm_dev), GFP_KERNEL);
|
||||
if (!vm_dev)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue